Added login redirect
This commit is contained in:
parent
eafb34d2c2
commit
af6e662aae
3 changed files with 20 additions and 4 deletions
|
|
@ -20,9 +20,10 @@ public interface ZalleryConstants {
|
|||
|
||||
/** Session Constants **/
|
||||
|
||||
public static final String SESSION_KEY_USER_MSG = "zall_user_message";
|
||||
public static final String SESSION_KEY_USER_OBJ = "zall_user";
|
||||
public static final long SESSION_TIMEOUT = 3*24*60*60*1000; // 2 day
|
||||
public static final String SESSION_KEY_USER_MSG = "zall_user_message";
|
||||
public static final String SESSION_KEY_USER_OBJ = "zall_user";
|
||||
public static final String SESSION_KEY_LOGIN_FRWD = "login_forward";
|
||||
public static final long SESSION_TIMEOUT = 3*24*60*60*1000; // 2 day
|
||||
|
||||
/** Cookie Constants **/
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import java.io.IOException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static zall.ZalleryConstants.SESSION_KEY_LOGIN_FRWD;
|
||||
|
||||
/**
|
||||
* This filter will check if user is valid, if not it will redirect to the login page
|
||||
*/
|
||||
|
|
@ -53,11 +55,17 @@ public class AuthenticationFilter implements Filter {
|
|||
} else {
|
||||
// do not continue the filter pipeline forward to login page
|
||||
logger.fine("User not authenticated, redirecting to login page.");
|
||||
httpRequest.getSession().putValue(SESSION_KEY_LOGIN_FRWD, getRequestURL(httpRequest));
|
||||
ZalleryServlet.redirect(LoginServlet.URI, httpRequest, (HttpServletResponse) response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getRequestURL(HttpServletRequest request){
|
||||
return request.getRequestURI() +
|
||||
(ObjectUtil.isEmpty(request.getQueryString()) ? "" : "?" + request.getQueryString());
|
||||
}
|
||||
|
||||
private boolean isWhitelisted(HttpServletRequest request) {
|
||||
if (ObjectUtil.isEmpty(request))
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import zall.Zallery;
|
|||
import zall.ZalleryServlet;
|
||||
import zall.bean.User;
|
||||
import zall.manager.AuthenticationManager;
|
||||
import zutil.ObjectUtil;
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.ui.UserMessageManager;
|
||||
|
|
@ -17,6 +18,8 @@ import java.io.IOException;
|
|||
import java.sql.SQLException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static zall.ZalleryConstants.SESSION_KEY_LOGIN_FRWD;
|
||||
|
||||
|
||||
@WebServlet(LoginServlet.URI)
|
||||
public class LoginServlet extends ZalleryServlet {
|
||||
|
|
@ -40,7 +43,11 @@ public class LoginServlet extends ZalleryServlet {
|
|||
// Forward user
|
||||
if (user != null) {
|
||||
logger.fine("User(" + user.getEmail() + ") already authenticated, forwarding to gallery.");
|
||||
redirect(GalleryServlet.URI, request, response);
|
||||
|
||||
if (ObjectUtil.isEmpty(request.getSession().getAttribute(SESSION_KEY_LOGIN_FRWD)))
|
||||
redirect((String)request.getSession().getAttribute(SESSION_KEY_LOGIN_FRWD), request, response);
|
||||
else
|
||||
redirect(GalleryServlet.URI, request, response);
|
||||
} else {
|
||||
include(JSP_FILE, request, response);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue