if (writableRequest.getType() == RequestType.SASL_TOKEN_MESSAGE_REQUEST) {
// initialize server-side SASL functionality, if we haven't yet
// (in which case we are looking at the first SASL message from the
// client).
SaslNettyServer saslNettyServer =
ctx.attr(NettyServer.CHANNEL_SASL_NETTY_SERVERS).get();
if (saslNettyServer == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("No saslNettyServer for " + ctx.channel() +
" yet; creating now, with secret manager: " + secretManager);
}
try {
saslNettyServer = new SaslNettyServer(secretManager,
AuthMethod.SIMPLE);
} catch (IOException ioe) { //TODO:
throw new RuntimeException(ioe);
}
ctx.attr(NettyServer.CHANNEL_SASL_NETTY_SERVERS).set(saslNettyServer);
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Found existing saslNettyServer on server:" +
ctx.channel().localAddress() + " for client " +
ctx.channel().remoteAddress());
}
}
((SaslTokenMessageRequest) writableRequest).processToken(saslNettyServer);
// Send response to client.
ctx.write(writableRequest);
if (saslNettyServer.isComplete()) {
// If authentication of client is complete, we will also send a
// SASL-Complete message to the client.
if (LOG.isDebugEnabled()) {
LOG.debug("SASL authentication is complete for client with " +
"username: " + saslNettyServer.getUserName());
}
SaslCompleteRequest saslComplete = new SaslCompleteRequest();
ctx.write(saslComplete);
if (LOG.isDebugEnabled()) {
LOG.debug("Removing SaslServerHandler from pipeline since SASL " +