String password = new String(((PasswordCallback)callbacks[1]).getPassword());
((PasswordCallback)callbacks[1]).clearPassword();
if (username == null || password == null)
return false;
Authenticator authenticator = (Authenticator)getContainer().getComponentInstanceOfType(Authenticator.class);
if (authenticator == null)
throw new LoginException("No Authenticator component found, check your configuration");
Credential[] credentials =
new Credential[]{new UsernameCredential(username), new PasswordCredential(password)};
String userId = authenticator.validateUser(credentials);
identity = authenticator.createIdentity(userId);
sharedState.put("javax.security.auth.login.name", userId);
// TODO use PasswordCredential wrapper
subject.getPrivateCredentials().add(password);
subject.getPublicCredentials().add(new UsernameCredential(username));
}