|
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>
|
@@ -323,6 +329,12 @@ public static final class Builder implements Serializable {
|
323 | 329 |
|
324 | 330 | private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;
|
325 | 331 |
|
| 332 | + private static final Log logger = LogFactory.getLog(Builder.class); |
| 333 | + |
| 334 | + private static final List<AuthorizationGrantType> AUTHORIZATION_GRANT_TYPES = Arrays.asList( |
| 335 | + AuthorizationGrantType.AUTHORIZATION_CODE, AuthorizationGrantType.CLIENT_CREDENTIALS, |
| 336 | + AuthorizationGrantType.REFRESH_TOKEN, AuthorizationGrantType.IMPLICIT, AuthorizationGrantType.PASSWORD); |
| 337 | + |
326 | 338 | private String registrationId;
|
327 | 339 |
|
328 | 340 | private String clientId;
|
@@ -597,6 +609,7 @@ else if (AuthorizationGrantType.PASSWORD.equals(this.authorizationGrantType)) {
|
597 | 609 | else if (AuthorizationGrantType.AUTHORIZATION_CODE.equals(this.authorizationGrantType)) {
|
598 | 610 | this.validateAuthorizationCodeGrantType();
|
599 | 611 | }
|
| 612 | + this.validateAuthorizationGrantTypes(); |
600 | 613 | this.validateScopes();
|
601 | 614 | return this.create();
|
602 | 615 | }
|
@@ -664,6 +677,17 @@ private void validatePasswordGrantType() {
|
664 | 677 | Assert.hasText(this.tokenUri, "tokenUri cannot be empty");
|
665 | 678 | }
|
666 | 679 |
|
| 680 | + private void validateAuthorizationGrantTypes() { |
| 681 | + for (AuthorizationGrantType authorizationGrantType : AUTHORIZATION_GRANT_TYPES) { |
| 682 | + if (authorizationGrantType.getValue().equalsIgnoreCase(this.authorizationGrantType.getValue()) |
| 683 | + && !authorizationGrantType.equals(this.authorizationGrantType)) { |
| 684 | + logger.warn(LogMessage.format( |
| 685 | + "AuthorizationGrantType: %s does not match the pre-defined constant %s and won't match a valid OAuth2AuthorizedClientProvider", |
| 686 | + this.authorizationGrantType, authorizationGrantType)); |
| 687 | + } |
| 688 | + } |
| 689 | + } |
| 690 | + |
667 | 691 | private void validateScopes() {
|
668 | 692 | if (this.scopes == null) {
|
669 | 693 | return;
|
|
0 commit comments