From efce9388e7cec04c611afcb4ba9ad6d0f05f8118 Mon Sep 17 00:00:00 2001 From: Dmytro Nosan Date: Fri, 12 Jul 2019 13:01:27 +0300 Subject: [PATCH] Trim OAuth2 provider property whitespace Update `OAuth2ClientPropertiesRegistrationAdapter` to trim whitespace of the "provider" property. See gh-17497 --- ...h2ClientPropertiesRegistrationAdapter.java | 5 ++-- ...entPropertiesRegistrationAdapterTests.java | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesRegistrationAdapter.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesRegistrationAdapter.java index 6f50ad81d1..3293025def 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesRegistrationAdapter.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesRegistrationAdapter.java @@ -56,9 +56,10 @@ public final class OAuth2ClientPropertiesRegistrationAdapter { private static ClientRegistration getClientRegistration(String registrationId, OAuth2ClientProperties.Registration properties, Map providers) { - Builder builder = getBuilderFromIssuerIfPossible(registrationId, properties.getProvider(), providers); + String provider = StringUtils.trimWhitespace(properties.getProvider()); + Builder builder = getBuilderFromIssuerIfPossible(registrationId, provider, providers); if (builder == null) { - builder = getBuilder(registrationId, properties.getProvider(), providers); + builder = getBuilder(registrationId, provider, providers); } PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull(); map.from(properties::getClientId).to(builder::clientId); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesRegistrationAdapterTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesRegistrationAdapterTests.java index ead7f3c5ab..6fb73a4ac9 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesRegistrationAdapterTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesRegistrationAdapterTests.java @@ -251,6 +251,31 @@ public class OAuth2ClientPropertiesRegistrationAdapterTests { assertThat(userInfoEndpoint.getUserNameAttributeName()).isEqualTo("sub"); } + @Test + public void getClientRegistrationsWhenRegistrationProviderPropertyShouldBeTrimmed() { + OAuth2ClientProperties properties = new OAuth2ClientProperties(); + OAuth2ClientProperties.Registration registration = createRegistration(" provider "); + Provider provider = createProvider(); + properties.getProvider().put("provider", provider); + properties.getRegistration().put("registration", registration); + assertThat(OAuth2ClientPropertiesRegistrationAdapter.getClientRegistrations(properties)).isNotEmpty(); + } + + @Test + public void getClientRegistrationsWhenRegistrationProviderPropertyWithIssuerShouldBeTrimmed() throws Exception { + this.server = new MockWebServer(); + this.server.start(); + String issuer = this.server.url("").toString(); + setupMockResponse(issuer); + OAuth2ClientProperties properties = new OAuth2ClientProperties(); + OAuth2ClientProperties.Registration registration = createRegistration(" provider "); + Provider provider = createProvider(); + provider.setIssuerUri(issuer); + properties.getProvider().put("provider", provider); + properties.getRegistration().put("registration", registration); + assertThat(OAuth2ClientPropertiesRegistrationAdapter.getClientRegistrations(properties)).isNotEmpty(); + } + private Provider createProvider() { Provider provider = new Provider(); provider.setAuthorizationUri("https://example.com/auth");