2013-03-05 37 views

回答

2

据我所知,没有办法来定义这种政策。

但是你可以建立一个Spring MVC的拦截器,在运行时将检查相应的处理方法进行预授权注释的存在:

public class PreAuthorizeChecker implements HandlerInterceptor { 

    @Override 
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { 
     if (handler instanceof HandlerMethod) { 
      HandlerMethod hm = (HandlerMethod) handler; 
      PreAuthorize annotation = AnnotationUtils.findAnnotation(hm.getMethod(), PreAuthorize.class); 
      if (annotation == null) { 
       // prevent access to method wihout security restrictions 
       throw new RuntimeException("Rights are not defined for this handler"); 
      } 

     } 
     return true; 
    } 
..... 
} 
+0

感谢 - 这正是我一直在寻找。 – slipheed 2013-03-05 19:44:12

+0

你好。 – 2013-03-06 09:01:20

相关问题