127
127
* </ul>
128
128
* <p>Authentication configuration:</p>
129
129
* <ul>
130
- * <li>{@code authProtocol =MONGO-CR|GSSAPI}: The authentication protocol to use if a credential was supplied.
131
- * The default is MONGO -CR, which is the native MongoDB Challenge Response mechanism.
130
+ * <li>{@code authMechanism =MONGO-CR|GSSAPI}: The authentication mechanism to use if a credential was supplied.
131
+ * The default is MONGODB -CR, which is the native MongoDB Challenge Response mechanism.
132
132
* </li>
133
133
* <li>{@code authSource=string}: The source of the authentication credentials. This is typically the database that
134
134
* the credentials have been created. The value defaults to the database specified in the path portion of the URI.
@@ -269,7 +269,7 @@ public MongoClientURI(final String uri) {
269
269
writeConcernKeys .add ("fsync" );
270
270
writeConcernKeys .add ("j" );
271
271
272
- authKeys .add ("authprotocol " );
272
+ authKeys .add ("authmechanism " );
273
273
authKeys .add ("authsource" );
274
274
275
275
allKeys .addAll (generalOptionsKeys );
@@ -393,7 +393,7 @@ private MongoCredential createCredentials(Map<String, List<String>> optionsMap,
393
393
database = "admin" ;
394
394
}
395
395
396
- String mechanism = MongoCredential .MONGO_CR_MECHANISM ;
396
+ String mechanism = MongoCredential .MONGODB_CR_MECHANISM ;
397
397
String authSource = database ;
398
398
399
399
for (String key : authKeys ) {
@@ -403,7 +403,7 @@ private MongoCredential createCredentials(Map<String, List<String>> optionsMap,
403
403
continue ;
404
404
}
405
405
406
- if (key .equals ("authprotocol " )) {
406
+ if (key .equals ("authmechanism " )) {
407
407
mechanism = value ;
408
408
} else if (key .equals ("authsource" )) {
409
409
authSource = value ;
@@ -413,9 +413,12 @@ private MongoCredential createCredentials(Map<String, List<String>> optionsMap,
413
413
if (mechanism .equals (MongoCredential .GSSAPI_MECHANISM )) {
414
414
return MongoCredential .createGSSAPICredential (userName );
415
415
}
416
- else {
416
+ else if ( mechanism . equals ( MongoCredential . MONGODB_CR_MECHANISM )) {
417
417
return MongoCredential .createMongoCRCredential (userName , authSource , password );
418
418
}
419
+ else {
420
+ throw new IllegalArgumentException ("Unsupported authMechanism: " + mechanism );
421
+ }
419
422
}
420
423
421
424
private String getLastValue (final Map <String , List <String >> optionsMap , final String key ) {
0 commit comments