String password)
throws SaslException {
final String msg =
"PLAIN: Authentication credentials verification failed!";
char passwd[] = password.toCharArray();
AuthenticateCallback authnCb =
new AuthenticateCallback(username, passwd);
for (int i = 0; i < passwd.length; i++)
passwd[i] = ' ';
passwd = null;
try {
cbh.handle(new Callback[] { authnCb });
} catch (IOException e) {
throw new SaslException(msg, e);
} catch (UnsupportedCallbackException e) {
throw new SaslException(msg, e);
}
authnCb.clearPassword();
if (!authnCb.isAuthenticated()) {
throw new AuthenticationException(msg);
}
}