Skip to content

Commit 1bd198e

Browse files
committed
Ensure that MongoInterruptedExceptions are not wrapped in a MongoSecurityException
JAVA-2448
1 parent fd1ff2e commit 1bd198e

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

driver-core/src/main/com/mongodb/connection/SaslAuthenticator.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package com.mongodb.connection;
1818

1919
import com.mongodb.MongoCredential;
20+
import com.mongodb.MongoException;
21+
import com.mongodb.MongoInterruptedException;
2022
import com.mongodb.MongoSecurityException;
2123
import com.mongodb.ServerAddress;
2224
import com.mongodb.async.SingleResultCallback;
@@ -63,7 +65,7 @@ public Void run() {
6365
res = sendSaslContinue(conversationId, response, connection);
6466
}
6567
} catch (Exception e) {
66-
throw wrapInMongoSecurityException(e);
68+
throw wrapException(e);
6769
} finally {
6870
disposeOfSaslClient(saslClient);
6971
}
@@ -86,7 +88,7 @@ public Void run() {
8688
@Override
8789
public void onResult(final BsonDocument result, final Throwable t) {
8890
if (t != null) {
89-
callback.onResult(null, wrapInMongoSecurityException(t));
91+
callback.onResult(null, wrapException(t));
9092
} else if (result.getBoolean("done").getValue()) {
9193
callback.onResult(null, null);
9294
} else {
@@ -95,7 +97,7 @@ public void onResult(final BsonDocument result, final Throwable t) {
9597
}
9698
});
9799
} catch (SaslException e) {
98-
throw wrapInMongoSecurityException(e);
100+
throw wrapException(e);
99101
}
100102
return null;
101103
}
@@ -151,10 +153,14 @@ private void disposeOfSaslClient(final SaslClient saslClient) {
151153
}
152154
}
153155

154-
private MongoSecurityException wrapInMongoSecurityException(final Throwable t) {
155-
return t instanceof MongoSecurityException
156-
? (MongoSecurityException) t
157-
: new MongoSecurityException(getCredential(), "Exception authenticating " + getCredential(), t);
156+
private MongoException wrapException(final Throwable t) {
157+
if (t instanceof MongoInterruptedException) {
158+
return (MongoInterruptedException) t;
159+
} else if (t instanceof MongoSecurityException) {
160+
return (MongoSecurityException) t;
161+
} else {
162+
return new MongoSecurityException(getCredential(), "Exception authenticating " + getCredential(), t);
163+
}
158164
}
159165

160166
void doAsSubject(final java.security.PrivilegedAction<Void> action) {
@@ -182,7 +188,7 @@ private final class Continuator implements SingleResultCallback<BsonDocument> {
182188
@Override
183189
public void onResult(final BsonDocument result, final Throwable t) {
184190
if (t != null) {
185-
callback.onResult(null, wrapInMongoSecurityException(t));
191+
callback.onResult(null, wrapException(t));
186192
disposeOfSaslClient(saslClient);
187193
} else if (result.getBoolean("done").getValue()) {
188194
callback.onResult(null, null);
@@ -205,7 +211,7 @@ public Void run() {
205211
sendSaslContinueAsync(saslStartDocument.getInt32("conversationId"),
206212
saslClient.evaluateChallenge((result.getBinary("payload")).getData()), connection, Continuator.this);
207213
} catch (SaslException e) {
208-
throw wrapInMongoSecurityException(e);
214+
throw wrapException(e);
209215
}
210216
return null;
211217
}

0 commit comments

Comments
 (0)