|
|
|
@ -40,6 +40,7 @@ import org.springframework.security.oauth2.core.OAuth2AuthenticationException; |
|
|
|
import org.springframework.security.oauth2.core.OAuth2Error; |
|
|
|
import org.springframework.security.oauth2.core.OAuth2Error; |
|
|
|
import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationResponse; |
|
|
|
import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationResponse; |
|
|
|
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames; |
|
|
|
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames; |
|
|
|
|
|
|
|
import org.springframework.security.oauth2.core.endpoint.PkceParameterNames; |
|
|
|
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeRequestAuthenticationException; |
|
|
|
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeRequestAuthenticationException; |
|
|
|
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeRequestAuthenticationProvider; |
|
|
|
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeRequestAuthenticationProvider; |
|
|
|
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeRequestAuthenticationToken; |
|
|
|
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeRequestAuthenticationToken; |
|
|
|
@ -151,18 +152,24 @@ public final class OAuth2AuthorizationEndpointFilter extends OncePerRequestFilte |
|
|
|
.matcher(HttpMethod.GET, authorizationEndpointUri); |
|
|
|
.matcher(HttpMethod.GET, authorizationEndpointUri); |
|
|
|
RequestMatcher authorizationRequestPostMatcher = PathPatternRequestMatcher.withDefaults() |
|
|
|
RequestMatcher authorizationRequestPostMatcher = PathPatternRequestMatcher.withDefaults() |
|
|
|
.matcher(HttpMethod.POST, authorizationEndpointUri); |
|
|
|
.matcher(HttpMethod.POST, authorizationEndpointUri); |
|
|
|
|
|
|
|
RequestMatcher authorizationConsentMatcher = createAuthorizationConsentMatcher(authorizationEndpointUri); |
|
|
|
RequestMatcher responseTypeParameterMatcher = ( |
|
|
|
|
|
|
|
request) -> request.getParameter(OAuth2ParameterNames.RESPONSE_TYPE) != null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RequestMatcher authorizationRequestMatcher = new OrRequestMatcher(authorizationRequestGetMatcher, |
|
|
|
RequestMatcher authorizationRequestMatcher = new OrRequestMatcher(authorizationRequestGetMatcher, |
|
|
|
new AndRequestMatcher(authorizationRequestPostMatcher, responseTypeParameterMatcher)); |
|
|
|
new AndRequestMatcher(authorizationRequestPostMatcher, |
|
|
|
RequestMatcher authorizationConsentMatcher = new AndRequestMatcher(authorizationRequestPostMatcher, |
|
|
|
new NegatedRequestMatcher(authorizationConsentMatcher))); |
|
|
|
new NegatedRequestMatcher(responseTypeParameterMatcher)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new OrRequestMatcher(authorizationRequestMatcher, authorizationConsentMatcher); |
|
|
|
return new OrRequestMatcher(authorizationRequestMatcher, authorizationConsentMatcher); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static RequestMatcher createAuthorizationConsentMatcher(String authorizationEndpointUri) { |
|
|
|
|
|
|
|
final RequestMatcher authorizationConsentPostMatcher = PathPatternRequestMatcher.withDefaults() |
|
|
|
|
|
|
|
.matcher(HttpMethod.POST, authorizationEndpointUri); |
|
|
|
|
|
|
|
return (request) -> authorizationConsentPostMatcher.matches(request) |
|
|
|
|
|
|
|
&& request.getParameter(OAuth2ParameterNames.RESPONSE_TYPE) == null |
|
|
|
|
|
|
|
&& request.getParameter(OAuth2ParameterNames.REQUEST_URI) == null |
|
|
|
|
|
|
|
&& request.getParameter(OAuth2ParameterNames.REDIRECT_URI) == null |
|
|
|
|
|
|
|
&& request.getParameter(PkceParameterNames.CODE_CHALLENGE) == null |
|
|
|
|
|
|
|
&& request.getParameter(PkceParameterNames.CODE_CHALLENGE_METHOD) == null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) |
|
|
|
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) |
|
|
|
throws ServletException, IOException { |
|
|
|
throws ServletException, IOException { |
|
|
|
|