1717package org .springframework .security .oauth2 .client .oidc .userinfo ;
1818
1919import java .time .Instant ;
20- import java .util .Arrays ;
2120import java .util .HashMap ;
22- import java .util .HashSet ;
2321import java .util .Map ;
24- import java .util .Set ;
2522import java .util .function .BiFunction ;
2623import java .util .function .Function ;
2724import java .util .function .Predicate ;
4138import org .springframework .security .oauth2 .core .converter .ClaimConversionService ;
4239import org .springframework .security .oauth2 .core .converter .ClaimTypeConverter ;
4340import org .springframework .security .oauth2 .core .oidc .OidcIdToken ;
44- import org .springframework .security .oauth2 .core .oidc .OidcScopes ;
4541import org .springframework .security .oauth2 .core .oidc .OidcUserInfo ;
4642import org .springframework .security .oauth2 .core .oidc .StandardClaimNames ;
4743import org .springframework .security .oauth2 .core .oidc .user .DefaultOidcUser ;
4844import org .springframework .security .oauth2 .core .oidc .user .OidcUser ;
4945import org .springframework .security .oauth2 .core .oidc .user .OidcUserAuthority ;
5046import org .springframework .security .oauth2 .core .user .OAuth2User ;
5147import org .springframework .util .Assert ;
52- import org .springframework .util .CollectionUtils ;
5348import org .springframework .util .StringUtils ;
5449
5550/**
@@ -72,9 +67,6 @@ public class OidcUserService implements OAuth2UserService<OidcUserRequest, OidcU
7267 private static final Converter <Map <String , Object >, Map <String , Object >> DEFAULT_CLAIM_TYPE_CONVERTER = new ClaimTypeConverter (
7368 createDefaultClaimTypeConverters ());
7469
75- private Set <String > accessibleScopes = new HashSet <>(
76- Arrays .asList (OidcScopes .PROFILE , OidcScopes .EMAIL , OidcScopes .ADDRESS , OidcScopes .PHONE ));
77-
7870 private OAuth2UserService <OAuth2UserRequest , OAuth2User > oauth2UserService = new DefaultOAuth2UserService ();
7971
8072 private Function <ClientRegistration , Converter <Map <String , Object >, Map <String , Object >>> claimTypeConverterFactory = (
@@ -150,30 +142,10 @@ private Map<String, Object> getClaims(OidcUserRequest userRequest, OAuth2User oa
150142 private boolean shouldRetrieveUserInfo (OidcUserRequest userRequest ) {
151143 // Auto-disabled if UserInfo Endpoint URI is not provided
152144 ProviderDetails providerDetails = userRequest .getClientRegistration ().getProviderDetails ();
153- if (!StringUtils .hasLength (providerDetails .getUserInfoEndpoint ().getUri ())) {
154- return false ;
155- }
156- // The Claims requested by the profile, email, address, and phone scope values
157- // are returned from the UserInfo Endpoint (as described in Section 5.3.2),
158- // when a response_type value is used that results in an Access Token being
159- // issued.
160- // However, when no Access Token is issued, which is the case for the
161- // response_type=id_token,
162- // the resulting Claims are returned in the ID Token.
163- // The Authorization Code Grant Flow, which is response_type=code, results in an
164- // Access Token being issued.
165- if (AuthorizationGrantType .AUTHORIZATION_CODE
166- .equals (userRequest .getClientRegistration ().getAuthorizationGrantType ())) {
167- // Return true if there is at least one match between the authorized scope(s)
168- // and accessible scope(s)
169- //
170- // Also return true if authorized scope(s) is empty, because the provider has
171- // not indicated which scopes are accessible via the access token
172- // @formatter:off
173- return this .accessibleScopes .isEmpty ()
174- || CollectionUtils .isEmpty (userRequest .getAccessToken ().getScopes ())
175- || CollectionUtils .containsAny (userRequest .getAccessToken ().getScopes (), this .accessibleScopes );
176- // @formatter:on
145+ if (StringUtils .hasLength (providerDetails .getUserInfoEndpoint ().getUri ())
146+ && AuthorizationGrantType .AUTHORIZATION_CODE
147+ .equals (userRequest .getClientRegistration ().getAuthorizationGrantType ())) {
148+ return true ;
177149 }
178150 return false ;
179151 }
@@ -204,40 +176,18 @@ public final void setClaimTypeConverterFactory(
204176 this .claimTypeConverterFactory = claimTypeConverterFactory ;
205177 }
206178
207- /**
208- * Sets the scope(s) that allow access to the user info resource. The default is
209- * {@link OidcScopes#PROFILE profile}, {@link OidcScopes#EMAIL email},
210- * {@link OidcScopes#ADDRESS address} and {@link OidcScopes#PHONE phone}. The scope(s)
211- * are checked against the "granted" scope(s) associated to the
212- * {@link OidcUserRequest#getAccessToken() access token} to determine if the user info
213- * resource is accessible or not. If there is at least one match, the user info
214- * resource will be requested, otherwise it will not.
215- * @param accessibleScopes the scope(s) that allow access to the user info resource
216- * @since 5.2
217- * @deprecated Use {@link #setRetrieveUserInfo(Predicate)} instead
218- */
219- @ Deprecated (since = "6.3" , forRemoval = true )
220- public final void setAccessibleScopes (Set <String > accessibleScopes ) {
221- Assert .notNull (accessibleScopes , "accessibleScopes cannot be null" );
222- this .accessibleScopes = accessibleScopes ;
223- }
224-
225179 /**
226180 * Sets the {@code Predicate} used to determine if the UserInfo Endpoint should be
227181 * called to retrieve information about the End-User (Resource Owner).
228182 * <p>
229- * By default, the UserInfo Endpoint is called if all of the following are true:
183+ * By default, the UserInfo Endpoint is called if all the following are true:
230184 * <ul>
231185 * <li>The user info endpoint is defined on the ClientRegistration</li>
232186 * <li>The Client Registration uses the
233187 * {@link AuthorizationGrantType#AUTHORIZATION_CODE}</li>
234- * <li>The access token contains one or more scopes allowed to access the UserInfo
235- * Endpoint ({@link OidcScopes#PROFILE profile}, {@link OidcScopes#EMAIL email},
236- * {@link OidcScopes#ADDRESS address} or {@link OidcScopes#PHONE phone}) or the access
237- * token scopes are empty</li>
238188 * </ul>
239- * @param retrieveUserInfo the function used to determine if the UserInfo Endpoint
240- * should be called
189+ * @param retrieveUserInfo the {@code Predicate} used to determine if the UserInfo
190+ * Endpoint should be called
241191 * @since 6.3
242192 */
243193 public final void setRetrieveUserInfo (Predicate <OidcUserRequest > retrieveUserInfo ) {
0 commit comments