1
我想將Spring安全應用程序轉換爲註釋,但我希望確保每個請求都有其自己的@PreAuthorize
註釋,然後才允許它被稱爲外部。我如何要求我的Spring應用程序中的所有請求處理程序都擁有@PreAuthorize
是否有可能爲此設置Spring Security?
我想將Spring安全應用程序轉換爲註釋,但我希望確保每個請求都有其自己的@PreAuthorize
註釋,然後才允許它被稱爲外部。我如何要求我的Spring應用程序中的所有請求處理程序都擁有@PreAuthorize
是否有可能爲此設置Spring Security?
據我所知,沒有辦法來定義這種政策。
但是你可以建立一個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;
}
.....
}
感謝 - 這正是我一直在尋找。 – slipheed 2013-03-05 19:44:12
你好。 – 2013-03-06 09:01:20