Spring Oauth2 SSO:使用 AuthorizationServer 授予的权限
Spring Oauth2 SSO: Use Authority granted by AuthorizationServer
我的设置是一个 AuthorizationServer,我在其中对 ldap 进行身份验证。
当我直接从授权服务器请求用户时
他有一个特定的权限,具体取决于 ldap 组。
调试时查看ResourceServer中的Oauth2Authentication,只有userAuthentication.details.authorities有这个权限。任何其他权限设置为 ROLE_USER。
是否可以使用AuthorizationServer提供的用户权限?
如果我使用 spring.oauth2.resource.tokenInfoUri 来检索权限,它会起作用。但是我想使用 AuthorizationServer 提供的 UserDetails..
解决方案是创建自定义 UserInfoTokenServices 并按照我在 中解释的那样提供它。
在此 UserInfoTokenServices 中,我能够从授权服务器的 /users
端点的响应中提取权限。
!!更新!!使用 Spring Boot 1.4.0,事情变得更容易了!
使用 Spring Boot 1.4.0 a PrincipalExtractor was introduced. This class should be implemented to extract a custom principal (see Spring Boot 1.4 Release Notes).
如果仅与权限有关,您可以实施 AuthoritiesExtractor。
我的设置是一个 AuthorizationServer,我在其中对 ldap 进行身份验证。 当我直接从授权服务器请求用户时 他有一个特定的权限,具体取决于 ldap 组。
调试时查看ResourceServer中的Oauth2Authentication,只有userAuthentication.details.authorities有这个权限。任何其他权限设置为 ROLE_USER。
是否可以使用AuthorizationServer提供的用户权限?
如果我使用 spring.oauth2.resource.tokenInfoUri 来检索权限,它会起作用。但是我想使用 AuthorizationServer 提供的 UserDetails..
解决方案是创建自定义 UserInfoTokenServices 并按照我在
在此 UserInfoTokenServices 中,我能够从授权服务器的 /users
端点的响应中提取权限。
!!更新!!使用 Spring Boot 1.4.0,事情变得更容易了!
使用 Spring Boot 1.4.0 a PrincipalExtractor was introduced. This class should be implemented to extract a custom principal (see Spring Boot 1.4 Release Notes).
如果仅与权限有关,您可以实施 AuthoritiesExtractor。