?
struts-action-trace.xml
?
<package name="tracePackage" namespace="/trace" extends="exceptionPackage">
<interceptors>
<interceptor name="traceAuthInterceptor" class="com.fusionability.web.interceptor.TraceAuthInterceptor"></interceptor>
<interceptor-stack name="traceAuthInterceptorStack">
<interceptor-ref name="defaultStack"></interceptor-ref>
<interceptor-ref name="traceAuthInterceptor"></interceptor-ref>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="traceAuthInterceptorStack"></default-interceptor-ref>
<action name="showAppList" class="wKJSAppAction" method="showAppList">
<result name="success">/application/application_list.jsp</result>
</action>
</package>
?
?
package com.fusionability.web.interceptor;
import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import com.fusionability.user.service.UserService;
import com.fusionability.web.bean.User;
import com.fusionability.web.bean.UserAppRelation;
import com.fusionability.web.utils.Constants;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
/**
* @author baoyou E-mail:curiousby@163.com
* @version 2015年12月23日 下午2:47:10
*
* desc: ...
*/
@SuppressWarnings("serial")
public class TraceAuthInterceptor extends AbstractInterceptor {
private static Logger log = Logger.getLogger(TraceAuthInterceptor.class);
private UserService userService;
@Override
public String intercept(ActionInvocation invocation) throws Exception {
User user = (User)ServletActionContext.getRequest().getSession().getAttribute(Constants.SESSION_USER);
if (user == null) {
return Action.LOGIN;
}else{
if( !"/FusionAbility/trace/showAppList.action".equals(ServletActionContext.getRequest().getRequestURI())){
try {
String appid = ServletActionContext.getRequest().getParameter("appid");
UserAppRelation userAppRelation = userService.getUserAppRelation(user.getUserid(), appid);
if (userAppRelation != null) {
return invocation.invoke();
}
return "error";
} catch (Exception e) {
//e.printStackTrace();
return "error";
}
}
return invocation.invoke();
}
}
public UserService getUserService() {
return userService;
}
public void setUserService(UserService userService) {
this.userService = userService;
}
}
?
?
?
?
?
?
?
?
?
?
原文:http://knight-black-bob.iteye.com/blog/2266046