我有一个支持 OAuth2 的 Spring Boot 应用程序。我有 2 个客户,每个客户都有自己的客户 ID:
@Configuration
@EnableAuthorizationServer
protected static class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter {
private static final String RESOURCE_ID = "my-rest-service";
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("clientOne")
.authorizedGrantTypes("password", "refresh_token")
.authorities("USER")
.scopes("read", "write")
.resourceIds(RESOURCE_ID)
.secret("123456"))
.and()
.withClient("clientTwo")
.authorizedGrantTypes("password", "refresh_token")
.scopes("read","write")
.resourceIds(RESOURCE_ID)
.secret("789654")
;
}
}
此外,我有一个User
其中有一个Role
. 我现在希望具有角色 ROLE_ONE 的用户在使用时只能获取身份验证令牌,clientOne
而具有 ROLE_TWO 的用户只能使用clientTwo
来获取该令牌。
我应该在哪里添加该逻辑?