spring oauth2 sersecurity-如何实现多个resourceservertokenservices

kupeojn6  于 2021-07-08  发布在  Java
关注(0)|答案(0)|浏览(316)

我有一个应用程序restfulapi。目前,我的资源已从授权服务器验证(图1)。我希望我的资源必须根据不同的远程多授权服务器进行验证(图2)。

如何实施 ResourceServerTokenServices 做这个?
我的当前设置跟踪 figure (1) Web安全配置适配器:

@Configuration
@EnableResourceServer
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
@Order(Ordered.HIGHEST_PRECEDENCE)
public class OAuth2ClientConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    private ResourceServerProperties sso;

    @Bean
    @Primary
    public ResourceServerTokenServices userInfoTokenServices() {
        CustomUserInfoTokenServices serv = new CustomUserInfoTokenServices(sso.getUserInfoUri(), sso.getClientId());
        return serv;
    }
}

customuserinfotokenservices:

public class CustomUserInfoTokenServices implements ResourceServerTokenServices {

    private final String userInfoEndpointUrl;

    private final String clientId;

    public CustomUserInfoTokenServices(String userInfoEndpointUrl, String clientId) {
        this.userInfoEndpointUrl = userInfoEndpointUrl;
        this.clientId = clientId;
    }

    @Override
    public OAuth2Authentication loadAuthentication(String accessToken) throws AuthenticationException, InvalidTokenException {
        // Call API from userInfoEndpointUrl
        // Extract result to get OAuth2Authentication
        return //OAuth2Authentication;
    }

    @Override
    public OAuth2AccessToken readAccessToken(String accessToken) {
        throw new UnsupportedOperationException("Not supported: read access token");
    }

我的应用程序属性:


# Resource port

server.port = 8081

# Server oauth configuare

security.oauth2.client.clientId = CLIENT_ID
security.oauth2.client.clientSecret = CLIENT_SECRET

# Authorization server

security.oauth2.resource.user-info-uri = http://127.0.0.1:8080/oauth/user/me

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题