|
@@ -47,18 +47,29 @@ import java.util.Set;
|
|
|
* @see DefaultOAuth2User
|
|
|
*/
|
|
|
public class DefaultOAuth2UserService implements OAuth2UserService<OAuth2UserRequest, OAuth2User> {
|
|
|
+ private static final String MISSING_USER_INFO_URI_ERROR_CODE = "missing_user_info_uri";
|
|
|
private static final String MISSING_USER_NAME_ATTRIBUTE_ERROR_CODE = "missing_user_name_attribute";
|
|
|
private NimbusUserInfoResponseClient userInfoResponseClient = new NimbusUserInfoResponseClient();
|
|
|
|
|
|
@Override
|
|
|
public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2AuthenticationException {
|
|
|
Assert.notNull(userRequest, "userRequest cannot be null");
|
|
|
+
|
|
|
+ if (!StringUtils.hasText(userRequest.getClientRegistration().getProviderDetails().getUserInfoEndpoint().getUri())) {
|
|
|
+ OAuth2Error oauth2Error = new OAuth2Error(
|
|
|
+ MISSING_USER_INFO_URI_ERROR_CODE,
|
|
|
+ "Missing required UserInfo Uri in UserInfoEndpoint for Client Registration: " +
|
|
|
+ userRequest.getClientRegistration().getRegistrationId(),
|
|
|
+ null
|
|
|
+ );
|
|
|
+ throw new OAuth2AuthenticationException(oauth2Error, oauth2Error.toString());
|
|
|
+ }
|
|
|
String userNameAttributeName = userRequest.getClientRegistration().getProviderDetails().getUserInfoEndpoint().getUserNameAttributeName();
|
|
|
if (!StringUtils.hasText(userNameAttributeName)) {
|
|
|
OAuth2Error oauth2Error = new OAuth2Error(
|
|
|
MISSING_USER_NAME_ATTRIBUTE_ERROR_CODE,
|
|
|
"Missing required \"user name\" attribute name in UserInfoEndpoint for Client Registration: " +
|
|
|
- userRequest.getClientRegistration().getRegistrationId(),
|
|
|
+ userRequest.getClientRegistration().getRegistrationId(),
|
|
|
null
|
|
|
);
|
|
|
throw new OAuth2AuthenticationException(oauth2Error, oauth2Error.toString());
|