use of com.mongodb.MongoSecurityException in project mongo-java-driver by mongodb.
the class X509Authenticator method authenticate.
@Override
void authenticate(final InternalConnection connection, final ConnectionDescription connectionDescription) {
try {
validateUserName(connectionDescription);
BsonDocument authCommand = getAuthCommand(getCredential().getUserName());
executeCommand(getCredential().getSource(), authCommand, connection);
} catch (MongoCommandException e) {
throw new MongoSecurityException(getCredential(), "Exception authenticating", e);
}
}
use of com.mongodb.MongoSecurityException in project mongo-java-driver by mongodb.
the class NativeAuthenticator method authenticate.
@Override
public void authenticate(final InternalConnection connection, final ConnectionDescription connectionDescription) {
try {
BsonDocument nonceResponse = executeCommand(getCredential().getSource(), getNonceCommand(), connection);
BsonDocument authCommand = getAuthCommand(getCredential().getUserName(), getCredential().getPassword(), ((BsonString) nonceResponse.get("nonce")).getValue());
executeCommand(getCredential().getSource(), authCommand, connection);
} catch (MongoCommandException e) {
throw new MongoSecurityException(getCredential(), "Exception authenticating", e);
}
}
use of com.mongodb.MongoSecurityException in project mongo-java-driver by mongodb.
the class PlainAuthenticator method createSaslClient.
@Override
protected SaslClient createSaslClient(final ServerAddress serverAddress) {
final MongoCredential credential = getCredential();
isTrue("mechanism is PLAIN", credential.getAuthenticationMechanism() == PLAIN);
try {
return Sasl.createSaslClient(new String[] { PLAIN.getMechanismName() }, credential.getUserName(), DEFAULT_PROTOCOL, serverAddress.getHost(), null, new CallbackHandler() {
@Override
public void handle(final Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (final Callback callback : callbacks) {
if (callback instanceof PasswordCallback) {
((PasswordCallback) callback).setPassword(credential.getPassword());
} else if (callback instanceof NameCallback) {
((NameCallback) callback).setName(credential.getUserName());
}
}
}
});
} catch (SaslException e) {
throw new MongoSecurityException(credential, "Exception initializing SASL client", e);
}
}
use of com.mongodb.MongoSecurityException in project mongo-java-driver by mongodb.
the class GSSAPIAuthenticator method createSaslClient.
@Override
protected SaslClient createSaslClient(final ServerAddress serverAddress) {
MongoCredential credential = getCredential();
try {
Map<String, Object> saslClientProperties = getCredential().getMechanismProperty(JAVA_SASL_CLIENT_PROPERTIES_KEY, null);
if (saslClientProperties == null) {
saslClientProperties = new HashMap<String, Object>();
saslClientProperties.put(Sasl.MAX_BUFFER, "0");
saslClientProperties.put(Sasl.CREDENTIALS, getGSSCredential(credential.getUserName()));
}
SaslClient saslClient = Sasl.createSaslClient(new String[] { GSSAPI.getMechanismName() }, credential.getUserName(), credential.getMechanismProperty(SERVICE_NAME_KEY, SERVICE_NAME_DEFAULT_VALUE), getHostName(serverAddress), saslClientProperties, null);
if (saslClient == null) {
throw new MongoSecurityException(credential, String.format("No platform support for %s mechanism", GSSAPI));
}
return saslClient;
} catch (SaslException e) {
throw new MongoSecurityException(credential, "Exception initializing SASL client", e);
} catch (GSSException e) {
throw new MongoSecurityException(credential, "Exception initializing GSSAPI credentials", e);
} catch (UnknownHostException e) {
throw new MongoSecurityException(credential, "Unable to canonicalize host name + " + serverAddress);
}
}
Aggregations