|
36 | 36 | import java.util.Collection;
|
37 | 37 | import java.util.List;
|
38 | 38 |
|
| 39 | +import static com.mongodb.AuthenticationMechanism.MONGODB_OIDC; |
39 | 40 | import static com.mongodb.MongoCredential.REFRESH_TOKEN_CALLBACK_KEY;
|
40 | 41 | import static com.mongodb.MongoCredential.REQUEST_TOKEN_CALLBACK_KEY;
|
41 | 42 |
|
@@ -113,21 +114,25 @@ private MongoCredential getMongoCredential() {
|
113 | 114 | MongoCredential credential = connectionString.getCredential();
|
114 | 115 | if (credential != null) {
|
115 | 116 | BsonArray callbacks = (BsonArray) getExpectedValue("callback");
|
116 |
| - for (BsonValue v : callbacks) { |
117 |
| - String string = ((BsonString) v).getValue(); |
118 |
| - if ("oidcRequest".equals(string)) { |
119 |
| - credential = credential.withMechanismProperty( |
120 |
| - REQUEST_TOKEN_CALLBACK_KEY, |
121 |
| - (MongoCredential.OidcRequestCallback) (context) -> null); |
122 |
| - } else if ("oidcRefresh".equals(string)) { |
123 |
| - credential = credential.withMechanismProperty( |
124 |
| - REFRESH_TOKEN_CALLBACK_KEY, |
125 |
| - (MongoCredential.OidcRefreshCallback) (context) -> null); |
126 |
| - } else { |
127 |
| - fail("Unsupported callback: " + string); |
| 117 | + if (callbacks != null) { |
| 118 | + for (BsonValue v : callbacks) { |
| 119 | + String string = ((BsonString) v).getValue(); |
| 120 | + if ("oidcRequest".equals(string)) { |
| 121 | + credential = credential.withMechanismProperty( |
| 122 | + REQUEST_TOKEN_CALLBACK_KEY, |
| 123 | + (MongoCredential.OidcRequestCallback) (context) -> null); |
| 124 | + } else if ("oidcRefresh".equals(string)) { |
| 125 | + credential = credential.withMechanismProperty( |
| 126 | + REFRESH_TOKEN_CALLBACK_KEY, |
| 127 | + (MongoCredential.OidcRefreshCallback) (context) -> null); |
| 128 | + } else { |
| 129 | + fail("Unsupported callback: " + string); |
| 130 | + } |
128 | 131 | }
|
129 | 132 | }
|
130 |
| - OidcAuthenticator.OidcValidator.validateBeforeUse(credential); |
| 133 | + if (MONGODB_OIDC.getMechanismName().equals(credential.getMechanism())) { |
| 134 | + OidcAuthenticator.OidcValidator.validateBeforeUse(credential); |
| 135 | + } |
131 | 136 | }
|
132 | 137 | return credential;
|
133 | 138 | }
|
|
0 commit comments