Skip to content

Commit

Permalink
Merge pull request quarkusio#44858 from tomas1885/mongodb_auth_mechanism
Browse files Browse the repository at this point in the history
Allow using Mongo auth mechanisms without user and password
  • Loading branch information
loicmathieu authored Dec 2, 2024
2 parents cce6e31 + cf06d7e commit e3aec53
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,6 @@ public ServerAddress apply(String address) {
}

private MongoCredential createMongoCredential(MongoClientConfig config) {
UsernamePassword usernamePassword = determineUserNamePassword(config.credentials);
if (usernamePassword == null) {
return null;
}

// get the authsource, or the database from the config, or 'admin' as it is the default auth source in mongo
// and null is not allowed
Expand All @@ -449,6 +445,13 @@ private MongoCredential createMongoCredential(MongoClientConfig config) {
mechanism = getAuthenticationMechanism(maybeMechanism.get());
}

UsernamePassword usernamePassword = determineUserNamePassword(config.credentials);
if (usernamePassword == null) {
if (mechanism == null) {
return null;
}
usernamePassword = new UsernamePassword(null, null);
}
// Create the MongoCredential instance.
String username = usernamePassword.getUsername();
char[] password = usernamePassword.getPassword();
Expand Down

0 comments on commit e3aec53

Please sign in to comment.