private SSOToken authenticateUser(String username, String password) throws PasswordValidationCallback.PasswordValidationException
{
debug.message("Entering SampleAMUsernamePasswordValidator.authenticateUser");
AuthContext ac = null;
SSOToken token = null;
debug.message("Username is "+username);
debug.message("OrgName is "+orgName);
try {
debug.message("Trying to make an AuthContext");
ac = new AuthContext(orgName);
debug.message("Made an AuthContext");
ac.login();
debug.message("Logged in AuthContext");
} catch (LoginException le) {
debug.error( "Failed to create AuthContext", le );
throw new PasswordValidationCallback.PasswordValidationException("Failed to create AuthContext", le);
}
try {
Callback[] callbacks = null;
// Get the information requested by the plug-ins
while (ac.hasMoreRequirements()) {
callbacks = ac.getRequirements();
if (callbacks != null) {
addLoginCallbackMessage(callbacks, orgName, username, password);
ac.submitRequirements(callbacks);
}
}
if (ac.getStatus() == AuthContext.Status.SUCCESS) {
debug.message("Authentication successful");
} else if (ac.getStatus() == AuthContext.Status.FAILED) {
debug.message("Authentication failed");
throw new PasswordValidationCallback.PasswordValidationException("Authentication failed");
} else {
debug.message("Unknown authentication status: " + ac.getStatus());
throw new PasswordValidationCallback.PasswordValidationException("Unknown authentication status: " + ac.getStatus());
}
} catch (Exception e) {
debug.error( "Authentication failed", e );
throw new PasswordValidationCallback.PasswordValidationException("Authentication failed", e);
}
try {
debug.message("Trying to get SSO token");
token = ac.getSSOToken();
debug.message("Got SSO token");
} catch (Exception e) {
debug.error( "getSSOToken failed", e );
throw new PasswordValidationCallback.PasswordValidationException("getSSOToken failed", e);
}