码迷,mamicode.com
首页 > 编程语言 > 详细

Spring security - why does RoleVoter supports all classes and WebExpressionVoter only supports subclasses of FilterInvocation?

时间:2020-01-21 14:42:49      阅读:84      评论:0      收藏:0      [点我收藏+]

标签:sep   spec   ref   method   man   required   represent   rate   div   

The secured object is an abstract representing whatever is secured. It may be a MethodInvocation in case of @Secured, @RolesAllowed, @PreFilter and @PreAuthorize, or a FilterInvocation in case of <intercept-url /> or any other object if required.

The @PreFilter and @PreAuthorize annotations are handled by PreInvocationAuthorizationAdviceVoter. It uses the MethodInvocation to get the annotations and their attributes values, so it has:

public boolean supports(Class<?> clazz) {
    return clazz.isAssignableFrom(MethodInvocation.class);
}

The WebExpressionVoter is web-invocation specific, because it matches the URL to the patterns from <intercept-url />, that‘s why it has:

public boolean supports(Class<?> clazz) {
    return clazz.isAssignableFrom(FilterInvocation.class);
}

The RoleVoter only uses the Authentication object contents, so it does not depend on the secured object, and that‘s why it has:

public boolean supports(Class<?> clazz) {
    return true;
}

Note, that You can have a separate AccessDecisionManager for URL level security and method level security. The first will use voters that support FilterInvocation, and the other the ones that support MethodInvocation. Also note that RoleVoter supports both so it can be used in both contexts.

 

关键在于,得加上

public boolean supports(Class<?> clazz) {
    return true;
}

Spring security - why does RoleVoter supports all classes and WebExpressionVoter only supports subclasses of FilterInvocation?

标签:sep   spec   ref   method   man   required   represent   rate   div   

原文地址:https://www.cnblogs.com/Hackerman/p/12221658.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!