Spring Boot + Spring Security + Hierarchical Roles

前端 未结 5 1823
甜味超标
甜味超标 2020-12-13 21:59

I\'m trying to setup hierarchical roles in my Spring Boot app without success. I\'ve done all that\'s been said in different places in the Internet. But with none of them ha

5条回答
  •  醉话见心
    2020-12-13 22:30

    You have to set the role hierarchy on the MethodSecurityExpressionHandler:

    @Configuration
    @EnableGlobalMethodSecurity(prePostEnabled = true)
    public static class GlobalMethodSecurityConfig extends GlobalMethodSecurityConfiguration {
        @Autowired
        private RoleHierarchy roleHierarchy;
    
        @Override
        protected MethodSecurityExpressionHandler createExpressionHandler() {
            final DefaultMethodSecurityExpressionHandler handler = new DefaultMethodSecurityExpressionHandler();
            handler.setRoleHierarchy(this.roleHierarchy);
            return handler;
        }
    }
    

    Check Javadoc for @EnableGlobalMethodSecurity for further information. Especially notice: that EnableGlobalMethodSecurity still must be included on the class extending GlobalMethodSecurityConfiguration to determine the settings.

提交回复
热议问题