if (path.endsWith(loginPageUrl)) {
logoutAction(request, sessionId);
return;
} else if (isFreeAccessExtensions(path)) {
if (sessionId != null) {
Session session = SessionManager.getInstance().getSession(sessionId, false);
if (session != null) {
remoteUser = (String) session.getAttribute(sessionUsernameKey);
if (remoteUser != null) {
context.setAttribute(remoteUserKey, remoteUser);
}
}
}
return; //skip by this filter.
} else if (isMatchLoginUrl(request)) {
//login check
remoteUser = checkUser(request, context);
context.setAttribute(remoteUserKey, remoteUser);
Session session = SessionManager.getInstance().createSession();
session.setAttribute(sessionUsernameKey, remoteUser);
response.setHeader("Set-Cookie", sessionCookieName + "=" + session.getId() + "; Path=/");
context.setAttribute(SC_AUTHORIZED, Boolean.TRUE);
} else if (StringUtils.isNotEmpty(sessionId)) {
//already login. -> session check
Session session = SessionManager.getInstance().getSession(sessionId, false);
if (session == null) { //invalid session.
throw new UnauthorizedException();
}
remoteUser = (String) session.getAttribute(sessionUsernameKey);
if (remoteUser == null) { //invalid session.
throw new UnauthorizedException();
}
context.setAttribute(remoteUserKey, remoteUser);
if (path.endsWith(logoutActionUrl)) {