Polish gh-70
This commit is contained in:
parent
8700ff19df
commit
78f44c7327
@ -19,10 +19,19 @@ package org.springframework.security.oauth2.server.authorization;
|
|||||||
* Internal class used for serialization across Spring Security Authorization Server classes.
|
* Internal class used for serialization across Spring Security Authorization Server classes.
|
||||||
*
|
*
|
||||||
* @author Anoop Garlapati
|
* @author Anoop Garlapati
|
||||||
|
* @since 0.0.1
|
||||||
*/
|
*/
|
||||||
public class Version {
|
public final class Version {
|
||||||
|
private static final int MAJOR = 0;
|
||||||
|
private static final int MINOR = 0;
|
||||||
|
private static final int PATCH = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Global Serialization value for Spring Security Authorization Server classes.
|
* Global Serialization value for Spring Security Authorization Server classes.
|
||||||
*/
|
*/
|
||||||
public static final long SERIAL_VERSION_UID = "0.0.1".hashCode();
|
public static final long SERIAL_VERSION_UID = getVersion().hashCode();
|
||||||
|
|
||||||
|
public static String getVersion() {
|
||||||
|
return MAJOR + "." + MINOR + "." + PATCH;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
* @author Anoop Garlapati
|
* @author Anoop Garlapati
|
||||||
* @see RegisteredClientRepository
|
* @see RegisteredClientRepository
|
||||||
* @see RegisteredClient
|
* @see RegisteredClient
|
||||||
|
* @since 0.0.1
|
||||||
*/
|
*/
|
||||||
public final class InMemoryRegisteredClientRepository implements RegisteredClientRepository {
|
public final class InMemoryRegisteredClientRepository implements RegisteredClientRepository {
|
||||||
private final Map<String, RegisteredClient> idRegistrationMap;
|
private final Map<String, RegisteredClient> idRegistrationMap;
|
||||||
@ -66,8 +67,8 @@ public final class InMemoryRegisteredClientRepository implements RegisteredClien
|
|||||||
idRegistrationMapResult.put(id, registration);
|
idRegistrationMapResult.put(id, registration);
|
||||||
clientIdRegistrationMapResult.put(clientId, registration);
|
clientIdRegistrationMapResult.put(clientId, registration);
|
||||||
}
|
}
|
||||||
idRegistrationMap = idRegistrationMapResult;
|
this.idRegistrationMap = idRegistrationMapResult;
|
||||||
clientIdRegistrationMap = clientIdRegistrationMapResult;
|
this.clientIdRegistrationMap = clientIdRegistrationMapResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,7 +25,6 @@ import java.io.Serializable;
|
|||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@ -36,17 +35,17 @@ import java.util.function.Consumer;
|
|||||||
* @author Joe Grandja
|
* @author Joe Grandja
|
||||||
* @author Anoop Garlapati
|
* @author Anoop Garlapati
|
||||||
* @see <a target="_blank" href="https://tools.ietf.org/html/rfc6749#section-2">Section 2 Client Registration</a>
|
* @see <a target="_blank" href="https://tools.ietf.org/html/rfc6749#section-2">Section 2 Client Registration</a>
|
||||||
|
* @since 0.0.1
|
||||||
*/
|
*/
|
||||||
public class RegisteredClient implements Serializable {
|
public class RegisteredClient implements Serializable {
|
||||||
private static final long serialVersionUID = Version.SERIAL_VERSION_UID;
|
private static final long serialVersionUID = Version.SERIAL_VERSION_UID;
|
||||||
private String id;
|
private String id;
|
||||||
private String clientId;
|
private String clientId;
|
||||||
private String clientSecret;
|
private String clientSecret;
|
||||||
private Set<ClientAuthenticationMethod> clientAuthenticationMethods =
|
private Set<ClientAuthenticationMethod> clientAuthenticationMethods;
|
||||||
Collections.singleton(ClientAuthenticationMethod.BASIC);
|
private Set<AuthorizationGrantType> authorizationGrantTypes;
|
||||||
private Set<AuthorizationGrantType> authorizationGrantTypes = Collections.emptySet();
|
private Set<String> redirectUris;
|
||||||
private Set<String> redirectUris = Collections.emptySet();
|
private Set<String> scopes;
|
||||||
private Set<String> scopes = Collections.emptySet();
|
|
||||||
|
|
||||||
protected RegisteredClient() {
|
protected RegisteredClient() {
|
||||||
}
|
}
|
||||||
@ -157,8 +156,7 @@ public class RegisteredClient implements Serializable {
|
|||||||
private String id;
|
private String id;
|
||||||
private String clientId;
|
private String clientId;
|
||||||
private String clientSecret;
|
private String clientSecret;
|
||||||
private Set<ClientAuthenticationMethod> clientAuthenticationMethods =
|
private Set<ClientAuthenticationMethod> clientAuthenticationMethods = new LinkedHashSet<>();
|
||||||
new LinkedHashSet<>(Collections.singletonList(ClientAuthenticationMethod.BASIC));
|
|
||||||
private Set<AuthorizationGrantType> authorizationGrantTypes = new LinkedHashSet<>();
|
private Set<AuthorizationGrantType> authorizationGrantTypes = new LinkedHashSet<>();
|
||||||
private Set<String> redirectUris = new LinkedHashSet<>();
|
private Set<String> redirectUris = new LinkedHashSet<>();
|
||||||
private Set<String> scopes = new LinkedHashSet<>();
|
private Set<String> scopes = new LinkedHashSet<>();
|
||||||
@ -171,13 +169,18 @@ public class RegisteredClient implements Serializable {
|
|||||||
this.id = registeredClient.id;
|
this.id = registeredClient.id;
|
||||||
this.clientId = registeredClient.clientId;
|
this.clientId = registeredClient.clientId;
|
||||||
this.clientSecret = registeredClient.clientSecret;
|
this.clientSecret = registeredClient.clientSecret;
|
||||||
this.clientAuthenticationMethods = registeredClient.clientAuthenticationMethods == null ? null :
|
if (!CollectionUtils.isEmpty(registeredClient.clientAuthenticationMethods)) {
|
||||||
new HashSet<>(registeredClient.clientAuthenticationMethods);
|
this.clientAuthenticationMethods.addAll(registeredClient.clientAuthenticationMethods);
|
||||||
this.authorizationGrantTypes = registeredClient.authorizationGrantTypes == null ? null :
|
}
|
||||||
new HashSet<>(registeredClient.authorizationGrantTypes);
|
if (!CollectionUtils.isEmpty(registeredClient.authorizationGrantTypes)) {
|
||||||
this.redirectUris = registeredClient.redirectUris == null ? null :
|
this.authorizationGrantTypes.addAll(registeredClient.authorizationGrantTypes);
|
||||||
new HashSet<>(registeredClient.redirectUris);
|
}
|
||||||
this.scopes = registeredClient.scopes == null ? null : new HashSet<>(registeredClient.scopes);
|
if (!CollectionUtils.isEmpty(registeredClient.redirectUris)) {
|
||||||
|
this.redirectUris.addAll(registeredClient.redirectUris);
|
||||||
|
}
|
||||||
|
if (!CollectionUtils.isEmpty(registeredClient.scopes)) {
|
||||||
|
this.scopes.addAll(registeredClient.scopes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -214,8 +217,8 @@ public class RegisteredClient implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the {@link ClientAuthenticationMethod authentication method} to the set of
|
* Adds an {@link ClientAuthenticationMethod authentication method}
|
||||||
* client authentication methods used when authenticating the client with the authorization server.
|
* the client may use when authenticating with the authorization server.
|
||||||
*
|
*
|
||||||
* @param clientAuthenticationMethod the authentication method
|
* @param clientAuthenticationMethod the authentication method
|
||||||
* @return the {@link Builder}
|
* @return the {@link Builder}
|
||||||
@ -226,10 +229,10 @@ public class RegisteredClient implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the {@link ClientAuthenticationMethod authentication method(s)} used
|
* A {@code Consumer} of the {@link ClientAuthenticationMethod authentication method(s)}
|
||||||
* when authenticating the client with the authorization server.
|
* allowing the ability to add, replace, or remove.
|
||||||
*
|
*
|
||||||
* @param clientAuthenticationMethodsConsumer the authentication method(s) {@link Consumer}
|
* @param clientAuthenticationMethodsConsumer a {@code Consumer} of the authentication method(s)
|
||||||
* @return the {@link Builder}
|
* @return the {@link Builder}
|
||||||
*/
|
*/
|
||||||
public Builder clientAuthenticationMethods(
|
public Builder clientAuthenticationMethods(
|
||||||
@ -239,8 +242,7 @@ public class RegisteredClient implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the {@link AuthorizationGrantType authorization grant type} to
|
* Adds an {@link AuthorizationGrantType authorization grant type} the client may use.
|
||||||
* the set of authorization grant types that the client may use.
|
|
||||||
*
|
*
|
||||||
* @param authorizationGrantType the authorization grant type
|
* @param authorizationGrantType the authorization grant type
|
||||||
* @return the {@link Builder}
|
* @return the {@link Builder}
|
||||||
@ -251,9 +253,10 @@ public class RegisteredClient implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the {@link AuthorizationGrantType authorization grant type(s)} that the client may use.
|
* A {@code Consumer} of the {@link AuthorizationGrantType authorization grant type(s)}
|
||||||
|
* allowing the ability to add, replace, or remove.
|
||||||
*
|
*
|
||||||
* @param authorizationGrantTypesConsumer the authorization grant type(s) {@link Consumer}
|
* @param authorizationGrantTypesConsumer a {@code Consumer} of the authorization grant type(s)
|
||||||
* @return the {@link Builder}
|
* @return the {@link Builder}
|
||||||
*/
|
*/
|
||||||
public Builder authorizationGrantTypes(Consumer<Set<AuthorizationGrantType>> authorizationGrantTypesConsumer) {
|
public Builder authorizationGrantTypes(Consumer<Set<AuthorizationGrantType>> authorizationGrantTypesConsumer) {
|
||||||
@ -262,9 +265,9 @@ public class RegisteredClient implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the redirect URI to the set of redirect URIs that the client may use in redirect-based flows.
|
* Adds a redirect URI the client may use in a redirect-based flow.
|
||||||
*
|
*
|
||||||
* @param redirectUri the redirect URI to add
|
* @param redirectUri the redirect URI
|
||||||
* @return the {@link Builder}
|
* @return the {@link Builder}
|
||||||
*/
|
*/
|
||||||
public Builder redirectUri(String redirectUri) {
|
public Builder redirectUri(String redirectUri) {
|
||||||
@ -273,9 +276,10 @@ public class RegisteredClient implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the redirect URI(s) that the client may use in redirect-based flows.
|
* A {@code Consumer} of the redirect URI(s)
|
||||||
|
* allowing the ability to add, replace, or remove.
|
||||||
*
|
*
|
||||||
* @param redirectUrisConsumer the redirect URI(s) {@link Consumer}
|
* @param redirectUrisConsumer a {@link Consumer} of the redirect URI(s)
|
||||||
* @return the {@link Builder}
|
* @return the {@link Builder}
|
||||||
*/
|
*/
|
||||||
public Builder redirectUris(Consumer<Set<String>> redirectUrisConsumer) {
|
public Builder redirectUris(Consumer<Set<String>> redirectUrisConsumer) {
|
||||||
@ -284,9 +288,9 @@ public class RegisteredClient implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the scope to the set of scopes used by the client.
|
* Adds a scope the client may use.
|
||||||
*
|
*
|
||||||
* @param scope the scope to add
|
* @param scope the scope
|
||||||
* @return the {@link Builder}
|
* @return the {@link Builder}
|
||||||
*/
|
*/
|
||||||
public Builder scope(String scope) {
|
public Builder scope(String scope) {
|
||||||
@ -295,9 +299,10 @@ public class RegisteredClient implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the scope(s) used by the client.
|
* A {@code Consumer} of the scope(s)
|
||||||
|
* allowing the ability to add, replace, or remove.
|
||||||
*
|
*
|
||||||
* @param scopesConsumer the scope(s) {@link Consumer}
|
* @param scopesConsumer a {@link Consumer} of the scope(s)
|
||||||
* @return the {@link Builder}
|
* @return the {@link Builder}
|
||||||
*/
|
*/
|
||||||
public Builder scopes(Consumer<Set<String>> scopesConsumer) {
|
public Builder scopes(Consumer<Set<String>> scopesConsumer) {
|
||||||
@ -311,17 +316,18 @@ public class RegisteredClient implements Serializable {
|
|||||||
* @return a {@link RegisteredClient}
|
* @return a {@link RegisteredClient}
|
||||||
*/
|
*/
|
||||||
public RegisteredClient build() {
|
public RegisteredClient build() {
|
||||||
Assert.notEmpty(this.clientAuthenticationMethods, "clientAuthenticationMethods cannot be empty");
|
|
||||||
Assert.notEmpty(this.authorizationGrantTypes, "authorizationGrantTypes cannot be empty");
|
|
||||||
if (authorizationGrantTypes.contains(AuthorizationGrantType.AUTHORIZATION_CODE)) {
|
|
||||||
Assert.hasText(this.id, "id cannot be empty");
|
|
||||||
Assert.hasText(this.clientId, "clientId cannot be empty");
|
Assert.hasText(this.clientId, "clientId cannot be empty");
|
||||||
|
Assert.notEmpty(this.authorizationGrantTypes, "authorizationGrantTypes cannot be empty");
|
||||||
|
if (this.authorizationGrantTypes.contains(AuthorizationGrantType.AUTHORIZATION_CODE)) {
|
||||||
Assert.hasText(this.clientSecret, "clientSecret cannot be empty");
|
Assert.hasText(this.clientSecret, "clientSecret cannot be empty");
|
||||||
Assert.notEmpty(this.redirectUris, "redirectUris cannot be empty");
|
Assert.notEmpty(this.redirectUris, "redirectUris cannot be empty");
|
||||||
}
|
}
|
||||||
this.validateScopes();
|
if (CollectionUtils.isEmpty(this.clientAuthenticationMethods)) {
|
||||||
this.validateRedirectUris();
|
this.clientAuthenticationMethods.add(ClientAuthenticationMethod.BASIC);
|
||||||
return this.create();
|
}
|
||||||
|
validateScopes();
|
||||||
|
validateRedirectUris();
|
||||||
|
return create();
|
||||||
}
|
}
|
||||||
|
|
||||||
private RegisteredClient create() {
|
private RegisteredClient create() {
|
||||||
@ -380,5 +386,4 @@ public class RegisteredClient implements Serializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ package org.springframework.security.oauth2.server.authorization.client;
|
|||||||
* @author Joe Grandja
|
* @author Joe Grandja
|
||||||
* @author Anoop Garlapati
|
* @author Anoop Garlapati
|
||||||
* @see RegisteredClient
|
* @see RegisteredClient
|
||||||
|
* @since 0.0.1
|
||||||
*/
|
*/
|
||||||
public interface RegisteredClientRepository {
|
public interface RegisteredClientRepository {
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ public class InMemoryRegisteredClientRepositoryTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void constructorListClientRegistrationWhenEmptyThenThrowIllegalArgumentException() {
|
public void constructorListRegisteredClientWhenEmptyThenThrowIllegalArgumentException() {
|
||||||
assertThatThrownBy(() -> {
|
assertThatThrownBy(() -> {
|
||||||
List<RegisteredClient> registrations = Collections.emptyList();
|
List<RegisteredClient> registrations = Collections.emptyList();
|
||||||
new InMemoryRegisteredClientRepository(registrations);
|
new InMemoryRegisteredClientRepository(registrations);
|
||||||
@ -82,34 +82,34 @@ public class InMemoryRegisteredClientRepositoryTests {
|
|||||||
@Test
|
@Test
|
||||||
public void findByIdWhenFoundThenFound() {
|
public void findByIdWhenFoundThenFound() {
|
||||||
String id = this.registration.getId();
|
String id = this.registration.getId();
|
||||||
assertThat(clients.findById(id)).isEqualTo(this.registration);
|
assertThat(this.clients.findById(id)).isEqualTo(this.registration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void findByIdWhenNotFoundThenNull() {
|
public void findByIdWhenNotFoundThenNull() {
|
||||||
String missingId = this.registration.getId() + "MISSING";
|
String missingId = this.registration.getId() + "MISSING";
|
||||||
assertThat(clients.findById(missingId)).isNull();
|
assertThat(this.clients.findById(missingId)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void findByIdWhenNullThenThrowIllegalArgumentException() {
|
public void findByIdWhenNullThenThrowIllegalArgumentException() {
|
||||||
assertThatThrownBy(() -> clients.findById(null)).isInstanceOf(IllegalArgumentException.class);
|
assertThatThrownBy(() -> this.clients.findById(null)).isInstanceOf(IllegalArgumentException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void findByClientIdWhenFoundThenFound() {
|
public void findByClientIdWhenFoundThenFound() {
|
||||||
String clientId = this.registration.getClientId();
|
String clientId = this.registration.getClientId();
|
||||||
assertThat(clients.findByClientId(clientId)).isEqualTo(this.registration);
|
assertThat(this.clients.findByClientId(clientId)).isEqualTo(this.registration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void findByClientIdWhenNotFoundThenNull() {
|
public void findByClientIdWhenNotFoundThenNull() {
|
||||||
String missingClientId = this.registration.getClientId() + "MISSING";
|
String missingClientId = this.registration.getClientId() + "MISSING";
|
||||||
assertThat(clients.findByClientId(missingClientId)).isNull();
|
assertThat(this.clients.findByClientId(missingClientId)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void findByClientIdWhenNullThenThrowIllegalArgumentException() {
|
public void findByClientIdWhenNullThenThrowIllegalArgumentException() {
|
||||||
assertThatThrownBy(() -> clients.findByClientId(null)).isInstanceOf(IllegalArgumentException.class);
|
assertThatThrownBy(() -> this.clients.findByClientId(null)).isInstanceOf(IllegalArgumentException.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ public class RegisteredClientTests {
|
|||||||
Collections.singleton(ClientAuthenticationMethod.BASIC);
|
Collections.singleton(ClientAuthenticationMethod.BASIC);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void buildWhenAuthorizationGrantTypesIsNotSetThenThrowIllegalArgumentException() {
|
public void buildWhenAuthorizationGrantTypesNotSetThenThrowIllegalArgumentException() {
|
||||||
assertThatThrownBy(() ->
|
assertThatThrownBy(() ->
|
||||||
RegisteredClient.withId(ID)
|
RegisteredClient.withId(ID)
|
||||||
.clientId(CLIENT_ID)
|
.clientId(CLIENT_ID)
|
||||||
@ -56,7 +56,7 @@ public class RegisteredClientTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void buildWhenAuthorizationCodeGrantAllAttributesProvidedThenAllAttributesAreSet() {
|
public void buildWhenAllAttributesProvidedThenAllAttributesAreSet() {
|
||||||
RegisteredClient registration = RegisteredClient.withId(ID)
|
RegisteredClient registration = RegisteredClient.withId(ID)
|
||||||
.clientId(CLIENT_ID)
|
.clientId(CLIENT_ID)
|
||||||
.clientSecret(CLIENT_SECRET)
|
.clientSecret(CLIENT_SECRET)
|
||||||
@ -77,21 +77,13 @@ public class RegisteredClientTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void buildWhenAuthorizationCodeGrantIdIsNullThenThrowIllegalArgumentException() {
|
public void buildWhenIdIsNullThenThrowIllegalArgumentException() {
|
||||||
assertThatThrownBy(() ->
|
assertThatThrownBy(() -> RegisteredClient.withId(null))
|
||||||
RegisteredClient.withId(null)
|
.isInstanceOf(IllegalArgumentException.class);
|
||||||
.clientId(CLIENT_ID)
|
|
||||||
.clientSecret(CLIENT_SECRET)
|
|
||||||
.authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
|
|
||||||
.clientAuthenticationMethod(ClientAuthenticationMethod.BASIC)
|
|
||||||
.redirectUris(redirectUris -> redirectUris.addAll(REDIRECT_URIS))
|
|
||||||
.scopes(scopes -> scopes.addAll(SCOPES))
|
|
||||||
.build()
|
|
||||||
).isInstanceOf(IllegalArgumentException.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void buildWhenAuthorizationCodeGrantClientIdIsNullThenThrowIllegalArgumentException() {
|
public void buildWhenClientIdIsNullThenThrowIllegalArgumentException() {
|
||||||
assertThatThrownBy(() ->
|
assertThatThrownBy(() ->
|
||||||
RegisteredClient.withId(ID)
|
RegisteredClient.withId(ID)
|
||||||
.clientId(null)
|
.clientId(null)
|
||||||
@ -105,21 +97,7 @@ public class RegisteredClientTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void buildWhenAuthorizationCodeGrantClientSecretIsNullThenThrowIllegalArgumentException() {
|
public void buildWhenRedirectUrisNotProvidedThenThrowIllegalArgumentException() {
|
||||||
assertThatThrownBy(() ->
|
|
||||||
RegisteredClient.withId(ID)
|
|
||||||
.clientId(null)
|
|
||||||
.clientSecret(CLIENT_SECRET)
|
|
||||||
.authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
|
|
||||||
.clientAuthenticationMethod(ClientAuthenticationMethod.BASIC)
|
|
||||||
.redirectUris(redirectUris -> redirectUris.addAll(REDIRECT_URIS))
|
|
||||||
.scopes(scopes -> scopes.addAll(SCOPES))
|
|
||||||
.build()
|
|
||||||
).isInstanceOf(IllegalArgumentException.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void buildWhenAuthorizationCodeGrantRedirectUrisNotProvidedThenThrowIllegalArgumentException() {
|
|
||||||
assertThatThrownBy(() ->
|
assertThatThrownBy(() ->
|
||||||
RegisteredClient.withId(ID)
|
RegisteredClient.withId(ID)
|
||||||
.clientId(CLIENT_ID)
|
.clientId(CLIENT_ID)
|
||||||
@ -132,7 +110,7 @@ public class RegisteredClientTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void buildWhenAuthorizationCodeGrantRedirectUrisConsumerClearsSetThenThrowIllegalArgumentException() {
|
public void buildWhenRedirectUrisConsumerClearsSetThenThrowIllegalArgumentException() {
|
||||||
assertThatThrownBy(() ->
|
assertThatThrownBy(() ->
|
||||||
RegisteredClient.withId(ID)
|
RegisteredClient.withId(ID)
|
||||||
.clientId(CLIENT_ID)
|
.clientId(CLIENT_ID)
|
||||||
@ -147,7 +125,7 @@ public class RegisteredClientTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void buildWhenAuthorizationCodeGrantClientAuthenticationMethodNotProvidedThenDefaultToBasic() {
|
public void buildWhenClientAuthenticationMethodNotProvidedThenDefaultToBasic() {
|
||||||
RegisteredClient registration = RegisteredClient.withId(ID)
|
RegisteredClient registration = RegisteredClient.withId(ID)
|
||||||
.clientId(CLIENT_ID)
|
.clientId(CLIENT_ID)
|
||||||
.clientSecret(CLIENT_SECRET)
|
.clientSecret(CLIENT_SECRET)
|
||||||
@ -161,7 +139,7 @@ public class RegisteredClientTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void buildWhenAuthorizationCodeGrantScopeIsEmptyThenScopeNotRequired() {
|
public void buildWhenScopeIsEmptyThenScopeNotRequired() {
|
||||||
RegisteredClient.withId(ID)
|
RegisteredClient.withId(ID)
|
||||||
.clientId(CLIENT_ID)
|
.clientId(CLIENT_ID)
|
||||||
.clientSecret(CLIENT_SECRET)
|
.clientSecret(CLIENT_SECRET)
|
||||||
@ -172,7 +150,7 @@ public class RegisteredClientTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void buildWhenAuthorizationCodeGrantScopeConsumerIsProvidedThenConsumerAccepted() {
|
public void buildWhenScopeConsumerIsProvidedThenConsumerAccepted() {
|
||||||
RegisteredClient registration = RegisteredClient.withId(ID)
|
RegisteredClient registration = RegisteredClient.withId(ID)
|
||||||
.clientId(CLIENT_ID)
|
.clientId(CLIENT_ID)
|
||||||
.clientSecret(CLIENT_SECRET)
|
.clientSecret(CLIENT_SECRET)
|
||||||
@ -186,11 +164,10 @@ public class RegisteredClientTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void buildWhenScopeContainsASpaceThenThrowIllegalArgumentException() {
|
public void buildWhenScopeContainsSpaceThenThrowIllegalArgumentException() {
|
||||||
assertThatThrownBy(() ->
|
assertThatThrownBy(() ->
|
||||||
RegisteredClient.withId(ID)
|
RegisteredClient.withId(ID)
|
||||||
.clientId(CLIENT_ID)
|
.clientId(CLIENT_ID)
|
||||||
.clientSecret(null)
|
|
||||||
.authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
|
.authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
|
||||||
.clientAuthenticationMethod(ClientAuthenticationMethod.BASIC)
|
.clientAuthenticationMethod(ClientAuthenticationMethod.BASIC)
|
||||||
.redirectUris(redirectUris -> redirectUris.addAll(REDIRECT_URIS))
|
.redirectUris(redirectUris -> redirectUris.addAll(REDIRECT_URIS))
|
||||||
@ -200,7 +177,7 @@ public class RegisteredClientTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void buildWhenScopesContainsAnInvalidCharacterThenThrowIllegalArgumentException() {
|
public void buildWhenScopeContainsInvalidCharacterThenThrowIllegalArgumentException() {
|
||||||
assertThatThrownBy(() ->
|
assertThatThrownBy(() ->
|
||||||
RegisteredClient.withId(ID)
|
RegisteredClient.withId(ID)
|
||||||
.clientId(CLIENT_ID)
|
.clientId(CLIENT_ID)
|
||||||
@ -214,7 +191,7 @@ public class RegisteredClientTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void buildWhenRedirectUrisContainInvalidUriThenThrowIllegalArgumentException() {
|
public void buildWhenRedirectUriInvalidThenThrowIllegalArgumentException() {
|
||||||
assertThatThrownBy(() ->
|
assertThatThrownBy(() ->
|
||||||
RegisteredClient.withId(ID)
|
RegisteredClient.withId(ID)
|
||||||
.clientId(CLIENT_ID)
|
.clientId(CLIENT_ID)
|
||||||
@ -228,7 +205,7 @@ public class RegisteredClientTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void buildWhenRedirectUrisContainUriWithFragmentThenThrowIllegalArgumentException() {
|
public void buildWhenRedirectUriContainsFragmentThenThrowIllegalArgumentException() {
|
||||||
assertThatThrownBy(() ->
|
assertThatThrownBy(() ->
|
||||||
RegisteredClient.withId(ID)
|
RegisteredClient.withId(ID)
|
||||||
.clientId(CLIENT_ID)
|
.clientId(CLIENT_ID)
|
||||||
@ -281,6 +258,7 @@ public class RegisteredClientTests {
|
|||||||
RegisteredClient.withId(ID)
|
RegisteredClient.withId(ID)
|
||||||
.clientId(CLIENT_ID)
|
.clientId(CLIENT_ID)
|
||||||
.clientSecret(CLIENT_SECRET)
|
.clientSecret(CLIENT_SECRET)
|
||||||
|
.authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
|
||||||
.authorizationGrantTypes(Set::clear)
|
.authorizationGrantTypes(Set::clear)
|
||||||
.clientAuthenticationMethod(ClientAuthenticationMethod.BASIC)
|
.clientAuthenticationMethod(ClientAuthenticationMethod.BASIC)
|
||||||
.redirectUris(redirectUris -> redirectUris.addAll(REDIRECT_URIS))
|
.redirectUris(redirectUris -> redirectUris.addAll(REDIRECT_URIS))
|
||||||
@ -323,20 +301,6 @@ public class RegisteredClientTests {
|
|||||||
.containsExactly(ClientAuthenticationMethod.BASIC, ClientAuthenticationMethod.POST);
|
.containsExactly(ClientAuthenticationMethod.BASIC, ClientAuthenticationMethod.POST);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void buildWhenClientAuthenticationMethodsConsumerClearsSetThenThrowIllegalArgumentException() {
|
|
||||||
assertThatThrownBy(() -> {
|
|
||||||
RegisteredClient.withId(ID)
|
|
||||||
.clientId(CLIENT_ID)
|
|
||||||
.clientSecret(CLIENT_SECRET)
|
|
||||||
.authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
|
|
||||||
.clientAuthenticationMethods(Set::clear)
|
|
||||||
.redirectUris(redirectUris -> redirectUris.addAll(REDIRECT_URIS))
|
|
||||||
.scopes(scopes -> scopes.addAll(SCOPES))
|
|
||||||
.build();
|
|
||||||
}).isInstanceOf(IllegalArgumentException.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void buildWhenOverrideIdThenOverridden() {
|
public void buildWhenOverrideIdThenOverridden() {
|
||||||
String overriddenId = "override";
|
String overriddenId = "override";
|
||||||
@ -383,7 +347,7 @@ public class RegisteredClientTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void buildWhenClientRegistrationValuesOverriddenThenPropagated() {
|
public void buildWhenRegisteredClientValuesOverriddenThenPropagated() {
|
||||||
RegisteredClient registration = TestRegisteredClients.registeredClient().build();
|
RegisteredClient registration = TestRegisteredClients.registeredClient().build();
|
||||||
String newSecret = "new-secret";
|
String newSecret = "new-secret";
|
||||||
String newScope = "new-scope";
|
String newScope = "new-scope";
|
||||||
|
Loading…
Reference in New Issue
Block a user