Trim OAuth2 provider property whitespace

Update `OAuth2ClientPropertiesRegistrationAdapter` to trim whitespace
of the "provider" property.

See gh-17497
pull/17662/head
Dmytro Nosan 5 years ago committed by Phillip Webb
parent fb1dd8fe93
commit efce9388e7

@ -56,9 +56,10 @@ public final class OAuth2ClientPropertiesRegistrationAdapter {
private static ClientRegistration getClientRegistration(String registrationId, private static ClientRegistration getClientRegistration(String registrationId,
OAuth2ClientProperties.Registration properties, Map<String, Provider> providers) { OAuth2ClientProperties.Registration properties, Map<String, Provider> providers) {
Builder builder = getBuilderFromIssuerIfPossible(registrationId, properties.getProvider(), providers); String provider = StringUtils.trimWhitespace(properties.getProvider());
Builder builder = getBuilderFromIssuerIfPossible(registrationId, provider, providers);
if (builder == null) { if (builder == null) {
builder = getBuilder(registrationId, properties.getProvider(), providers); builder = getBuilder(registrationId, provider, providers);
} }
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull(); PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
map.from(properties::getClientId).to(builder::clientId); map.from(properties::getClientId).to(builder::clientId);

@ -251,6 +251,31 @@ public class OAuth2ClientPropertiesRegistrationAdapterTests {
assertThat(userInfoEndpoint.getUserNameAttributeName()).isEqualTo("sub"); 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() { private Provider createProvider() {
Provider provider = new Provider(); Provider provider = new Provider();
provider.setAuthorizationUri("https://example.com/auth"); provider.setAuthorizationUri("https://example.com/auth");

Loading…
Cancel
Save