package com.cvicse.interceptor;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
public class AuthrityInterceptor extends AbstractInterceptor {
private static final long serialVersionUID = 4297635740201526003L;
@Override
public String intercept(ActionInvocation invocation) throws Exception {
System.out.println("hello");
ActionContext ctx = invocation.getInvocationContext();
String user = (String)ctx.getSession().get("user");
System.out.println(user);
if(user != null){
return invocation.invoke();
}
HttpServletResponse response = ServletActionContext.getResponse();
String rootPath = ServletActionContext.getRequest().getContextPath();
response.sendRedirect(rootPath + "/login.jsp");
return null;
}
}