Make ClientRegistration.clientSecret optional
Fixes gh-5652
This commit is contained in:
parent
8a0c6868cd
commit
010d99a7d0
|
@ -20,6 +20,7 @@ import org.springframework.security.oauth2.core.AuthorizationGrantType;
|
||||||
import org.springframework.security.oauth2.core.ClientAuthenticationMethod;
|
import org.springframework.security.oauth2.core.ClientAuthenticationMethod;
|
||||||
import org.springframework.security.oauth2.core.oidc.OidcScopes;
|
import org.springframework.security.oauth2.core.oidc.OidcScopes;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -463,7 +464,7 @@ public final class ClientRegistration {
|
||||||
|
|
||||||
clientRegistration.registrationId = this.registrationId;
|
clientRegistration.registrationId = this.registrationId;
|
||||||
clientRegistration.clientId = this.clientId;
|
clientRegistration.clientId = this.clientId;
|
||||||
clientRegistration.clientSecret = this.clientSecret;
|
clientRegistration.clientSecret = StringUtils.hasText(this.clientSecret) ? this.clientSecret : "";
|
||||||
clientRegistration.clientAuthenticationMethod = this.clientAuthenticationMethod;
|
clientRegistration.clientAuthenticationMethod = this.clientAuthenticationMethod;
|
||||||
clientRegistration.authorizationGrantType = this.authorizationGrantType;
|
clientRegistration.authorizationGrantType = this.authorizationGrantType;
|
||||||
clientRegistration.redirectUriTemplate = this.redirectUriTemplate;
|
clientRegistration.redirectUriTemplate = this.redirectUriTemplate;
|
||||||
|
@ -488,7 +489,6 @@ public final class ClientRegistration {
|
||||||
() -> "authorizationGrantType must be " + AuthorizationGrantType.AUTHORIZATION_CODE.getValue());
|
() -> "authorizationGrantType must be " + AuthorizationGrantType.AUTHORIZATION_CODE.getValue());
|
||||||
Assert.hasText(this.registrationId, "registrationId cannot be empty");
|
Assert.hasText(this.registrationId, "registrationId cannot be empty");
|
||||||
Assert.hasText(this.clientId, "clientId cannot be empty");
|
Assert.hasText(this.clientId, "clientId cannot be empty");
|
||||||
Assert.hasText(this.clientSecret, "clientSecret cannot be empty");
|
|
||||||
Assert.notNull(this.clientAuthenticationMethod, "clientAuthenticationMethod cannot be null");
|
Assert.notNull(this.clientAuthenticationMethod, "clientAuthenticationMethod cannot be null");
|
||||||
Assert.hasText(this.redirectUriTemplate, "redirectUriTemplate cannot be empty");
|
Assert.hasText(this.redirectUriTemplate, "redirectUriTemplate cannot be empty");
|
||||||
Assert.hasText(this.authorizationUri, "authorizationUri cannot be empty");
|
Assert.hasText(this.authorizationUri, "authorizationUri cannot be empty");
|
||||||
|
@ -515,7 +515,6 @@ public final class ClientRegistration {
|
||||||
() -> "authorizationGrantType must be " + AuthorizationGrantType.CLIENT_CREDENTIALS.getValue());
|
() -> "authorizationGrantType must be " + AuthorizationGrantType.CLIENT_CREDENTIALS.getValue());
|
||||||
Assert.hasText(this.registrationId, "registrationId cannot be empty");
|
Assert.hasText(this.registrationId, "registrationId cannot be empty");
|
||||||
Assert.hasText(this.clientId, "clientId cannot be empty");
|
Assert.hasText(this.clientId, "clientId cannot be empty");
|
||||||
Assert.hasText(this.clientSecret, "clientSecret cannot be empty");
|
|
||||||
Assert.notNull(this.clientAuthenticationMethod, "clientAuthenticationMethod cannot be null");
|
Assert.notNull(this.clientAuthenticationMethod, "clientAuthenticationMethod cannot be null");
|
||||||
Assert.hasText(this.tokenUri, "tokenUri cannot be empty");
|
Assert.hasText(this.tokenUri, "tokenUri cannot be empty");
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,21 +124,22 @@ public class ClientRegistrationTests {
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void buildWhenAuthorizationCodeGrantClientSecretIsNullThenThrowIllegalArgumentException() {
|
public void buildWhenAuthorizationCodeGrantClientSecretIsNullThenDefaultToEmpty() {
|
||||||
ClientRegistration.withRegistrationId(REGISTRATION_ID)
|
ClientRegistration clientRegistration = ClientRegistration.withRegistrationId(REGISTRATION_ID)
|
||||||
.clientId(CLIENT_ID)
|
.clientId(CLIENT_ID)
|
||||||
.clientSecret(null)
|
.clientSecret(null)
|
||||||
.clientAuthenticationMethod(ClientAuthenticationMethod.BASIC)
|
.clientAuthenticationMethod(ClientAuthenticationMethod.BASIC)
|
||||||
.authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
|
.authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
|
||||||
.redirectUriTemplate(REDIRECT_URI)
|
.redirectUriTemplate(REDIRECT_URI)
|
||||||
.scope(SCOPES.toArray(new String[0]))
|
.scope(SCOPES.toArray(new String[0]))
|
||||||
.authorizationUri(AUTHORIZATION_URI)
|
.authorizationUri(AUTHORIZATION_URI)
|
||||||
.tokenUri(TOKEN_URI)
|
.tokenUri(TOKEN_URI)
|
||||||
.userInfoAuthenticationMethod(AuthenticationMethod.FORM)
|
.userInfoAuthenticationMethod(AuthenticationMethod.FORM)
|
||||||
.jwkSetUri(JWK_SET_URI)
|
.jwkSetUri(JWK_SET_URI)
|
||||||
.clientName(CLIENT_NAME)
|
.clientName(CLIENT_NAME)
|
||||||
.build();
|
.build();
|
||||||
|
assertThat(clientRegistration.getClientSecret()).isEqualTo("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
@ -462,16 +463,15 @@ public class ClientRegistrationTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void buildWhenClientCredentialsGrantClientSecretIsNullThenThrowIllegalArgumentException() {
|
public void buildWhenClientCredentialsGrantClientSecretIsNullThenDefaultToEmpty() {
|
||||||
assertThatThrownBy(() ->
|
ClientRegistration clientRegistration = ClientRegistration.withRegistrationId(REGISTRATION_ID)
|
||||||
ClientRegistration.withRegistrationId(REGISTRATION_ID)
|
.clientId(CLIENT_ID)
|
||||||
.clientId(CLIENT_ID)
|
.clientSecret(null)
|
||||||
.clientSecret(null)
|
.clientAuthenticationMethod(ClientAuthenticationMethod.BASIC)
|
||||||
.clientAuthenticationMethod(ClientAuthenticationMethod.BASIC)
|
.authorizationGrantType(AuthorizationGrantType.CLIENT_CREDENTIALS)
|
||||||
.authorizationGrantType(AuthorizationGrantType.CLIENT_CREDENTIALS)
|
.tokenUri(TOKEN_URI)
|
||||||
.tokenUri(TOKEN_URI)
|
.build();
|
||||||
.build()
|
assertThat(clientRegistration.getClientSecret()).isEqualTo("");
|
||||||
).isInstanceOf(IllegalArgumentException.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue