Skip to content

Commit c3adeb8

Browse files
committed
trimming the whitespace for this provider.
see gh-17487
1 parent 6164e3e commit c3adeb8

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesRegistrationAdapter.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ private static ClientRegistration getClientRegistration(String registrationId,
7575

7676
private static Builder getBuilderFromIssuerIfPossible(String registrationId, String configuredProviderId,
7777
Map<String, Provider> providers) {
78-
String providerId = (configuredProviderId != null) ? configuredProviderId : registrationId;
78+
String providerId = StringUtils
79+
.trimWhitespace((configuredProviderId != null) ? configuredProviderId : registrationId);
7980
if (providers.containsKey(providerId)) {
8081
Provider provider = providers.get(providerId);
8182
String issuer = provider.getIssuerUri();
@@ -89,7 +90,8 @@ private static Builder getBuilderFromIssuerIfPossible(String registrationId, Str
8990

9091
private static Builder getBuilder(String registrationId, String configuredProviderId,
9192
Map<String, Provider> providers) {
92-
String providerId = (configuredProviderId != null) ? configuredProviderId : registrationId;
93+
String providerId = StringUtils
94+
.trimWhitespace((configuredProviderId != null) ? configuredProviderId : registrationId);
9395
CommonOAuth2Provider provider = getCommonProvider(providerId);
9496
if (provider == null && !providers.containsKey(providerId)) {
9597
throw new IllegalStateException(getErrorMessage(configuredProviderId, registrationId));

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesRegistrationAdapterTests.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,31 @@ void oidcProviderConfigurationWithCustomConfigurationOverridesProviderDefaults()
251251
assertThat(userInfoEndpoint.getUserNameAttributeName()).isEqualTo("sub");
252252
}
253253

254+
@Test
255+
void getClientRegistrationsWhenRegistrationProviderPropertyShouldBeTrimmed() {
256+
OAuth2ClientProperties properties = new OAuth2ClientProperties();
257+
OAuth2ClientProperties.Registration registration = createRegistration(" provider ");
258+
Provider provider = createProvider();
259+
properties.getProvider().put("provider", provider);
260+
properties.getRegistration().put("registration", registration);
261+
assertThat(OAuth2ClientPropertiesRegistrationAdapter.getClientRegistrations(properties)).isNotEmpty();
262+
}
263+
264+
@Test
265+
void getClientRegistrationsWhenRegistrationProviderPropertyWithIssuerShouldBeTrimmed() throws Exception {
266+
this.server = new MockWebServer();
267+
this.server.start();
268+
String issuer = this.server.url("").toString();
269+
setupMockResponse(issuer);
270+
OAuth2ClientProperties properties = new OAuth2ClientProperties();
271+
OAuth2ClientProperties.Registration registration = createRegistration(" provider ");
272+
Provider provider = createProvider();
273+
provider.setIssuerUri(issuer);
274+
properties.getProvider().put("provider", provider);
275+
properties.getRegistration().put("registration", registration);
276+
assertThat(OAuth2ClientPropertiesRegistrationAdapter.getClientRegistrations(properties)).isNotEmpty();
277+
}
278+
254279
private Provider createProvider() {
255280
Provider provider = new Provider();
256281
provider.setAuthorizationUri("https://example.com/auth");

0 commit comments

Comments
 (0)