mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-28 13:45:20 +01:00
Fix MongoDB auth-less connection
This commit is contained in:
parent
bfc79c6051
commit
f4f9612789
@ -122,18 +122,34 @@ public class MongoDBBacking extends AbstractBacking {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
MongoCredential credential = MongoCredential.createCredential(
|
MongoCredential credential = null;
|
||||||
configuration.getUsername(),
|
|
||||||
configuration.getDatabase(),
|
if (configuration.getUsername() != null && !configuration.getUsername().equals("") && configuration.getDatabase() != null && !configuration.getDatabase().equals("")) {
|
||||||
configuration.getPassword().toCharArray()
|
if (configuration.getPassword() == null || configuration.getPassword().equals("")) {
|
||||||
);
|
credential = MongoCredential.createCredential(
|
||||||
|
configuration.getUsername(),
|
||||||
|
configuration.getDatabase(), null
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
credential = MongoCredential.createCredential(
|
||||||
|
configuration.getUsername(),
|
||||||
|
configuration.getDatabase(),
|
||||||
|
configuration.getPassword().toCharArray()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ServerAddress address = new ServerAddress(
|
ServerAddress address = new ServerAddress(
|
||||||
configuration.getAddress().split(":")[0],
|
configuration.getAddress().split(":")[0],
|
||||||
Integer.parseInt(configuration.getAddress().split(":")[1])
|
Integer.parseInt(configuration.getAddress().split(":")[1])
|
||||||
);
|
);
|
||||||
|
|
||||||
mongoClient = new MongoClient(address, Collections.singletonList(credential));
|
if (credential == null) {
|
||||||
|
mongoClient = new MongoClient(address, Collections.emptyList());
|
||||||
|
} else {
|
||||||
|
mongoClient = new MongoClient(address, Collections.singletonList(credential));
|
||||||
|
}
|
||||||
|
|
||||||
database = mongoClient.getDatabase(configuration.getDatabase());
|
database = mongoClient.getDatabase(configuration.getDatabase());
|
||||||
setAcceptingLogins(true);
|
setAcceptingLogins(true);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user