Skip to content

Commit 31003bd

Browse files
authored
NIFI-14916 Fixed MongoDBControllerService handling of X509 authentication (apache#10250)
Signed-off-by: David Handermann <exceptionfactory@apache.org>
1 parent 112739b commit 31003bd

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

nifi-extension-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/main/java/org/apache/nifi/mongodb/MongoDBControllerService.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ protected MongoClient createClient(ConfigurationContext context, MongoClient exi
131131
case PLAIN -> builder.credential(MongoCredential.createPlainCredential(user, database, passw.toCharArray()));
132132
default -> throw new IllegalArgumentException("Unsupported authentication mechanism with username and password: " + mechanism);
133133
}
134+
} else if (authMechanism != null) {
135+
final AuthenticationMechanism mechanism = AuthenticationMechanism.fromMechanismName(authMechanism.toUpperCase());
136+
switch (mechanism) {
137+
case MONGODB_X509 -> builder.credential(MongoCredential.createMongoX509Credential(user));
138+
case MONGODB_OIDC -> builder.credential(MongoCredential.createOidcCredential(user));
139+
case GSSAPI -> builder.credential(MongoCredential.createGSSAPICredential(user));
140+
default -> throw new IllegalArgumentException("Unsupported authentication mechanism with username only: " + mechanism);
141+
}
134142
} else if (user != null && passw != null) {
135143
final MongoCredential credential = MongoCredential.createCredential(user, database, passw.toCharArray());
136144
builder.credential(credential);

0 commit comments

Comments
 (0)