package com.sais.inkaNet.business.login.interceptor;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
import com.sais.inkaNet.business.login.findpassword.action.FindPassWordAction;
import com.sais.inkaNet.business.login.login.action.LoginAction;
import com.sais.inkaNet.common.util.constants.IPortalConstants;
import org.apache.log4j.Logger;
import org.apache.log4j.MDC;
import java.util.Map;
/**
* <p>类名称: [登录拦截器]</p>
* <p>类描述: [拦截器]</p>
*
public class CheckLoginInterceptor extends MethodFilterInterceptor {
/**
* <p>方法描述: [session校验拦截器]</p>
*
* @param actionInvocation 参数说明
*
* @return 返回结果的说明
*
* @throws Exception 抛出异常的原因
*/
@SuppressWarnings("unchecked")
public String myIntercept(ActionInvocation actionInvocation) throws Exception {
Object action = actionInvocation.getAction();
//-----------------判断action实体是否instanceof登录Action,登录Action请求被允许---------------------------
if (action instanceof LoginAction) {
LOGGER.info("CheckLoginInterceptor拦截-->:验证用户登录,这是一个loginAction,请求被允许");
return actionInvocation.invoke();
}else if(action instanceof FindPassWordAction){
LOGGER.info("CheckLoginInterceptor拦截-->:验证用户忘记密码,FindPassWordAction,请求被允许");
return actionInvocation.invoke();
}
Map session = actionInvocation.getInvocationContext().getSession();
String keyid = (String) session.get("userId");
if (keyid == null) {
LOGGER.info("CheckLoginInterceptor拦截-->:验证用户,该用户不合法跳转到登录页面重新登录");
} else {
//--------将日志公用信息放入MDC中----------
MDC.put("logPreFix", new StringBuffer("-->【").append(account).append("|").append(userName)
.append("】"));
LOGGER.info("CheckLoginInterceptor拦截-->:验证用户,合法用户");
return actionInvocation.invoke();
}
return "!/login.jsp";
}
/**
* <p>方法描述: [方法功能中文描述]</p>
*/
public void destroy() {
super.destroy();
LOGGER.info("销毁拦截器");
MDC.remove("logPreFix");
}
@Override
protected String doIntercept(ActionInvocation arg0) throws Exception {
return myIntercept(arg0);
}
}
拦截器
最新推荐文章于 2024-08-31 23:30:52 发布