|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2020 the original author or authors. |
| 2 | + * Copyright 2002-2022 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
24 | 24 | import java.util.HashSet;
|
25 | 25 | import java.util.LinkedHashMap;
|
26 | 26 | import java.util.LinkedHashSet;
|
| 27 | +import java.util.List; |
27 | 28 | import java.util.Map;
|
28 | 29 | import java.util.Set;
|
29 | 30 |
|
| 31 | +import org.apache.commons.logging.Log; |
| 32 | +import org.apache.commons.logging.LogFactory; |
| 33 | + |
| 34 | +import org.springframework.core.log.LogMessage; |
30 | 35 | import org.springframework.security.core.SpringSecurityCoreVersion;
|
31 | 36 | import org.springframework.security.oauth2.core.AuthenticationMethod;
|
32 | 37 | import org.springframework.security.oauth2.core.AuthorizationGrantType;
|
|
39 | 44 | * Provider.
|
40 | 45 | *
|
41 | 46 | * @author Joe Grandja
|
| 47 | + * @author Michael Sosa |
42 | 48 | * @since 5.0
|
43 | 49 | * @see <a target="_blank" href="https://tools.ietf.org/html/rfc6749#section-2">Section 2
|
44 | 50 | * Client Registration</a>
|
@@ -333,6 +339,12 @@ public static final class Builder implements Serializable {
|
333 | 339 |
|
334 | 340 | private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;
|
335 | 341 |
|
| 342 | + private static final Log logger = LogFactory.getLog(Builder.class); |
| 343 | + |
| 344 | + private static final List<AuthorizationGrantType> AUTHORIZATION_GRANT_TYPES = Arrays.asList( |
| 345 | + AuthorizationGrantType.AUTHORIZATION_CODE, AuthorizationGrantType.CLIENT_CREDENTIALS, |
| 346 | + AuthorizationGrantType.REFRESH_TOKEN, AuthorizationGrantType.IMPLICIT, AuthorizationGrantType.PASSWORD); |
| 347 | + |
336 | 348 | private String registrationId;
|
337 | 349 |
|
338 | 350 | private String clientId;
|
@@ -622,6 +634,7 @@ else if (AuthorizationGrantType.IMPLICIT.equals(this.authorizationGrantType)) {
|
622 | 634 | else if (AuthorizationGrantType.AUTHORIZATION_CODE.equals(this.authorizationGrantType)) {
|
623 | 635 | this.validateAuthorizationCodeGrantType();
|
624 | 636 | }
|
| 637 | + this.validateAuthorizationGrantTypes(); |
625 | 638 | this.validateScopes();
|
626 | 639 | return this.create();
|
627 | 640 | }
|
@@ -698,6 +711,17 @@ private void validatePasswordGrantType() {
|
698 | 711 | Assert.hasText(this.tokenUri, "tokenUri cannot be empty");
|
699 | 712 | }
|
700 | 713 |
|
| 714 | + private void validateAuthorizationGrantTypes() { |
| 715 | + for (AuthorizationGrantType authorizationGrantType : AUTHORIZATION_GRANT_TYPES) { |
| 716 | + if (authorizationGrantType.getValue().equalsIgnoreCase(this.authorizationGrantType.getValue()) |
| 717 | + && !authorizationGrantType.equals(this.authorizationGrantType)) { |
| 718 | + logger.warn(LogMessage.format( |
| 719 | + "AuthorizationGrantType: %s does not match the pre-defined constant %s and won't match a valid OAuth2AuthorizedClientProvider", |
| 720 | + this.authorizationGrantType, authorizationGrantType)); |
| 721 | + } |
| 722 | + } |
| 723 | + } |
| 724 | + |
701 | 725 | private void validateScopes() {
|
702 | 726 | if (this.scopes == null) {
|
703 | 727 | return;
|
|
0 commit comments