|  | @@ -17,11 +17,8 @@
 | 
	
		
			
				|  |  |  package org.springframework.security.oauth2.client.oidc.userinfo;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import java.time.Instant;
 | 
	
		
			
				|  |  | -import java.util.Arrays;
 | 
	
		
			
				|  |  |  import java.util.HashMap;
 | 
	
		
			
				|  |  | -import java.util.HashSet;
 | 
	
		
			
				|  |  |  import java.util.Map;
 | 
	
		
			
				|  |  | -import java.util.Set;
 | 
	
		
			
				|  |  |  import java.util.function.BiFunction;
 | 
	
		
			
				|  |  |  import java.util.function.Function;
 | 
	
		
			
				|  |  |  import java.util.function.Predicate;
 | 
	
	
		
			
				|  | @@ -41,7 +38,6 @@ import org.springframework.security.oauth2.core.OAuth2Error;
 | 
	
		
			
				|  |  |  import org.springframework.security.oauth2.core.converter.ClaimConversionService;
 | 
	
		
			
				|  |  |  import org.springframework.security.oauth2.core.converter.ClaimTypeConverter;
 | 
	
		
			
				|  |  |  import org.springframework.security.oauth2.core.oidc.OidcIdToken;
 | 
	
		
			
				|  |  | -import org.springframework.security.oauth2.core.oidc.OidcScopes;
 | 
	
		
			
				|  |  |  import org.springframework.security.oauth2.core.oidc.OidcUserInfo;
 | 
	
		
			
				|  |  |  import org.springframework.security.oauth2.core.oidc.StandardClaimNames;
 | 
	
		
			
				|  |  |  import org.springframework.security.oauth2.core.oidc.user.DefaultOidcUser;
 | 
	
	
		
			
				|  | @@ -49,7 +45,6 @@ import org.springframework.security.oauth2.core.oidc.user.OidcUser;
 | 
	
		
			
				|  |  |  import org.springframework.security.oauth2.core.oidc.user.OidcUserAuthority;
 | 
	
		
			
				|  |  |  import org.springframework.security.oauth2.core.user.OAuth2User;
 | 
	
		
			
				|  |  |  import org.springframework.util.Assert;
 | 
	
		
			
				|  |  | -import org.springframework.util.CollectionUtils;
 | 
	
		
			
				|  |  |  import org.springframework.util.StringUtils;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /**
 | 
	
	
		
			
				|  | @@ -72,9 +67,6 @@ public class OidcUserService implements OAuth2UserService<OidcUserRequest, OidcU
 | 
	
		
			
				|  |  |  	private static final Converter<Map<String, Object>, Map<String, Object>> DEFAULT_CLAIM_TYPE_CONVERTER = new ClaimTypeConverter(
 | 
	
		
			
				|  |  |  			createDefaultClaimTypeConverters());
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	private Set<String> accessibleScopes = new HashSet<>(
 | 
	
		
			
				|  |  | -			Arrays.asList(OidcScopes.PROFILE, OidcScopes.EMAIL, OidcScopes.ADDRESS, OidcScopes.PHONE));
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |  	private OAuth2UserService<OAuth2UserRequest, OAuth2User> oauth2UserService = new DefaultOAuth2UserService();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	private Function<ClientRegistration, Converter<Map<String, Object>, Map<String, Object>>> claimTypeConverterFactory = (
 | 
	
	
		
			
				|  | @@ -150,30 +142,10 @@ public class OidcUserService implements OAuth2UserService<OidcUserRequest, OidcU
 | 
	
		
			
				|  |  |  	private boolean shouldRetrieveUserInfo(OidcUserRequest userRequest) {
 | 
	
		
			
				|  |  |  		// Auto-disabled if UserInfo Endpoint URI is not provided
 | 
	
		
			
				|  |  |  		ProviderDetails providerDetails = userRequest.getClientRegistration().getProviderDetails();
 | 
	
		
			
				|  |  | -		if (!StringUtils.hasLength(providerDetails.getUserInfoEndpoint().getUri())) {
 | 
	
		
			
				|  |  | -			return false;
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | -		// The Claims requested by the profile, email, address, and phone scope values
 | 
	
		
			
				|  |  | -		// are returned from the UserInfo Endpoint (as described in Section 5.3.2),
 | 
	
		
			
				|  |  | -		// when a response_type value is used that results in an Access Token being
 | 
	
		
			
				|  |  | -		// issued.
 | 
	
		
			
				|  |  | -		// However, when no Access Token is issued, which is the case for the
 | 
	
		
			
				|  |  | -		// response_type=id_token,
 | 
	
		
			
				|  |  | -		// the resulting Claims are returned in the ID Token.
 | 
	
		
			
				|  |  | -		// The Authorization Code Grant Flow, which is response_type=code, results in an
 | 
	
		
			
				|  |  | -		// Access Token being issued.
 | 
	
		
			
				|  |  | -		if (AuthorizationGrantType.AUTHORIZATION_CODE
 | 
	
		
			
				|  |  | -			.equals(userRequest.getClientRegistration().getAuthorizationGrantType())) {
 | 
	
		
			
				|  |  | -			// Return true if there is at least one match between the authorized scope(s)
 | 
	
		
			
				|  |  | -			// and accessible scope(s)
 | 
	
		
			
				|  |  | -			//
 | 
	
		
			
				|  |  | -			// Also return true if authorized scope(s) is empty, because the provider has
 | 
	
		
			
				|  |  | -			// not indicated which scopes are accessible via the access token
 | 
	
		
			
				|  |  | -			// @formatter:off
 | 
	
		
			
				|  |  | -			return this.accessibleScopes.isEmpty()
 | 
	
		
			
				|  |  | -					|| CollectionUtils.isEmpty(userRequest.getAccessToken().getScopes())
 | 
	
		
			
				|  |  | -					|| CollectionUtils.containsAny(userRequest.getAccessToken().getScopes(), this.accessibleScopes);
 | 
	
		
			
				|  |  | -			// @formatter:on
 | 
	
		
			
				|  |  | +		if (StringUtils.hasLength(providerDetails.getUserInfoEndpoint().getUri())
 | 
	
		
			
				|  |  | +				&& AuthorizationGrantType.AUTHORIZATION_CODE
 | 
	
		
			
				|  |  | +					.equals(userRequest.getClientRegistration().getAuthorizationGrantType())) {
 | 
	
		
			
				|  |  | +			return true;
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  		return false;
 | 
	
		
			
				|  |  |  	}
 | 
	
	
		
			
				|  | @@ -204,40 +176,18 @@ public class OidcUserService implements OAuth2UserService<OidcUserRequest, OidcU
 | 
	
		
			
				|  |  |  		this.claimTypeConverterFactory = claimTypeConverterFactory;
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	/**
 | 
	
		
			
				|  |  | -	 * Sets the scope(s) that allow access to the user info resource. The default is
 | 
	
		
			
				|  |  | -	 * {@link OidcScopes#PROFILE profile}, {@link OidcScopes#EMAIL email},
 | 
	
		
			
				|  |  | -	 * {@link OidcScopes#ADDRESS address} and {@link OidcScopes#PHONE phone}. The scope(s)
 | 
	
		
			
				|  |  | -	 * are checked against the "granted" scope(s) associated to the
 | 
	
		
			
				|  |  | -	 * {@link OidcUserRequest#getAccessToken() access token} to determine if the user info
 | 
	
		
			
				|  |  | -	 * resource is accessible or not. If there is at least one match, the user info
 | 
	
		
			
				|  |  | -	 * resource will be requested, otherwise it will not.
 | 
	
		
			
				|  |  | -	 * @param accessibleScopes the scope(s) that allow access to the user info resource
 | 
	
		
			
				|  |  | -	 * @since 5.2
 | 
	
		
			
				|  |  | -	 * @deprecated Use {@link #setRetrieveUserInfo(Predicate)} instead
 | 
	
		
			
				|  |  | -	 */
 | 
	
		
			
				|  |  | -	@Deprecated(since = "6.3", forRemoval = true)
 | 
	
		
			
				|  |  | -	public final void setAccessibleScopes(Set<String> accessibleScopes) {
 | 
	
		
			
				|  |  | -		Assert.notNull(accessibleScopes, "accessibleScopes cannot be null");
 | 
	
		
			
				|  |  | -		this.accessibleScopes = accessibleScopes;
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |  	/**
 | 
	
		
			
				|  |  |  	 * Sets the {@code Predicate} used to determine if the UserInfo Endpoint should be
 | 
	
		
			
				|  |  |  	 * called to retrieve information about the End-User (Resource Owner).
 | 
	
		
			
				|  |  |  	 * <p>
 | 
	
		
			
				|  |  | -	 * By default, the UserInfo Endpoint is called if all of the following are true:
 | 
	
		
			
				|  |  | +	 * By default, the UserInfo Endpoint is called if all the following are true:
 | 
	
		
			
				|  |  |  	 * <ul>
 | 
	
		
			
				|  |  |  	 * <li>The user info endpoint is defined on the ClientRegistration</li>
 | 
	
		
			
				|  |  |  	 * <li>The Client Registration uses the
 | 
	
		
			
				|  |  |  	 * {@link AuthorizationGrantType#AUTHORIZATION_CODE}</li>
 | 
	
		
			
				|  |  | -	 * <li>The access token contains one or more scopes allowed to access the UserInfo
 | 
	
		
			
				|  |  | -	 * Endpoint ({@link OidcScopes#PROFILE profile}, {@link OidcScopes#EMAIL email},
 | 
	
		
			
				|  |  | -	 * {@link OidcScopes#ADDRESS address} or {@link OidcScopes#PHONE phone}) or the access
 | 
	
		
			
				|  |  | -	 * token scopes are empty</li>
 | 
	
		
			
				|  |  |  	 * </ul>
 | 
	
		
			
				|  |  | -	 * @param retrieveUserInfo the function used to determine if the UserInfo Endpoint
 | 
	
		
			
				|  |  | -	 * should be called
 | 
	
		
			
				|  |  | +	 * @param retrieveUserInfo the {@code Predicate} used to determine if the UserInfo
 | 
	
		
			
				|  |  | +	 * Endpoint should be called
 | 
	
		
			
				|  |  |  	 * @since 6.3
 | 
	
		
			
				|  |  |  	 */
 | 
	
		
			
				|  |  |  	public final void setRetrieveUserInfo(Predicate<OidcUserRequest> retrieveUserInfo) {
 |