use of javax.security.sasl.SaslException 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);
}
}
use of javax.security.sasl.SaslException in project hadoop by apache.
the class TestSaslRPC method testSaslPlainServerBadPassword.
@Test
public void testSaslPlainServerBadPassword() {
SaslException e = null;
try {
runNegotiation(new TestPlainCallbacks.Client("user", "pass1"), new TestPlainCallbacks.Server("user", "pass2"));
} catch (SaslException se) {
e = se;
}
assertNotNull(e);
String message = e.getMessage();
assertContains("PLAIN auth failed", message);
assertContains("wrong password", message);
}
use of javax.security.sasl.SaslException in project hadoop by apache.
the class SaslPlainServer method evaluateResponse.
@Override
public byte[] evaluateResponse(byte[] response) throws SaslException {
if (completed) {
throw new IllegalStateException("PLAIN authentication has completed");
}
if (response == null) {
throw new IllegalArgumentException("Received null response");
}
try {
String payload;
try {
payload = new String(response, "UTF-8");
} catch (Exception e) {
throw new IllegalArgumentException("Received corrupt response", e);
}
// [ authz, authn, password ]
String[] parts = payload.split("