package com.fusionability.web.interceptor; import org.apache.struts2.ServletActionContext; import com.fusionability.web.bean.User; import com.fusionability.web.utils.Constants; import com.opensymphony.xwork2.Action; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.interceptor.AbstractInterceptor; /** * 认证拦截器(可以拦截URL的跳转) */ public class AuthInterceptor extends AbstractInterceptor { @Override public String intercept(ActionInvocation invocation) throws Exception { if("/FusionAbility/user/register.action".equals(ServletActionContext.getRequest().getRequestURI()) ||"/FusionAbility/user/login.action".equals(ServletActionContext.getRequest().getRequestURI()) ||"/FusionAbility/user/doRegister.action".equals(ServletActionContext.getRequest().getRequestURI()) ||"/FusionAbility/user/doLogin.action".equals(ServletActionContext.getRequest().getRequestURI()) ||"/FusionAbility/user/isExistUser.action".equals(ServletActionContext.getRequest().getRequestURI()) ||"/FusionAbility/user/refreshPatchcaImage.action".equals(ServletActionContext.getRequest().getRequestURI()) ||"/FusionAbility/user/doMail.action".equals(ServletActionContext.getRequest().getRequestURI()) ||"/FusionAbility/user/isRightCode.action".equals(ServletActionContext.getRequest().getRequestURI()) ||"/FusionAbility/user/updateRetrievepassword.action".equals(ServletActionContext.getRequest().getRequestURI()) ||"/FusionAbility/user/goUpdateRetrievepassword.action".equals(ServletActionContext.getRequest().getRequestURI())){ return invocation.invoke(); } User user = (User)ServletActionContext.getRequest().getSession().getAttribute(Constants.SESSION_USER); if (user == null) { //重定向到登录页面 return Action.LOGIN; } return invocation.invoke(); } }
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="interceptorPackage" extends="struts-default"> <interceptors> <interceptor name="authInterceptor" class="com.fusionability.web.interceptor.AuthInterceptor"></interceptor> <interceptor-stack name="traceStack"> <interceptor-ref name="defaultStack"></interceptor-ref> <interceptor-ref name="authInterceptor"></interceptor-ref> </interceptor-stack> </interceptors> <default-interceptor-ref name="traceStack"></default-interceptor-ref> </package> </struts>
捐助开发者
在兴趣的驱动下,写一个免费
的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(右上角的爱心标志,支持支付宝和PayPal捐助),没钱捧个人场,谢谢各位。
谢谢您的赞助,我会做的更好!