2013-03-05 36 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

相關問題