Skip to content

Commit be0cd71

Browse files
katcharovstIncMale
andauthored
Apply suggestions from code review
Co-authored-by: Valentin Kovalenko <valentin.kovalenko@mongodb.com>
1 parent c788f29 commit be0cd71

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

driver-core/src/main/com/mongodb/MongoCredential.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,9 @@ public final class MongoCredential {
200200
/**
201201
* This callback is invoked when the OIDC-based authenticator requests
202202
* a token. The type of the value must be {@link OidcCallback}.
203-
* {@link IdpInfo} will not be supplied to the callback, and a refresh
204-
* token must not be returned by the callback.
203+
* {@link IdpInfo} will not be supplied to the callback,
204+
* and a {@linkplain OidcCallbackResult#getRefreshToken() refresh token}
205+
* must not be returned by the callback.
205206
* <p>
206207
* If this is provided, {@link MongoCredential#PROVIDER_NAME_KEY}
207208
* and {@link MongoCredential#OIDC_HUMAN_CALLBACK_KEY}
@@ -719,9 +720,7 @@ public static final class OidcCallbackResult {
719720
* @param accessToken The OIDC access token
720721
*/
721722
public OidcCallbackResult(final String accessToken) {
722-
notNull("accessToken", accessToken);
723-
this.accessToken = accessToken;
724-
this.refreshToken = null;
723+
this(accessToken, null);
725724
}
726725

727726
/**

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public String getMechanismName() {
104104

105105
@Override
106106
protected SaslClient createSaslClient(final ServerAddress serverAddress) {
107-
this.serverAddress = serverAddress;
107+
this.serverAddress = assertNotNull(serverAddress);
108108
MongoCredentialWithCache mongoCredentialWithCache = getMongoCredentialWithCache();
109109
return new OidcSaslClient(mongoCredentialWithCache);
110110
}
@@ -153,7 +153,7 @@ public void setSpeculativeAuthenticateResponse(@Nullable final BsonDocument resp
153153
}
154154

155155
private boolean isAutomaticAuthentication() {
156-
return getRequestCallback() == null;
156+
return getMechanismProperty(PROVIDER_NAME_KEY) == null;
157157
}
158158

159159
private boolean isHumanCallback() {
@@ -602,7 +602,9 @@ public static void validateBeforeUse(final MongoCredential credential) {
602602
@VisibleForTesting(otherwise = VisibleForTesting.AccessModifier.PRIVATE)
603603
static class OidcCallbackContextImpl implements OidcCallbackContext {
604604
private final Duration timeout;
605+
@Nullable
605606
private final IdpInfo idpInfo;
607+
@Nullable
606608
private final String refreshToken;
607609

608610
OidcCallbackContextImpl(final Duration timeout) {
@@ -613,7 +615,7 @@ static class OidcCallbackContextImpl implements OidcCallbackContext {
613615

614616
OidcCallbackContextImpl(final Duration timeout, final IdpInfo idpInfo, @Nullable final String refreshToken) {
615617
this.timeout = assertNotNull(timeout);
616-
this.idpInfo = idpInfo;
618+
this.idpInfo = assertNotNull(idpInfo);
617619
this.refreshToken = refreshToken;
618620
}
619621

0 commit comments

Comments
 (0)