【问题标题】:Spring Security, complex object as authoritySpring Security,复杂对象作为权限
【发布时间】:2018-05-31 07:35:46
【问题描述】:

有谁知道如何使用复杂对象作为spring安全权限,而不是实现自定义accessDecisionManager。我不想实现自定义 accessDecisionManager,因为我还需要重新实现角色投票者,这适用于 SPeL,并且认为这不是一个好主意。

【问题讨论】:

    标签: spring-security


    【解决方案1】:

    是的,可能最简单的方法是连接 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);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2013-09-30
      • 2014-04-05
      • 2013-06-01
      • 1970-01-01
      • 2011-10-14
      • 2014-06-02
      • 1970-01-01
      • 2013-10-14
      相关资源
      最近更新 更多