* @return forward
* @throws Exception on any error
*/
public static ActionForward checkAuthSession(LogonForm form, boolean reset, ActionMapping mapping, HttpServletRequest request,
HttpServletResponse response, LogonStateAndCache logonStateMachine) throws Exception{
AuthenticationScheme authScheme = (AuthenticationScheme) request.getSession().getAttribute(Constants.AUTH_SESSION);
if (authScheme == null || reset || authScheme.getResourceId() != logonStateMachine.getHighestPriorityScheme().getResourceId()) {
if (log.isDebugEnabled())
log.debug("Creating new authentication session using scheme '" + "THE SCHEME NAME" + "'");
// Try to initalise the highest priority scheme,
if (request.getSession().getAttribute(Constants.SESSION_LOCKED) != null) {
// If session locked then only display password
SessionInfo info = LogonControllerFactory.getInstance().getSessionInfo(request);
Calendar now = new GregorianCalendar();
authScheme = new DefaultAuthenticationScheme(info.getRealmId(), Integer.MAX_VALUE, "Fake sheme", "Fake scheme",
now, now, true, 0);
authScheme.addModule(PasswordAuthenticationModule.MODULE_NAME);
} else {
authScheme = logonStateMachine.getHighestPriorityScheme();
}
if (authScheme == null) {
log.info("There are no authenticated schemes.");
return null;
} else {
authScheme.setUser(logonStateMachine.getUser());
authScheme.init(request.getSession());
if (authScheme.nextAuthenticationModule() == null) {
throw new Exception("No authentication modules have been configured.");
}
request.getSession().setAttribute(Constants.AUTH_SESSION, authScheme);
if (log.isDebugEnabled())
log.debug("Scheme " + authScheme.getSchemeName() + " initialised OK");
}
}
while (true) {
AuthenticationModule module = authScheme.currentAuthenticationModule();
if (form != null) {
form.setCurrentModuleIndex(authScheme.getCurrentModuleIndex());
}
// The module may wish to forward somewhere other than to the
// default login page
ActionForward forward = module.startAuthentication(mapping, request, response);
if (module.isRequired()) {
return forward;
} else {
// Are we at the end of the sequence
if (authScheme.nextAuthenticationModule() == null) {
return LogonAction.finishAuthentication(authScheme, request, response);
}
}
}
}