/**
* Bootstrap the authentication process on the current request.
* @return
*/
public CompleteAuthState bootstrap() {
CompleteAuthState result = new CompleteAuthState();
try {
AuthSession authSession = null;
// Try to get the existing auth session. While bootstrapping,
// errors in this step will lead to resetting of the auth process
try {
authSession = authSessionService.get();
}
catch(AuthException ax) {
Logger.error("Authentication error while trying to get auth " +
"session. Reseting auth system in clean state", ax);
authSystemCleanerProvider.get().clean();
}
if (authSession != null) {
result.setAuthState(AuthState.authenticated);
result.setAuthServiceName(authSession.getAuthServiceName());
return result;
}
//Reaching this step means there was no existing auth session.
//In stead get the auth initialization
AuthInitialization authInit =
authInitService.get();
result.setAuthServiceName(authInit.getAuthServiceName());
switch (authInit.getState()) {
case nil: { //Implies user has not started authenticating yet
result.setAuthState(AuthState.nil);
break;
}
case registering: {
result.setAuthState(handleRegistration(authInit));
break;
}
case authenticating: {
result.setAuthState(handleAuthentication(authInit));
}
}
}
catch(Exception ex) {
Logger.error("Error bootstrapping authentication", ex);
result.setAuthState(AuthState.serverError);
}
return result;
}