Rev 1081 | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.creation.interceptors;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import org.apache.struts2.ServletActionContext;import com.opensymphony.xwork2.ActionInvocation;import com.opensymphony.xwork2.interceptor.AbstractInterceptor;public class LoginInterceptor extends AbstractInterceptor {private static final long serialVersionUID = 1L;private static final String USER_NAME = "USERNAME";@Overridepublic String intercept(ActionInvocation invocation) throws Exception {HttpServletRequest request = ServletActionContext.getRequest();HttpServletResponse response = ServletActionContext.getResponse();HttpSession session = request.getSession(); // Get the existing session or create a new oneString username = (String) session.getAttribute(LoginInterceptor.USER_NAME);if(username == null){response.sendRedirect("/content/login");return null;}return invocation.invoke();}}