要实现这一点,您似乎必须:
- 创建模型(用户,角色,权限)以及检索给定用户权限的方法;
- 定义自己的
org.springframework.security.authentication.ProviderManager
并将其配置(设置其提供程序)为customorg.springframework.security.authentication.AuthenticationProvider
。最后一个应该在其authenticate方法上返回Authentication,应该使用来设置org.springframework.security.core.GrantedAuthority
(在您的情况下)给定用户的所有权限。
该文章中的技巧是为用户分配角色,但是要为
Authentication.authorities对象中的这些角色设置权限。
为此,我建议您阅读API,并查看是否可以扩展一些基本的ProviderManager和AuthenticationProvider而不是全部实现。我已经完成了
org.springframework.security.ldap.authentication.LdapAuthenticationProvider设置自定义LdapAuthoritiesPopulator的操作,该操作将为用户检索正确的角色。
希望这次我能得到您想要的。祝好运。



