Spring security Spring安全性,以复杂对象作为权限

Spring security Spring安全性,以复杂对象作为权限,spring-security,Spring Security,是否有人知道如何将复杂对象用作spring安全授权,而不是实现自定义accessDecisionManager。我不想实现自定义accessDecisionManager,因为我还需要重新实现角色投票者,这与SPeL一起工作,我认为这不是一个好主意。是的,可能最简单的方法是连接一个bean: @Component public class MyAuthorizer { boolean authorize(Authentication authentication) { /

是否有人知道如何将复杂对象用作spring安全授权,而不是实现自定义accessDecisionManager。我不想实现自定义accessDecisionManager,因为我还需要重新实现角色投票者,这与SPeL一起工作,我认为这不是一个好主意。

是的,可能最简单的方法是连接一个bean:

@Component
public class MyAuthorizer {
    boolean authorize(Authentication authentication) {
        // do your custom checking here
    }
}
然后

@Controller
public class MyController {
    @PreAuthorize("@myAuthorizer.authorize(authentication)")
    // ... request mapping, etc
}
或者,如果可以将复杂对象简化为字符串,
hasAuthority
将像处理简单权限一样工作:

public class MyCustomAuthority implements GrantedAuthority {
    Object all;
    Object my;
    Object complexity;

    public String getAuthority() {
        return String.valueOf(this.complexity);
    }
}