|
@@ -1,5 +1,5 @@
|
|
/*
|
|
/*
|
|
- * Copyright 2002-2018 the original author or authors.
|
|
|
|
|
|
+ * Copyright 2002-2020 the original author or authors.
|
|
*
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* you may not use this file except in compliance with the License.
|
|
@@ -38,6 +38,7 @@ import org.springframework.security.oauth2.core.user.OAuth2User;
|
|
import org.springframework.security.oauth2.core.user.OAuth2UserAuthority;
|
|
import org.springframework.security.oauth2.core.user.OAuth2UserAuthority;
|
|
import org.springframework.util.Assert;
|
|
import org.springframework.util.Assert;
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.util.StringUtils;
|
|
|
|
+import org.springframework.web.reactive.function.UnsupportedMediaTypeException;
|
|
import org.springframework.web.reactive.function.client.ClientResponse;
|
|
import org.springframework.web.reactive.function.client.ClientResponse;
|
|
import org.springframework.web.reactive.function.client.WebClient;
|
|
import org.springframework.web.reactive.function.client.WebClient;
|
|
|
|
|
|
@@ -140,7 +141,19 @@ public class DefaultReactiveOAuth2UserService implements ReactiveOAuth2UserServi
|
|
|
|
|
|
return new DefaultOAuth2User(authorities, attrs, userNameAttributeName);
|
|
return new DefaultOAuth2User(authorities, attrs, userNameAttributeName);
|
|
})
|
|
})
|
|
- .onErrorMap(e -> e instanceof IOException, t -> new AuthenticationServiceException("Unable to access the userInfoEndpoint " + userInfoUri, t))
|
|
|
|
|
|
+ .onErrorMap(IOException.class, e -> new AuthenticationServiceException("Unable to access the userInfoEndpoint " + userInfoUri, e))
|
|
|
|
+ .onErrorMap(UnsupportedMediaTypeException.class, e -> {
|
|
|
|
+ String errorMessage = "An error occurred while attempting to retrieve the UserInfo Resource from '" +
|
|
|
|
+ userRequest.getClientRegistration().getProviderDetails().getUserInfoEndpoint().getUri() +
|
|
|
|
+ "': response contains invalid content type '" + e.getContentType().toString() + "'. " +
|
|
|
|
+ "The UserInfo Response should return a JSON object (content type 'application/json') " +
|
|
|
|
+ "that contains a collection of name and value pairs of the claims about the authenticated End-User. " +
|
|
|
|
+ "Please ensure the UserInfo Uri in UserInfoEndpoint for Client Registration '" +
|
|
|
|
+ userRequest.getClientRegistration().getRegistrationId() + "' conforms to the UserInfo Endpoint, " +
|
|
|
|
+ "as defined in OpenID Connect 1.0: 'https://openid.net/specs/openid-connect-core-1_0.html#UserInfo'";
|
|
|
|
+ OAuth2Error oauth2Error = new OAuth2Error(INVALID_USER_INFO_RESPONSE_ERROR_CODE, errorMessage, null);
|
|
|
|
+ throw new OAuth2AuthenticationException(oauth2Error, oauth2Error.toString(), e);
|
|
|
|
+ })
|
|
.onErrorMap(t -> !(t instanceof AuthenticationServiceException), t -> {
|
|
.onErrorMap(t -> !(t instanceof AuthenticationServiceException), t -> {
|
|
OAuth2Error oauth2Error = new OAuth2Error(INVALID_USER_INFO_RESPONSE_ERROR_CODE, "An error occurred reading the UserInfo Success response: " + t.getMessage(), null);
|
|
OAuth2Error oauth2Error = new OAuth2Error(INVALID_USER_INFO_RESPONSE_ERROR_CODE, "An error occurred reading the UserInfo Success response: " + t.getMessage(), null);
|
|
return new OAuth2AuthenticationException(oauth2Error, oauth2Error.toString(), t);
|
|
return new OAuth2AuthenticationException(oauth2Error, oauth2Error.toString(), t);
|