#java #spring-boot #spring-security #microservices
#java #spring-boot #spring-безопасность #микросервисы
Вопрос:
У меня есть RESTful API для приложений. В настоящее время мой ресурс проверяется с серверов авторизации. (Рисунок 1). Я хочу, чтобы мой ресурс должен быть проверен на разных удаленных нескольких серверах авторизации. (Рисунок 2). Как я могу реализовать ResourceServerTokenServices
это?
Мои текущие настройки следуют figure (1)
WebSecurityConfigurerAdapter:
@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