{
context.sendResponse("503 Refusing any other AUTH command.");
return;
}
MessageHandler msgHandler = getMessageHandler(context);
boolean authenticating = context.getSession().isAuthenticating();
if (!authenticating)
{
String[] args = getArgs(commandString);
// Let's check the command syntax
if (args.length < 2)
{
context.sendResponse("501 Syntax: " + VERB
+ " mechanism [initial-response]");
return;
}
// Let's check if we support the required authentication mechanism
String mechanism = args[1];
if (!msgHandler.getAuthenticationMechanisms().contains(
mechanism.toUpperCase()))
{
context
.sendResponse("504 The requested authentication mechanism is not supported");
return;
}
}
// OK, let's go trough the authentication process.
// The authentication process may require a series of
// challenge-responses
try
{
if (authenticating && commandString.trim().equals(AUTH_CANCEL_COMMAND))
{
// RFC 2554 explicitly states this:
context.sendResponse("501 Authentication canceled by client.");
return;
}
StringBuilder response = new StringBuilder();
boolean finished = msgHandler.auth(commandString, response, context);
context.getSession().setAuthenticating(!finished);
if (!finished)
{