mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 19:46:32 +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;
|
||||||
|
|
||||||
|
if (configuration.getUsername() != null && !configuration.getUsername().equals("") && configuration.getDatabase() != null && !configuration.getDatabase().equals("")) {
|
||||||
|
if (configuration.getPassword() == null || configuration.getPassword().equals("")) {
|
||||||
|
credential = MongoCredential.createCredential(
|
||||||
|
configuration.getUsername(),
|
||||||
|
configuration.getDatabase(), null
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
credential = MongoCredential.createCredential(
|
||||||
configuration.getUsername(),
|
configuration.getUsername(),
|
||||||
configuration.getDatabase(),
|
configuration.getDatabase(),
|
||||||
configuration.getPassword().toCharArray()
|
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])
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (credential == null) {
|
||||||
|
mongoClient = new MongoClient(address, Collections.emptyList());
|
||||||
|
} else {
|
||||||
mongoClient = new MongoClient(address, Collections.singletonList(credential));
|
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