17
17
package com .mongodb .connection ;
18
18
19
19
import com .mongodb .MongoCredential ;
20
+ import com .mongodb .MongoException ;
21
+ import com .mongodb .MongoInterruptedException ;
20
22
import com .mongodb .MongoSecurityException ;
21
23
import com .mongodb .ServerAddress ;
22
24
import com .mongodb .async .SingleResultCallback ;
@@ -63,7 +65,7 @@ public Void run() {
63
65
res = sendSaslContinue (conversationId , response , connection );
64
66
}
65
67
} catch (Exception e ) {
66
- throw wrapInMongoSecurityException (e );
68
+ throw wrapException (e );
67
69
} finally {
68
70
disposeOfSaslClient (saslClient );
69
71
}
@@ -86,7 +88,7 @@ public Void run() {
86
88
@ Override
87
89
public void onResult (final BsonDocument result , final Throwable t ) {
88
90
if (t != null ) {
89
- callback .onResult (null , wrapInMongoSecurityException (t ));
91
+ callback .onResult (null , wrapException (t ));
90
92
} else if (result .getBoolean ("done" ).getValue ()) {
91
93
callback .onResult (null , null );
92
94
} else {
@@ -95,7 +97,7 @@ public void onResult(final BsonDocument result, final Throwable t) {
95
97
}
96
98
});
97
99
} catch (SaslException e ) {
98
- throw wrapInMongoSecurityException (e );
100
+ throw wrapException (e );
99
101
}
100
102
return null ;
101
103
}
@@ -151,10 +153,14 @@ private void disposeOfSaslClient(final SaslClient saslClient) {
151
153
}
152
154
}
153
155
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
+ }
158
164
}
159
165
160
166
void doAsSubject (final java .security .PrivilegedAction <Void > action ) {
@@ -182,7 +188,7 @@ private final class Continuator implements SingleResultCallback<BsonDocument> {
182
188
@ Override
183
189
public void onResult (final BsonDocument result , final Throwable t ) {
184
190
if (t != null ) {
185
- callback .onResult (null , wrapInMongoSecurityException (t ));
191
+ callback .onResult (null , wrapException (t ));
186
192
disposeOfSaslClient (saslClient );
187
193
} else if (result .getBoolean ("done" ).getValue ()) {
188
194
callback .onResult (null , null );
@@ -205,7 +211,7 @@ public Void run() {
205
211
sendSaslContinueAsync (saslStartDocument .getInt32 ("conversationId" ),
206
212
saslClient .evaluateChallenge ((result .getBinary ("payload" )).getData ()), connection , Continuator .this );
207
213
} catch (SaslException e ) {
208
- throw wrapInMongoSecurityException (e );
214
+ throw wrapException (e );
209
215
}
210
216
return null ;
211
217
}
0 commit comments