(PasswordValidationCallback.PlainTextPasswordRequest) request;
final String username = plainTextRequest.getUsername();
final String password = plainTextRequest.getPassword();
LoginContext loginContext;
try {
loginContext = new LoginContext(getLoginContextName(), new AbstractCallbackHandler() {
@Override
protected void handleInternal(Callback callback) throws UnsupportedCallbackException {
if (callback instanceof NameCallback) {
((NameCallback) callback).setName(username);
}
else if (callback instanceof PasswordCallback) {
((PasswordCallback) callback).setPassword(password.toCharArray());
}
else {
throw new UnsupportedCallbackException(callback);
}
}
});
}
catch (LoginException ex) {
throw new PasswordValidationCallback.PasswordValidationException(ex);
}
catch (SecurityException ex) {
throw new PasswordValidationCallback.PasswordValidationException(ex);
}
try {
loginContext.login();
Subject subject = loginContext.getSubject();
if (!subject.getPrincipals().isEmpty()) {
if (logger.isDebugEnabled()) {
logger.debug("Authentication request for user '" + username + "' successful");
}
return true;