Skip to content

Commit a3d35ec

Browse files
author
Steve Riesenberg
committed
Merge branch '5.8.x'
Closes gh-12234
2 parents 102c5e7 + 52888d6 commit a3d35ec

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/registration/ClientRegistration.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@
2424
import java.util.HashSet;
2525
import java.util.LinkedHashMap;
2626
import java.util.LinkedHashSet;
27+
import java.util.List;
2728
import java.util.Map;
2829
import java.util.Set;
2930

31+
import org.apache.commons.logging.Log;
32+
import org.apache.commons.logging.LogFactory;
33+
34+
import org.springframework.core.log.LogMessage;
3035
import org.springframework.security.core.SpringSecurityCoreVersion;
3136
import org.springframework.security.oauth2.core.AuthenticationMethod;
3237
import org.springframework.security.oauth2.core.AuthorizationGrantType;
@@ -39,6 +44,7 @@
3944
* Provider.
4045
*
4146
* @author Joe Grandja
47+
* @author Michael Sosa
4248
* @since 5.0
4349
* @see <a target="_blank" href="https://tools.ietf.org/html/rfc6749#section-2">Section 2
4450
* Client Registration</a>
@@ -323,6 +329,12 @@ public static final class Builder implements Serializable {
323329

324330
private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;
325331

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+
326338
private String registrationId;
327339

328340
private String clientId;
@@ -597,6 +609,7 @@ else if (AuthorizationGrantType.PASSWORD.equals(this.authorizationGrantType)) {
597609
else if (AuthorizationGrantType.AUTHORIZATION_CODE.equals(this.authorizationGrantType)) {
598610
this.validateAuthorizationCodeGrantType();
599611
}
612+
this.validateAuthorizationGrantTypes();
600613
this.validateScopes();
601614
return this.create();
602615
}
@@ -664,6 +677,17 @@ private void validatePasswordGrantType() {
664677
Assert.hasText(this.tokenUri, "tokenUri cannot be empty");
665678
}
666679

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+
667691
private void validateScopes() {
668692
if (this.scopes == null) {
669693
return;

0 commit comments

Comments
 (0)