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