}
}
public void receiveSaslMechanisms(final SaslMechanisms saslMechanisms)
{
SaslInit init = new SaslInit();
init.setHostname(_remoteHostname);
Set<Symbol> mechanisms = new HashSet<Symbol>(Arrays.asList(saslMechanisms.getSaslServerMechanisms()));
if (mechanisms.contains(SASL_PLAIN) && _password != null)
{
init.setMechanism(SASL_PLAIN);
byte[] usernameBytes = _user.getName().getBytes(Charset.forName("UTF-8"));
byte[] passwordBytes = _password.getBytes(Charset.forName("UTF-8"));
byte[] initResponse = new byte[usernameBytes.length + passwordBytes.length + 2];
System.arraycopy(usernameBytes, 0, initResponse, 1, usernameBytes.length);
System.arraycopy(passwordBytes, 0, initResponse, usernameBytes.length + 2, passwordBytes.length);
init.setInitialResponse(new Binary(initResponse));
}
else if (mechanisms.contains(SASL_ANONYMOUS))
{
init.setMechanism(SASL_ANONYMOUS);
}
else if (mechanisms.contains(SASL_EXTERNAL))
{
init.setMechanism(SASL_EXTERNAL);
}
_saslFrameOutput.send(new SASLFrame(init), null);
}