|
@@ -32,6 +32,7 @@ import reactor.util.context.Context;
|
|
|
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
+import org.springframework.http.HttpStatusCode;
|
|
|
import org.springframework.security.authentication.AbstractAuthenticationToken;
|
|
|
import org.springframework.security.authentication.AnonymousAuthenticationToken;
|
|
|
import org.springframework.security.core.Authentication;
|
|
@@ -585,7 +586,7 @@ public final class ServletOAuth2AuthorizedClientExchangeFilterFunction implement
|
|
|
* A map of HTTP status code to OAuth 2.0 error code for HTTP status codes that
|
|
|
* should be interpreted as authentication or authorization failures.
|
|
|
*/
|
|
|
- private final Map<Integer, String> httpStatusToOAuth2ErrorCodeMap;
|
|
|
+ private final Map<HttpStatusCode, String> httpStatusToOAuth2ErrorCodeMap;
|
|
|
|
|
|
/**
|
|
|
* The {@link OAuth2AuthorizationFailureHandler} to notify when an
|
|
@@ -596,9 +597,9 @@ public final class ServletOAuth2AuthorizedClientExchangeFilterFunction implement
|
|
|
private AuthorizationFailureForwarder(OAuth2AuthorizationFailureHandler authorizationFailureHandler) {
|
|
|
Assert.notNull(authorizationFailureHandler, "authorizationFailureHandler cannot be null");
|
|
|
this.authorizationFailureHandler = authorizationFailureHandler;
|
|
|
- Map<Integer, String> httpStatusToOAuth2Error = new HashMap<>();
|
|
|
- httpStatusToOAuth2Error.put(HttpStatus.UNAUTHORIZED.value(), OAuth2ErrorCodes.INVALID_TOKEN);
|
|
|
- httpStatusToOAuth2Error.put(HttpStatus.FORBIDDEN.value(), OAuth2ErrorCodes.INSUFFICIENT_SCOPE);
|
|
|
+ Map<HttpStatusCode, String> httpStatusToOAuth2Error = new HashMap<>();
|
|
|
+ httpStatusToOAuth2Error.put(HttpStatus.UNAUTHORIZED, OAuth2ErrorCodes.INVALID_TOKEN);
|
|
|
+ httpStatusToOAuth2Error.put(HttpStatus.FORBIDDEN, OAuth2ErrorCodes.INSUFFICIENT_SCOPE);
|
|
|
this.httpStatusToOAuth2ErrorCodeMap = Collections.unmodifiableMap(httpStatusToOAuth2Error);
|
|
|
}
|
|
|
|
|
@@ -641,10 +642,10 @@ public final class ServletOAuth2AuthorizedClientExchangeFilterFunction implement
|
|
|
authParameters.get(OAuth2ParameterNames.ERROR_URI));
|
|
|
}
|
|
|
}
|
|
|
- return resolveErrorIfPossible(response.statusCode().value());
|
|
|
+ return resolveErrorIfPossible(response.statusCode());
|
|
|
}
|
|
|
|
|
|
- private OAuth2Error resolveErrorIfPossible(int statusCode) {
|
|
|
+ private OAuth2Error resolveErrorIfPossible(HttpStatusCode statusCode) {
|
|
|
if (this.httpStatusToOAuth2ErrorCodeMap.containsKey(statusCode)) {
|
|
|
return new OAuth2Error(this.httpStatusToOAuth2ErrorCodeMap.get(statusCode), null,
|
|
|
"https://tools.ietf.org/html/rfc6750#section-3.1");
|
|
@@ -678,7 +679,7 @@ public final class ServletOAuth2AuthorizedClientExchangeFilterFunction implement
|
|
|
*/
|
|
|
private Mono<Void> handleWebClientResponseException(ClientRequest request,
|
|
|
WebClientResponseException exception) {
|
|
|
- return Mono.justOrEmpty(resolveErrorIfPossible(exception.getRawStatusCode())).flatMap((oauth2Error) -> {
|
|
|
+ return Mono.justOrEmpty(resolveErrorIfPossible(exception.getStatusCode())).flatMap((oauth2Error) -> {
|
|
|
Map<String, Object> attrs = request.attributes();
|
|
|
OAuth2AuthorizedClient authorizedClient = getOAuth2AuthorizedClient(attrs);
|
|
|
if (authorizedClient == null) {
|