Skip to content

Commit 006f82e

Browse files
committed
adds not mechanism
1 parent 251cf4c commit 006f82e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

mongodb-driver/src/main/java/org/eclipse/jnosql/diana/mongodb/document/MongoAuthentication.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ private MongoAuthentication() {
3737

3838
static Optional<MongoCredential> of(Settings settings) {
3939

40-
4140
Optional<String> user = settings.get(Arrays.asList(USER.get(),
4241
Configurations.USER.get()))
4342
.map(Object::toString);
@@ -49,16 +48,20 @@ static Optional<MongoCredential> of(Settings settings) {
4948
Optional<String> source = settings.get(AUTHENTICATION_SOURCE.get())
5049
.map(Object::toString);
5150

52-
AuthenticationMechanism mechanism = settings.get(AUTHENTICATION_MECHANISM.get())
51+
Optional<AuthenticationMechanism> mechanism = settings.get(AUTHENTICATION_MECHANISM.get())
5352
.map(Object::toString)
54-
.map(AuthenticationMechanism::fromMechanismName)
55-
.orElse(AuthenticationMechanism.PLAIN);
53+
.map(AuthenticationMechanism::fromMechanismName);
5654

5755
if (!user.isPresent()) {
5856
return Optional.empty();
5957
}
6058

61-
switch (mechanism) {
59+
if (!mechanism.isPresent()) {
60+
return Optional.of(MongoCredential.createCredential(user.orElseThrow(missingExceptionUser()),
61+
source.orElseThrow(missingExceptionSource()), password.orElseThrow(missingExceptionPassword())));
62+
}
63+
64+
switch (mechanism.get()) {
6265
case PLAIN:
6366
return Optional.of(MongoCredential.createPlainCredential(user.orElseThrow(missingExceptionUser()),
6467
source.orElseThrow(missingExceptionSource()), password.orElseThrow(missingExceptionPassword())));

0 commit comments

Comments
 (0)