Blame | Last modification | View Log | RSS feed
package in.shop2020.support.interceptors;import javax.servlet.ServletContext;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 oneServletContext context = ServletActionContext.getServletContext();String username = (String) session.getAttribute(LoginInterceptor.USER_NAME);if(username == null){response.sendRedirect(context.getContextPath() + "/reports");return null;}return invocation.invoke();}}