package cn.com.oneslife.interceptor;
import java.util.Map;
import org.apache.struts2.StrutsStatics;
import cn.com.oneslife.bean.Account;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
public class AuthInterceptor extends AbstractInterceptor{
private static final long serialVersionUID = 2305639447880823381L;
@SuppressWarnings("unchecked")
@Override
public String intercept(ActionInvocation invocation) throws Exception {
ActionContext context = invocation.getInvocationContext();
ActionSupport action = (ActionSupport)invocation.getAction();
Map<String,Object> session = context.getSession();
Account acc = (Account) session.get("ACC_INFO");
Map<String,Object> request = (Map<String, Object>) context.get(StrutsStatics.HTTP_REQUEST);
String proId = (String) request.get("PROID");
if(null == acc){
action.addActionError("Sorry,You not have login! please login!");
return ActionSupport.LOGIN;
}
if(null == proId || "".equals(proId)){
action.addActionError("Sorry,You should be appoint proId!");
return ActionSupport.INPUT;
}
if(hasAuth(acc.getId(),proId)){
return invocation.invoke();
}else{
action.addActionError("Sorry,You not have auth!");
return ActionSupport.INPUT;
}
}
private Boolean hasAuth(Integer accId,String proId){
return Boolean.TRUE;
}
}
分享到:
相关推荐
Struts2拦截器实现权限控制demo,我感觉对初学者还是有一定帮助的
struts 拦截器实现权限拦截,例子简单易懂,有详细的注释。
综合使用servlet filter与struts2 interceptor对权限进行验证。
struts2 用拦截器 实现用户权限登录 可以直接运行,只单单用到struts的东西。
NULL 博文链接:https://luckyhua.iteye.com/blog/1863458
里面是自己实现struts拦截器的一个原理,基于jdk的动态代理
一个关于struts拦截器的简单例子,适合初学者!
Struts2拦截器(Interceptor) Struts2拦截器(Interceptor)
基于SSH2框架Struts2拦截器的登录验证实现
运用struts2的拦截器技术实现的页面检测拦截非法用户饿坏指定用户注册。。。
使用struts拦截器+注解实现日志审计功能 详见博客: http://blog.csdn.net/lk_blog/article/details/10248395
利用Struts2的核心技术----拦截器实现权限控制。详细代码详解
Struts2拦截器的实现原理相对简单,当请求struts2的action时,Struts 2会查找配置文件,并根据其配置实例化相对的 拦截器对象,然后串成一个列表,最后一个一个地调用列表中的拦截器 三、定义Struts2拦截器。 ...
Struts拦截器的案例,没有使用Hibernate,使用的是JDBC,该代码的核心实现是拦截器,至于数据库可根据个人需求进行修改。
Struts2拦截器源程序 Struts2拦截器源程序 Struts2拦截器源程序 Struts2拦截器源程序 Struts2拦截器源程序
struts2拦截器和验证框架
struts1.x拦截器jar包,有saif-0.1.jar和 saif-spring.jar 两个jar包
使用struts的拦截器拦截一些敏感性的词或一些非法或不文秘的言论
使用Struts2实现用户权限拦截、重点是掌握拦截器的使用和配置方法,通过案例的学习,就能掌握struts中拦截器的使用方法,让我们能快速上手
Struts通过拦截器实现登录后跳转到登录前页面