複数のトークンを検証できるようにしたいSpring SecurityアプリがありAuthorization
ます-Googleまたは内部サービスからベアラートークンを含むヘッダーを渡し、バックエンドに各サービスで順番に検証を試みさせたいです。
resource.setOrder(x)
私の問題は、(低いx 値に基づいて) 最初のものしか表示されないことです。つまり、2 つのリソース サーバー構成がありますが、最初の構成のみを使用し、2 番目の構成は使用していません。
Google を 3 に設定し、もう一方を 4 に設定すると、Google トークンの検証は機能しますが、アクセスしようとする/
と許可され、Google フィルターが機能していることがわかります (BTE for Google
出力で) が、構成した 2 番目のフィルターは機能しません ( BTE for App
) 。 .
次のように 2 つの ResourceServer を構成しようとしています。
@Bean
protected ResourceServerConfiguration googleLoginResources() {
ResourceServerConfiguration resource = new ResourceServerConfiguration() {
public void setConfigurers(List<ResourceServerConfigurer> configurers) {
super.setConfigurers(configurers);
}
};
resource.setConfigurers(Collections.<ResourceServerConfigurer>singletonList(new ResourceServerConfigurerAdapter() {
ResourceServerTokenServices googleLoginTokenServices(OAuthProperties oAuthProperties, AccessTokenValidator tokenValidator) {
LOGGER.info("Configuring Google ResourceServerTokenServices");
GoogleTokenServices googleTokenServices = new GoogleTokenServices(tokenValidator);
googleTokenServices.setUserInfoUrl(oAuthProperties.getUserInfoUrl());
return googleTokenServices;
}
AccessTokenValidator googleLoginTokenValidator(OAuthProperties oAuthProperties) {
LOGGER.info("Configuring Google AccessTokenValidator");
GoogleAccessTokenValidator accessTokenValidator = new GoogleAccessTokenValidator();
accessTokenValidator.setClientId(oAuthProperties.getClientId());
accessTokenValidator.setCheckTokenUrl(oAuthProperties.getCheckTokenUrl());
return accessTokenValidator;
}
class BTEG extends BearerTokenExtractor {
@Override
protected String extractToken(HttpServletRequest request) {
LOGGER.info("BTE for Google");
return super.extractToken(request);
}
}
@Override
public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
LOGGER.info("Configuring Google ResourceServerSecurityConfigurer");
resources.resourceId(oAuthProperties.getClientId());
ResourceServerTokenServices gts = googleLoginTokenServices(oAuthProperties, googleLoginTokenValidator(oAuthProperties));
// DelegatingTokenServices dts = new DelegatingTokenServices();
// dts.addResourceServerTokenServices(gts);
resources.tokenServices(gts);
resources.tokenExtractor(new BTEG());
}
@Override
public void configure(HttpSecurity http) throws Exception {
LOGGER.info("Configuring HTTP");
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
http
.cors().and()
//.csrf().ignoringAntMatchers("/h2-console/**").and()
.authorizeRequests()
.antMatchers(HttpMethod.OPTIONS, "/login/google").permitAll()
//.antMatchers("/h2-console/**").permitAll()
.antMatchers("/login/google").hasRole("GOOGLE_USER")
//.antMatchers("/").permitAll()
;
}
}));
resource.setOrder(3);
return resource;
}
@Bean
protected ResourceServerConfiguration appLoginResources() {
ResourceServerConfiguration resource = new ResourceServerConfiguration() {
public void setConfigurers(List<ResourceServerConfigurer> configurers) {
super.setConfigurers(configurers);
}
};
resource.setConfigurers(Collections.<ResourceServerConfigurer>singletonList(new ResourceServerConfigurerAdapter() {
class BTEA extends BearerTokenExtractor {
@Override
protected String extractToken(HttpServletRequest request) {
LOGGER.info("BTE for App");
return super.extractToken(request);
}
}
@Override
public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
LOGGER.info("Configuring App ResourceServerSecurityConfigurer");
resources.resourceId("app");
resources.tokenExtractor(new BTEA());
}
@Override
public void configure(HttpSecurity http) throws Exception {
LOGGER.info("Configuring App HTTP");
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
http
//.cors().and()
.authorizeRequests()
//.antMatchers(HttpMethod.OPTIONS, "/").permitAll()
.antMatchers("/").hasRole("ASDF")
;
}
}));
resource.setOrder(4);
return resource;
}
これを両方 (または必要に応じてそれ以上) で機能させるにはどうすればよいですか?