|
@@ -27,14 +27,12 @@ import jakarta.servlet.http.HttpServletResponse;
|
|
|
|
|
|
import org.springframework.core.log.LogMessage;
|
|
|
import org.springframework.http.HttpMethod;
|
|
|
-import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.converter.HttpMessageConverter;
|
|
|
import org.springframework.http.server.ServletServerHttpResponse;
|
|
|
import org.springframework.security.authentication.AbstractAuthenticationToken;
|
|
|
import org.springframework.security.authentication.AuthenticationDetailsSource;
|
|
|
import org.springframework.security.authentication.AuthenticationManager;
|
|
|
import org.springframework.security.core.Authentication;
|
|
|
-import org.springframework.security.core.AuthenticationException;
|
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
import org.springframework.security.oauth2.core.OAuth2AccessToken;
|
|
|
import org.springframework.security.oauth2.core.OAuth2AuthenticationException;
|
|
@@ -44,13 +42,13 @@ import org.springframework.security.oauth2.core.OAuth2RefreshToken;
|
|
|
import org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse;
|
|
|
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
|
|
|
import org.springframework.security.oauth2.core.http.converter.OAuth2AccessTokenResponseHttpMessageConverter;
|
|
|
-import org.springframework.security.oauth2.core.http.converter.OAuth2ErrorHttpMessageConverter;
|
|
|
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2AccessTokenAuthenticationToken;
|
|
|
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeAuthenticationProvider;
|
|
|
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationGrantAuthenticationToken;
|
|
|
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2ClientCredentialsAuthenticationProvider;
|
|
|
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2DeviceCodeAuthenticationProvider;
|
|
|
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2RefreshTokenAuthenticationProvider;
|
|
|
+import org.springframework.security.oauth2.server.authorization.web.authentication.OAuth2ErrorAuthenticationFailureHandler;
|
|
|
import org.springframework.security.oauth2.server.authorization.web.authentication.DelegatingAuthenticationConverter;
|
|
|
import org.springframework.security.oauth2.server.authorization.web.authentication.OAuth2AuthorizationCodeAuthenticationConverter;
|
|
|
import org.springframework.security.oauth2.server.authorization.web.authentication.OAuth2ClientCredentialsAuthenticationConverter;
|
|
@@ -107,13 +105,11 @@ public final class OAuth2TokenEndpointFilter extends OncePerRequestFilter {
|
|
|
private final RequestMatcher tokenEndpointMatcher;
|
|
|
private final HttpMessageConverter<OAuth2AccessTokenResponse> accessTokenHttpResponseConverter =
|
|
|
new OAuth2AccessTokenResponseHttpMessageConverter();
|
|
|
- private final HttpMessageConverter<OAuth2Error> errorHttpResponseConverter =
|
|
|
- new OAuth2ErrorHttpMessageConverter();
|
|
|
private AuthenticationDetailsSource<HttpServletRequest, ?> authenticationDetailsSource =
|
|
|
new WebAuthenticationDetailsSource();
|
|
|
private AuthenticationConverter authenticationConverter;
|
|
|
private AuthenticationSuccessHandler authenticationSuccessHandler = this::sendAccessTokenResponse;
|
|
|
- private AuthenticationFailureHandler authenticationFailureHandler = this::sendErrorResponse;
|
|
|
+ private AuthenticationFailureHandler authenticationFailureHandler = new OAuth2ErrorAuthenticationFailureHandler();
|
|
|
|
|
|
/**
|
|
|
* Constructs an {@code OAuth2TokenEndpointFilter} using the provided parameters.
|
|
@@ -250,15 +246,6 @@ public final class OAuth2TokenEndpointFilter extends OncePerRequestFilter {
|
|
|
this.accessTokenHttpResponseConverter.write(accessTokenResponse, null, httpResponse);
|
|
|
}
|
|
|
|
|
|
- private void sendErrorResponse(HttpServletRequest request, HttpServletResponse response,
|
|
|
- AuthenticationException exception) throws IOException {
|
|
|
-
|
|
|
- OAuth2Error error = ((OAuth2AuthenticationException) exception).getError();
|
|
|
- ServletServerHttpResponse httpResponse = new ServletServerHttpResponse(response);
|
|
|
- httpResponse.setStatusCode(HttpStatus.BAD_REQUEST);
|
|
|
- this.errorHttpResponseConverter.write(error, null, httpResponse);
|
|
|
- }
|
|
|
-
|
|
|
private static void throwError(String errorCode, String parameterName) {
|
|
|
OAuth2Error error = new OAuth2Error(errorCode, "OAuth 2.0 Parameter: " + parameterName, DEFAULT_ERROR_URI);
|
|
|
throw new OAuth2AuthenticationException(error);
|