@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException
{
String name = null;
String password = null;
AuthenticationResult authenticated = null;
for(Callback callback : callbacks)
{
if (callback instanceof NameCallback)
{
String id = ((NameCallback) callback).getDefaultName();
try
{
name = getNameFromId(id);
}
catch (NamingException e)
{
_logger.warn("SASL Authentication Exception", e);
}
if(password != null)
{
authenticated = doLDAPNameAuthentication(name, password);
}
}
else if (callback instanceof PlainPasswordCallback)
{
password = ((PlainPasswordCallback)callback).getPlainPassword();
if(name != null)
{
authenticated = doLDAPNameAuthentication(name, password);
if(authenticated.getStatus()== AuthenticationResult.AuthenticationStatus.SUCCESS)
{
((PlainPasswordCallback)callback).setAuthenticated(true);
}
}
}
else if (callback instanceof AuthorizeCallback)
{
((AuthorizeCallback) callback).setAuthorized(authenticated != null && authenticated.getStatus() == AuthenticationResult.AuthenticationStatus.SUCCESS);
}
else
{
throw new UnsupportedCallbackException(callback);
}