* 1. This is the first connection from this browser session.
* 2. The 'reset' parameter has been passed on the request
* 3. The logon state machine is in {@link LogonStateAndCache#STATE_RETURN_TO_LOGON}
*
*/
UserDatabase udb = UserDatabaseManager.getInstance().getUserDatabase(form.getRealmName());
if (logonStateMachine == null || logonStateMachine.getState() == LogonStateAndCache.STATE_RETURN_TO_LOGON || reset) {
/*
* If the client is already logged on, then we got here because
* a <i>Session Lock</i> has occured and so only require
* the users password
*/
if (LogonControllerFactory.getInstance().hasClientLoggedOn(request, response) == LogonController.LOGGED_ON) {
logonStateMachine = new LogonStateAndCache(LogonStateAndCache.STATE_DISPLAY_USERNAME_ENTERED, request.getSession());
logonStateMachine.setUser(LogonControllerFactory.getInstance().getUser(request));
form.initUser();
form.setHasMoreAuthenticationSchemes(false);
} else {
/*
* This is a brand new session so we require the username
*/
logonStateMachine = new LogonStateAndCache(LogonStateAndCache.STATE_STARTED, request.getSession());
request.getSession().removeAttribute(Constants.AUTH_SESSION);
if(!Util.isNullOrTrimmedBlank(form.getUsername())) {
try {
User user = udb.getAccount(form.getUsername());
logonStateMachine.removeFromSpoofCache(user.getPrincipalName());
form.initUser();
try {
logonStateMachine.setUser(user);
}
catch(AccountLockedException ale) {
// Continue anyway and get the exception later
}
logonStateMachine.setState(LogonStateAndCache.STATE_DISPLAY_USERNAME_ENTERED);
}
catch(UserNotFoundException unfe) {
form.initUser();
// Spoof some authentication schemes
form.setHasMoreAuthenticationSchemes(true);
}
}
}
} else {
/*
* A username has been provided but it was unknown. The error message
* indicating this will not be displayed until the next stage is
* complete
*/
if (logonStateMachine.getState() == LogonStateAndCache.STATE_UNKNOWN_USERNAME) {
logonStateMachine.setState(LogonStateAndCache.STATE_UNKNOWN_USERNAME_PROMPT_FOR_PASSWORD);
}
else if (logonStateMachine.getState() == LogonStateAndCache.STATE_KNOWN_USERNAME_MULTIPLE_SCHEMES_SELECT){
/*
* The scheme to sign on with has changed, so we need to update the
* logon state machine.
*/
logonStateMachine.forceHighestPriorityScheme(request.getParameter("selectedAuthenticationScheme"),
request.getParameter("username"));
logonStateMachine.setState(LogonStateAndCache.STATE_KNOWN_USERNAME_MULTIPLE_SCHEMES);
} else if (logonStateMachine.getState() == LogonStateAndCache.STATE_KNOWN_USERNAME_NO_SCHEME_SPOOF_PASSWORD_ENTRY){
/*
* The scheme to sign on with has changed, so we need to update the
* logon state machine
*/
logonStateMachine.setSpoofedHighestPriorityScheme(request.getParameter("username"));
}
else if(logonStateMachine.getState() == LogonStateAndCache.STATE_DISPLAY_USERNAME_ENTRY){
/*
* The username has been collected, now process it.
*/
if(Util.isNullOrTrimmedBlank(form.getUsername())) {
/**
* Page refreshed, stay in same state
*/
logonStateMachine.setState(LogonStateAndCache.STATE_STARTED);
}
else {
logonStateMachine.setState(LogonStateAndCache.STATE_DISPLAY_USERNAME_ENTERED);
try {
User user = udb.getAccount(form.getUsername());
logonStateMachine.removeFromSpoofCache(user.getPrincipalName());
try {
logonStateMachine.setUser(user);
}
catch(AccountLockedException ale) {