mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Merge pull request #17497 from nosan
* pr/17497: Trim OAuth2 provider property whitespace Closes gh-17497
This commit is contained in:
commit
0da0bff397
@ -56,9 +56,10 @@ public final class OAuth2ClientPropertiesRegistrationAdapter {
|
||||
|
||||
private static ClientRegistration getClientRegistration(String registrationId,
|
||||
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) {
|
||||
builder = getBuilder(registrationId, properties.getProvider(), providers);
|
||||
builder = getBuilder(registrationId, provider, providers);
|
||||
}
|
||||
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
|
||||
map.from(properties::getClientId).to(builder::clientId);
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user