加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

DWR 过滤器验证权限

发布时间:2020-12-16 01:56:30 所属栏目:百科 来源:网络整理
导读:实现方法:在dwr每个方法调用前拦截验证权限 1.实现拦截器(需dwr2.0以上版本) package net.gkyh.util; import java.lang.reflect.Method; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.directwebremotin
实现方法:在dwr每个方法调用前拦截验证权限
1.实现拦截器(需dwr2.0以上版本)


package net.gkyh.util;
import java.lang.reflect.Method;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.directwebremoting.AjaxFilter;
import org.directwebremoting.AjaxFilterChain;
import org.directwebremoting.WebContext;
import org.directwebremoting.WebContextFactory;


public class DWRFilter implements AjaxFilter{
public Object doFilter(Object object,Method method,Object[] arr,
AjaxFilterChain chain) throws Exception {
//获取session
WebContext ctx = WebContextFactory.get();
HttpServletRequest request = ctx.getHttpServletRequest();
HttpSession session = request.getSession();
String flag =(String) session.getAttribute("flag");
if(null == flag){
System.out.println("session验证失败");
return "session_error";
}
//拦截调用方法
String methodName=method.getName();
System.out.println("拦截目标方法:"+methodName);

if(!CheckLimit(methodName)){
System.out.println("权限验证失败");
return "limit_error";
}
Object obj=chain.doFilter(object,method,arr);
System.out.println("目标方法"+method.getName()+"执行结束");
return obj;
}
}
2.修改dwr.xml,添加红色部分
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN" "http://www.getahead.ltd.uk/dwr/dwr10.dtd">
<dwr>
<allow>
<create javascript="TermManager" creator="spring" scope="application">
<param name="beanName" value="TermManager"></param>
</create>
<filter class="net.gkyh.util.DWRFilter"></filter> </allow> </dwr> 3.调用TermManager中的方法时会先执行DWRFilter拦截器

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读