Skip to content

Commit d79f13e

Browse files
Remove the openid scope matcher in OAuth2AuthorizationEndpointFilter
Closes gh-1811
1 parent b76300b commit d79f13e

File tree

2 files changed

+4
-23
lines changed

2 files changed

+4
-23
lines changed

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/web/OAuth2AuthorizationEndpointFilter.java

+2-17
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.springframework.security.oauth2.core.OAuth2Error;
4040
import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationResponse;
4141
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
42-
import org.springframework.security.oauth2.core.oidc.OidcScopes;
4342
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeRequestAuthenticationException;
4443
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeRequestAuthenticationProvider;
4544
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeRequestAuthenticationToken;
@@ -57,9 +56,7 @@
5756
import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy;
5857
import org.springframework.security.web.util.RedirectUrlBuilder;
5958
import org.springframework.security.web.util.UrlUtils;
60-
import org.springframework.security.web.util.matcher.AndRequestMatcher;
6159
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
62-
import org.springframework.security.web.util.matcher.NegatedRequestMatcher;
6360
import org.springframework.security.web.util.matcher.OrRequestMatcher;
6461
import org.springframework.security.web.util.matcher.RequestMatcher;
6562
import org.springframework.util.Assert;
@@ -151,20 +148,8 @@ private static RequestMatcher createDefaultRequestMatcher(String authorizationEn
151148
HttpMethod.GET.name());
152149
RequestMatcher authorizationRequestPostMatcher = new AntPathRequestMatcher(authorizationEndpointUri,
153150
HttpMethod.POST.name());
154-
RequestMatcher openidScopeMatcher = (request) -> {
155-
String scope = request.getParameter(OAuth2ParameterNames.SCOPE);
156-
return StringUtils.hasText(scope) && scope.contains(OidcScopes.OPENID);
157-
};
158-
RequestMatcher responseTypeParameterMatcher = (
159-
request) -> request.getParameter(OAuth2ParameterNames.RESPONSE_TYPE) != null;
160-
161-
RequestMatcher authorizationRequestMatcher = new OrRequestMatcher(authorizationRequestGetMatcher,
162-
new AndRequestMatcher(authorizationRequestPostMatcher, responseTypeParameterMatcher,
163-
openidScopeMatcher));
164-
RequestMatcher authorizationConsentMatcher = new AndRequestMatcher(authorizationRequestPostMatcher,
165-
new NegatedRequestMatcher(responseTypeParameterMatcher));
166-
167-
return new OrRequestMatcher(authorizationRequestMatcher, authorizationConsentMatcher);
151+
152+
return new OrRequestMatcher(authorizationRequestGetMatcher, authorizationRequestPostMatcher);
168153
}
169154

170155
@Override

oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/web/OAuth2AuthorizationEndpointFilterTests.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -611,19 +611,15 @@ public void doFilterWhenAuthorizationRequestAuthenticatedThenAuthorizationRespon
611611

612612
@Test
613613
public void doFilterWhenAuthenticationRequestAuthenticatedThenAuthorizationResponse() throws Exception {
614-
// Setup OpenID Connect request
615-
RegisteredClient registeredClient = TestRegisteredClients.registeredClient().scopes((scopes) -> {
616-
scopes.clear();
617-
scopes.add(OidcScopes.OPENID);
618-
}).build();
614+
RegisteredClient registeredClient = TestRegisteredClients.registeredClient().scopes(Set::clear).build();
619615
OAuth2AuthorizationCodeRequestAuthenticationToken authorizationCodeRequestAuthenticationResult = new OAuth2AuthorizationCodeRequestAuthenticationToken(
620616
AUTHORIZATION_URI, registeredClient.getClientId(), this.principal, this.authorizationCode,
621617
registeredClient.getRedirectUris().iterator().next(), STATE, registeredClient.getScopes());
622618
authorizationCodeRequestAuthenticationResult.setAuthenticated(true);
623619
given(this.authenticationManager.authenticate(any())).willReturn(authorizationCodeRequestAuthenticationResult);
624620

625621
MockHttpServletRequest request = createAuthorizationRequest(registeredClient);
626-
request.setMethod("POST"); // OpenID Connect supports POST method
622+
request.setMethod("POST");
627623
request.setQueryString(null);
628624
MockHttpServletResponse response = new MockHttpServletResponse();
629625
FilterChain filterChain = mock(FilterChain.class);

0 commit comments

Comments
 (0)