论坛首页 Java企业应用论坛

讨论一下Spring MVC 中的 SimpleFormController 权限控制

浏览 3916 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (10) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-04-30  
用Spring2.5的 SimpleFormController 时,想在formBackingObject()函数里面设置一个权限控制,验证用户没有权限则跳转,但却发现SimpleFormController 中好像没有这么一个跳转功能。感觉这方面SimpleFormController 真是不是太好。
   发表时间:2009-05-01   最后修改:2009-05-01
Calf 写道
用Spring2.5的 SimpleFormController 时,想在formBackingObject()函数里面设置一个权限控制,验证用户没有权限则跳转,但却发现SimpleFormController 中好像没有这么一个跳转功能。感觉这方面SimpleFormController 真是不是太好。


SimpleFormController实现了Controller中的handleRequest(request,response)方法,所有的流程都被隐藏起来了,只把formBackingObject,onsubmit少数方法暴露给你。如果你想在进入表单之前就做判断,你有几个选择:
1、Filter;
2、Interpret;
3、Aop,截住handleRequest方法;

我习惯第三种方法,给出下面代码供你参考:

@Aspect
public class Access{
@Around("execution(* YourSimpleFormController.handleRequest(..))")
public Object check(ProceedingJoinPoint thisJoinPoint) throws Throwable{
   Object[] args=thisJoinPoint.getArgs();
   HttpServletRequest request=(HttpServletRequest)args[0];
   HttpServletResponse response=(HttpServletResponse)args[1];
   /*对request中的数据判断用户的权限如果不成功response.setRedirect
     或者request.getRequestDispatcher.forward或者直接返回一个新的ModelAndView
     ex: return new ModelAndView("noright");
     
     如果用户有权限,你就运行thisJoinPoint.proceed();把控制权还给SimpleFormController.
   */
}
}
0 请登录后投票
   发表时间:2009-05-15  
大哥,能不能给个具体的例子看看?
0 请登录后投票
   发表时间:2009-05-15  
权限这些 还是用拦截器吧
0 请登录后投票
   发表时间:2009-05-15  
laiseeme 写道
权限这些 还是用拦截器吧


用filter吗?
也给个例子参考下吧。
0 请登录后投票
   发表时间:2009-05-16  
laiseeme 写道
权限这些 还是用拦截器吧

对的,支持用拦截器(Intercepter)
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics