Skip to content

Commit 4a844b1

Browse files
committed
PR fixes for OIDC feature branch
1 parent 479fcdd commit 4a844b1

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@
230230
* </ul>
231231
* <p>Authentication configuration:</p>
232232
* <ul>
233-
* <li>{@code authMechanism=MONGO-CR|GSSAPI|PLAIN|MONGODB-X509}: The authentication mechanism to use if a credential was supplied.
233+
* <li>{@code authMechanism=MONGO-CR|GSSAPI|PLAIN|MONGODB-X509|MONGODB-OIDC}: The authentication mechanism to use if a credential was supplied.
234234
* The default is unspecified, in which case the client will pick the most secure mechanism available based on the sever version. For the
235-
* GSSAPI and MONGODB-X509 mechanisms, no password is accepted, only the username.
235+
* GSSAPI, MONGODB-X509, and MONGODB-OIDC mechanisms, no password is accepted, only the username.
236236
* </li>
237237
* <li>{@code authSource=string}: The source of the authentication credentials. This is typically the database that
238238
* the credentials have been created. The value defaults to the database specified in the path portion of the connection string.

driver-core/src/main/com/mongodb/internal/Locks.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static void withLockAsync(final StampedLock lock, final AsyncRunnable run
5454
}, callback);
5555
}
5656

57-
public static void withLock(final StampedLock lock, final Runnable runnable) {
57+
public static void withInterruptibleLock(final StampedLock lock, final Runnable runnable) {
5858
long stamp;
5959
try {
6060
stamp = lock.writeLockInterruptibly();

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ protected SaslClient createSaslClient(final ServerAddress serverAddress) {
126126
@Nullable
127127
public BsonDocument createSpeculativeAuthenticateCommand(final InternalConnection connection) {
128128
try {
129-
String cachedAccessToken = getCachedAccessToken();
129+
String cachedAccessToken = getMongoCredentialWithCache()
130+
.getOidcCacheEntry()
131+
.getCachedAccessToken();
130132
if (cachedAccessToken != null) {
131133
return wrapInSpeculative(prepareTokenAsJwt(cachedAccessToken));
132134
} else {
@@ -284,7 +286,7 @@ private void authenticationLoopAsync(final InternalConnection connection, final
284286

285287
private byte[] evaluate(final byte[] challenge) {
286288
byte[][] jwt = new byte[1][];
287-
Locks.withLock(getMongoCredentialWithCache().getOidcLock(), () -> {
289+
Locks.withInterruptibleLock(getMongoCredentialWithCache().getOidcLock(), () -> {
288290
OidcCacheEntry oidcCacheEntry = getMongoCredentialWithCache().getOidcCacheEntry();
289291
String cachedRefreshToken = oidcCacheEntry.getRefreshToken();
290292
IdpInfo cachedIdpInfo = oidcCacheEntry.getIdpInfo();
@@ -358,7 +360,7 @@ private byte[] evaluate(final byte[] challenge) {
358360
private String validatedCachedAccessToken() {
359361
MongoCredentialWithCache mongoCredentialWithCache = getMongoCredentialWithCache();
360362
OidcCacheEntry cacheEntry = mongoCredentialWithCache.getOidcCacheEntry();
361-
String cachedAccessToken = getCachedAccessToken();
363+
String cachedAccessToken = cacheEntry.getCachedAccessToken();
362364
String invalidConnectionAccessToken = connectionLastAccessToken;
363365

364366
if (cachedAccessToken != null) {
@@ -377,7 +379,7 @@ private boolean clientIsComplete() {
377379

378380
private boolean shouldRetryHandler() {
379381
boolean[] result = new boolean[1];
380-
Locks.withLock(getMongoCredentialWithCache().getOidcLock(), () -> {
382+
Locks.withInterruptibleLock(getMongoCredentialWithCache().getOidcLock(), () -> {
381383
MongoCredentialWithCache mongoCredentialWithCache = getMongoCredentialWithCache();
382384
OidcCacheEntry cacheEntry = mongoCredentialWithCache.getOidcCacheEntry();
383385
if (fallbackState == FallbackState.PHASE_1_CACHED_TOKEN) {
@@ -402,13 +404,6 @@ private boolean shouldRetryHandler() {
402404
return result[0];
403405
}
404406

405-
@Nullable
406-
private String getCachedAccessToken() {
407-
return getMongoCredentialWithCache()
408-
.getOidcCacheEntry()
409-
.getCachedAccessToken();
410-
}
411-
412407
static final class OidcCacheEntry {
413408
@Nullable
414409
private final String accessToken;

0 commit comments

Comments
 (0)