1
0
mirror of synced 2026-08-06 02:08:01 +00:00

Remove HttpClientConfig

Issue gh-4478
This commit is contained in:
Joe Grandja
2017-09-12 21:03:40 -04:00
parent 95de158909
commit 4ff0b52f74
5 changed files with 28 additions and 149 deletions
@@ -15,11 +15,9 @@
*/
package org.springframework.security.config.annotation.web.configurers.oauth2.client;
import org.springframework.context.ApplicationContext;
import org.springframework.security.config.annotation.web.HttpSecurityBuilder;
import org.springframework.security.config.annotation.web.configurers.AbstractAuthenticationFilterConfigurer;
import org.springframework.security.core.authority.mapping.GrantedAuthoritiesMapper;
import org.springframework.security.jose.jws.JwsAlgorithm;
import org.springframework.security.jwt.JwtDecoder;
import org.springframework.security.jwt.nimbus.NimbusJwtDecoderJwkSupport;
import org.springframework.security.oauth2.client.authentication.AuthorizationCodeAuthenticationProcessingFilter;
@@ -36,7 +34,6 @@ import org.springframework.security.oauth2.client.token.SecurityTokenRepository;
import org.springframework.security.oauth2.client.user.OAuth2UserService;
import org.springframework.security.oauth2.client.user.nimbus.NimbusOAuth2UserService;
import org.springframework.security.oauth2.core.AccessToken;
import org.springframework.security.oauth2.core.http.HttpClientConfig;
import org.springframework.security.oauth2.core.provider.DefaultProviderMetadata;
import org.springframework.security.oauth2.core.provider.ProviderMetadata;
import org.springframework.security.oauth2.core.user.OAuth2User;
@@ -134,8 +131,8 @@ final class AuthorizationCodeAuthenticationFilterConfigurer<H extends HttpSecuri
@Override
public void init(H http) throws Exception {
AuthorizationCodeAuthenticationProvider authenticationProvider = new AuthorizationCodeAuthenticationProvider(
this.getAuthorizationCodeTokenExchanger(http), this.getAccessTokenRepository(),
this.getProviderJwtDecoderRegistry(http), this.getUserInfoService(http));
this.getAuthorizationCodeTokenExchanger(), this.getAccessTokenRepository(),
this.getProviderJwtDecoderRegistry(), this.getUserInfoService());
if (this.userAuthoritiesMapper != null) {
authenticationProvider.setAuthoritiesMapper(this.userAuthoritiesMapper);
}
@@ -160,14 +157,9 @@ final class AuthorizationCodeAuthenticationFilterConfigurer<H extends HttpSecuri
this.authorizationResponseMatcher : this.getAuthenticationFilter().getAuthorizationResponseMatcher());
}
private AuthorizationGrantTokenExchanger<AuthorizationCodeAuthenticationToken> getAuthorizationCodeTokenExchanger(H http) {
private AuthorizationGrantTokenExchanger<AuthorizationCodeAuthenticationToken> getAuthorizationCodeTokenExchanger() {
if (this.authorizationCodeTokenExchanger == null) {
NimbusAuthorizationCodeTokenExchanger nimbusAuthorizationCodeTokenExchanger = new NimbusAuthorizationCodeTokenExchanger();
HttpClientConfig httpClientConfig = this.getHttpClientConfig(http);
if (httpClientConfig != null) {
nimbusAuthorizationCodeTokenExchanger.setHttpClientConfig(httpClientConfig);
}
this.authorizationCodeTokenExchanger = nimbusAuthorizationCodeTokenExchanger;
this.authorizationCodeTokenExchanger = new NimbusAuthorizationCodeTokenExchanger();
}
return this.authorizationCodeTokenExchanger;
}
@@ -179,11 +171,10 @@ final class AuthorizationCodeAuthenticationFilterConfigurer<H extends HttpSecuri
return this.accessTokenRepository;
}
private ProviderJwtDecoderRegistry getProviderJwtDecoderRegistry(H http) {
HttpClientConfig httpClientConfig = this.getHttpClientConfig(http);
private ProviderJwtDecoderRegistry getProviderJwtDecoderRegistry() {
Map<ProviderMetadata, JwtDecoder> jwtDecoders = new HashMap<>();
ClientRegistrationRepository clientRegistrationRepository = OAuth2LoginConfigurer.getClientRegistrationRepository(this.getBuilder());
clientRegistrationRepository.getRegistrations().stream().forEach(registration -> {
clientRegistrationRepository.getRegistrations().forEach(registration -> {
ClientRegistration.ProviderDetails providerDetails = registration.getProviderDetails();
if (StringUtils.hasText(providerDetails.getJwkSetUri())) {
DefaultProviderMetadata providerMetadata = new DefaultProviderMetadata();
@@ -198,15 +189,15 @@ final class AuthorizationCodeAuthenticationFilterConfigurer<H extends HttpSecuri
providerMetadata.setTokenEndpoint(this.toURL(providerDetails.getTokenUri()));
providerMetadata.setUserInfoEndpoint(this.toURL(providerDetails.getUserInfoUri()));
providerMetadata.setJwkSetUri(this.toURL(providerDetails.getJwkSetUri()));
NimbusJwtDecoderJwkSupport nimbusJwtDecoderJwkSupport = new NimbusJwtDecoderJwkSupport(
providerDetails.getJwkSetUri(), JwsAlgorithm.RS256, httpClientConfig);
NimbusJwtDecoderJwkSupport nimbusJwtDecoderJwkSupport =
new NimbusJwtDecoderJwkSupport(providerDetails.getJwkSetUri());
jwtDecoders.put(providerMetadata, nimbusJwtDecoderJwkSupport);
}
});
return new DefaultProviderJwtDecoderRegistry(jwtDecoders);
}
private OAuth2UserService getUserInfoService(H http) {
private OAuth2UserService getUserInfoService() {
if (this.userInfoService == null) {
NimbusOAuth2UserService nimbusOAuth2UserService = new NimbusOAuth2UserService();
if (!this.customUserTypes.isEmpty()) {
@@ -215,21 +206,11 @@ final class AuthorizationCodeAuthenticationFilterConfigurer<H extends HttpSecuri
if (!this.userNameAttributeNames.isEmpty()) {
nimbusOAuth2UserService.setUserNameAttributeNames(this.userNameAttributeNames);
}
HttpClientConfig httpClientConfig = this.getHttpClientConfig(http);
if (httpClientConfig != null) {
nimbusOAuth2UserService.setHttpClientConfig(httpClientConfig);
}
this.userInfoService = nimbusOAuth2UserService;
}
return this.userInfoService;
}
private HttpClientConfig getHttpClientConfig(H http) {
Map<String, HttpClientConfig> httpClientConfigs =
http.getSharedObject(ApplicationContext.class).getBeansOfType(HttpClientConfig.class);
return (!httpClientConfigs.isEmpty() ? httpClientConfigs.values().iterator().next() : null);
}
private URL toURL(String urlStr) {
if (!StringUtils.hasText(urlStr)) {
return null;