1

Springセキュリティアプリケーションをアノテーションに切り替えたいのですが、@PreAuthorize外部からの呼び出しを許可する前に、すべてのリクエストに独自のアノテーションがあることを確認したいと思います。

このためのポリシーでSpringSecurityを設定することは可能ですか?

4

1 に答える 1

3

私の知る限り、そのような種類のポリシーを定義する方法はありません。

ただし、実行時に対応するハンドラーメソッドのPreAuthorizeアノテーションの存在をチェックするSpringMVCインターセプターを設定できます。

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;
    }
.....
}
于 2013-03-05T17:02:31.037 に答える