Skip to content

Commit 9f38271

Browse files
committed
PR Fixes
1 parent 537bead commit 9f38271

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

driver-core/src/main/com/mongodb/internal/connection/OidcAuthenticator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public class OidcAuthenticator extends SaslAuthenticator {
8080

8181
private static final String AWS_WEB_IDENTITY_TOKEN_FILE = "AWS_WEB_IDENTITY_TOKEN_FILE";
8282

83+
@Nullable
8384
private ServerAddress serverAddress;
8485

8586
@Nullable
@@ -497,7 +498,7 @@ private static IdpInfo toIdpInfo(final byte[] challenge) {
497498

498499
private void validateAllowedHosts(final MongoCredential credential) {
499500
List<String> allowedHosts = assertNotNull(credential.getMechanismProperty(ALLOWED_HOSTS_KEY, DEFAULT_ALLOWED_HOSTS));
500-
String host = serverAddress.getHost();
501+
String host = assertNotNull(serverAddress).getHost();
501502
boolean permitted = allowedHosts.stream().anyMatch(allowedHost -> {
502503
if (allowedHost.startsWith("*.")) {
503504
String ending = allowedHost.substring(1);

driver-core/src/test/unit/com/mongodb/AuthConnectionStringTest.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.Collection;
3737
import java.util.List;
3838

39+
import static com.mongodb.AuthenticationMechanism.MONGODB_OIDC;
3940
import static com.mongodb.MongoCredential.REFRESH_TOKEN_CALLBACK_KEY;
4041
import static com.mongodb.MongoCredential.REQUEST_TOKEN_CALLBACK_KEY;
4142

@@ -113,21 +114,25 @@ private MongoCredential getMongoCredential() {
113114
MongoCredential credential = connectionString.getCredential();
114115
if (credential != null) {
115116
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+
}
128131
}
129132
}
130-
OidcAuthenticator.OidcValidator.validateBeforeUse(credential);
133+
if (MONGODB_OIDC.getMechanismName().equals(credential.getMechanism())) {
134+
OidcAuthenticator.OidcValidator.validateBeforeUse(credential);
135+
}
131136
}
132137
return credential;
133138
}

0 commit comments

Comments
 (0)