From 6c0ecea4944e320f72731f84caf535f770876201 Mon Sep 17 00:00:00 2001 From: Joe Grandja Date: Thu, 1 Jun 2017 16:04:24 -0400 Subject: [PATCH] Use java.util.Function instead of Converter Fixes gh-4323 --- ...tionCodeAuthenticationFilterConfigurer.java | 6 +++--- .../oauth2/client/OAuth2LoginConfigurer.java | 4 ++-- ...tionCodeAuthenticationProcessingFilter.java | 4 ++-- .../converter/AbstractOAuth2UserConverter.java | 12 ++++++------ .../converter/CustomOAuth2UserConverter.java | 18 ++++++++++-------- .../user/converter/OAuth2UserConverter.java | 2 +- .../user/converter/UserInfoConverter.java | 2 +- .../client/user/converter/package-info.java | 3 +-- .../user/nimbus/NimbusOAuth2UserService.java | 15 +++++++-------- ...thorizationResponseAttributesConverter.java | 8 ++++---- .../ErrorResponseAttributesConverter.java | 8 ++++---- .../client/web/converter/package-info.java | 3 +-- samples/boot/oauth2login/README.adoc | 4 ++-- .../client/OAuth2LoginAutoConfiguration.java | 14 +++++++------- 14 files changed, 51 insertions(+), 52 deletions(-) diff --git a/config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/client/AuthorizationCodeAuthenticationFilterConfigurer.java b/config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/client/AuthorizationCodeAuthenticationFilterConfigurer.java index 508330b748..b8ec434b2b 100644 --- a/config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/client/AuthorizationCodeAuthenticationFilterConfigurer.java +++ b/config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/client/AuthorizationCodeAuthenticationFilterConfigurer.java @@ -15,7 +15,6 @@ */ package org.springframework.security.config.annotation.web.configurers.oauth2.client; -import org.springframework.core.convert.converter.Converter; import org.springframework.http.client.ClientHttpResponse; import org.springframework.security.config.annotation.web.HttpSecurityBuilder; import org.springframework.security.config.annotation.web.configurers.AbstractAuthenticationFilterConfigurer; @@ -34,6 +33,7 @@ import org.springframework.util.Assert; import java.net.URI; import java.util.HashMap; import java.util.Map; +import java.util.function.Function; /** * @author Joe Grandja @@ -43,7 +43,7 @@ final class AuthorizationCodeAuthenticationFilterConfigurer authorizationCodeTokenExchanger; private OAuth2UserService userInfoService; - private Map> userInfoTypeConverters = new HashMap<>(); + private Map> userInfoTypeConverters = new HashMap<>(); AuthorizationCodeAuthenticationFilterConfigurer() { @@ -71,7 +71,7 @@ final class AuthorizationCodeAuthenticationFilterConfigurer userInfoTypeConverter(Converter userInfoConverter, URI userInfoUri) { + AuthorizationCodeAuthenticationFilterConfigurer userInfoTypeConverter(Function userInfoConverter, URI userInfoUri) { Assert.notNull(userInfoConverter, "userInfoConverter cannot be null"); Assert.notNull(userInfoUri, "userInfoUri cannot be null"); this.userInfoTypeConverters.put(userInfoUri, userInfoConverter); diff --git a/config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/client/OAuth2LoginConfigurer.java b/config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/client/OAuth2LoginConfigurer.java index c619d1be9d..1d36f67d48 100644 --- a/config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/client/OAuth2LoginConfigurer.java +++ b/config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/client/OAuth2LoginConfigurer.java @@ -16,7 +16,6 @@ package org.springframework.security.config.annotation.web.configurers.oauth2.client; import org.springframework.context.ApplicationContext; -import org.springframework.core.convert.converter.Converter; import org.springframework.http.client.ClientHttpResponse; import org.springframework.security.config.annotation.web.HttpSecurityBuilder; import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; @@ -36,6 +35,7 @@ import org.springframework.util.CollectionUtils; import java.net.URI; import java.util.Arrays; import java.util.Map; +import java.util.function.Function; import java.util.stream.Collectors; /** @@ -95,7 +95,7 @@ public final class OAuth2LoginConfigurer> exten return this.and(); } - public OAuth2LoginConfigurer userInfoTypeConverter(Converter userInfoConverter, URI userInfoUri) { + public OAuth2LoginConfigurer userInfoTypeConverter(Function userInfoConverter, URI userInfoUri) { Assert.notNull(userInfoConverter, "userInfoConverter cannot be null"); Assert.notNull(userInfoUri, "userInfoUri cannot be null"); OAuth2LoginConfigurer.this.authorizationCodeAuthenticationFilterConfigurer.userInfoTypeConverter(userInfoConverter, userInfoUri); diff --git a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/authentication/AuthorizationCodeAuthenticationProcessingFilter.java b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/authentication/AuthorizationCodeAuthenticationProcessingFilter.java index bc8c144123..4fa10d6afe 100644 --- a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/authentication/AuthorizationCodeAuthenticationProcessingFilter.java +++ b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/authentication/AuthorizationCodeAuthenticationProcessingFilter.java @@ -123,7 +123,7 @@ public class AuthorizationCodeAuthenticationProcessingFilter extends AbstractAut public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException { - ErrorResponseAttributes authorizationError = this.errorResponseConverter.convert(request); + ErrorResponseAttributes authorizationError = this.errorResponseConverter.apply(request); if (authorizationError != null) { OAuth2Error oauth2Error = new OAuth2Error(authorizationError.getErrorCode(), authorizationError.getDescription(), authorizationError.getUri()); @@ -144,7 +144,7 @@ public class AuthorizationCodeAuthenticationProcessingFilter extends AbstractAut } AuthorizationCodeAuthorizationResponseAttributes authorizationCodeResponseAttributes = - this.authorizationCodeResponseConverter.convert(request); + this.authorizationCodeResponseConverter.apply(request); AuthorizationCodeAuthenticationToken authRequest = new AuthorizationCodeAuthenticationToken( authorizationCodeResponseAttributes.getCode(), clientRegistration); diff --git a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/user/converter/AbstractOAuth2UserConverter.java b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/user/converter/AbstractOAuth2UserConverter.java index aa20aff605..0109c5627b 100644 --- a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/user/converter/AbstractOAuth2UserConverter.java +++ b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/user/converter/AbstractOAuth2UserConverter.java @@ -15,7 +15,6 @@ */ package org.springframework.security.oauth2.client.user.converter; -import org.springframework.core.convert.converter.Converter; import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; @@ -23,9 +22,10 @@ import org.springframework.security.oauth2.core.user.OAuth2User; import java.io.IOException; import java.util.Map; +import java.util.function.Function; /** - * Base implementation of a {@link Converter} that converts a {@link ClientHttpResponse} + * Base implementation of a Function that converts a {@link ClientHttpResponse} * to a specific type of {@link OAuth2User}. * * @author Joe Grandja @@ -33,14 +33,14 @@ import java.util.Map; * @see OAuth2User * @see ClientHttpResponse */ -public abstract class AbstractOAuth2UserConverter implements Converter { +public abstract class AbstractOAuth2UserConverter implements Function { private final HttpMessageConverter jackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter(); protected AbstractOAuth2UserConverter() { } @Override - public final T convert(ClientHttpResponse clientHttpResponse) { + public final R apply(ClientHttpResponse clientHttpResponse) { Map userAttributes; try { @@ -49,9 +49,9 @@ public abstract class AbstractOAuth2UserConverter implemen throw new IllegalArgumentException("An error occurred reading the UserInfo response: " + ex.getMessage(), ex); } - return this.convert(userAttributes); + return this.apply(userAttributes); } - protected abstract T convert(Map userAttributes); + protected abstract R apply(Map userAttributes); } diff --git a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/user/converter/CustomOAuth2UserConverter.java b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/user/converter/CustomOAuth2UserConverter.java index c101a4fe83..85b1b906d2 100644 --- a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/user/converter/CustomOAuth2UserConverter.java +++ b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/user/converter/CustomOAuth2UserConverter.java @@ -15,16 +15,17 @@ */ package org.springframework.security.oauth2.client.user.converter; -import org.springframework.core.convert.converter.Converter; import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.security.oauth2.core.user.OAuth2User; +import org.springframework.util.Assert; import java.io.IOException; +import java.util.function.Function; /** - * An implementation of a {@link Converter} that converts a {@link ClientHttpResponse} + * A Function that converts a {@link ClientHttpResponse} * to a custom type of {@link OAuth2User}, as supplied via the constructor. * * @author Joe Grandja @@ -32,20 +33,21 @@ import java.io.IOException; * @see OAuth2User * @see ClientHttpResponse */ -public final class CustomOAuth2UserConverter implements Converter { +public final class CustomOAuth2UserConverter implements Function { private final HttpMessageConverter jackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter(); - private final Class customType; + private final Class customType; - public CustomOAuth2UserConverter(Class customType) { + public CustomOAuth2UserConverter(Class customType) { + Assert.notNull(customType, "customType cannot be null"); this.customType = customType; } @Override - public T convert(ClientHttpResponse clientHttpResponse) { - T user; + public R apply(ClientHttpResponse clientHttpResponse) { + R user; try { - user = (T) this.jackson2HttpMessageConverter.read(this.customType, clientHttpResponse); + user = (R) this.jackson2HttpMessageConverter.read(this.customType, clientHttpResponse); } catch (IOException ex) { throw new IllegalArgumentException("An error occurred reading the UserInfo response: " + ex.getMessage(), ex); } diff --git a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/user/converter/OAuth2UserConverter.java b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/user/converter/OAuth2UserConverter.java index 3e0d123644..99d47874ac 100644 --- a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/user/converter/OAuth2UserConverter.java +++ b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/user/converter/OAuth2UserConverter.java @@ -40,7 +40,7 @@ public final class OAuth2UserConverter extends AbstractOAuth2UserConverter userAttributes) { + protected OAuth2User apply(Map userAttributes) { return new DefaultOAuth2User(userAttributes, this.nameAttributeKey); } } diff --git a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/user/converter/UserInfoConverter.java b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/user/converter/UserInfoConverter.java index 6b06fece18..2544a9a35d 100644 --- a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/user/converter/UserInfoConverter.java +++ b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/user/converter/UserInfoConverter.java @@ -33,7 +33,7 @@ import java.util.Map; public final class UserInfoConverter extends AbstractOAuth2UserConverter { @Override - protected UserInfo convert(Map userAttributes) { + protected UserInfo apply(Map userAttributes) { return new DefaultUserInfo(userAttributes); } } diff --git a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/user/converter/package-info.java b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/user/converter/package-info.java index 6ebf53767b..2076982ef0 100644 --- a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/user/converter/package-info.java +++ b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/user/converter/package-info.java @@ -14,7 +14,6 @@ * limitations under the License. */ /** - * {@link org.springframework.core.convert.converter.Converter} implementations - * for {@link org.springframework.security.oauth2.core.user.OAuth2User}. + * Support classes for converting to {@link org.springframework.security.oauth2.core.user.OAuth2User}. */ package org.springframework.security.oauth2.client.user.converter; diff --git a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/user/nimbus/NimbusOAuth2UserService.java b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/user/nimbus/NimbusOAuth2UserService.java index dde39be591..5bcbc42d94 100644 --- a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/user/nimbus/NimbusOAuth2UserService.java +++ b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/user/nimbus/NimbusOAuth2UserService.java @@ -22,7 +22,6 @@ import com.nimbusds.oauth2.sdk.http.HTTPResponse; import com.nimbusds.oauth2.sdk.token.BearerAccessToken; import com.nimbusds.openid.connect.sdk.UserInfoErrorResponse; import com.nimbusds.openid.connect.sdk.UserInfoRequest; -import org.springframework.core.convert.converter.Converter; import org.springframework.http.MediaType; import org.springframework.http.client.ClientHttpResponse; import org.springframework.security.authentication.AuthenticationServiceException; @@ -40,13 +39,14 @@ import java.io.IOException; import java.net.URI; import java.util.HashMap; import java.util.Map; +import java.util.function.Function; /** * An implementation of an {@link OAuth2UserService} that uses the Nimbus OAuth 2.0 SDK internally. * *

- * This implementation uses a Map of Converter's keyed by URI. - * The URI represents the UserInfo Endpoint address and the mapped Converter + * This implementation uses a Map of converter's keyed by URI. + * The URI represents the UserInfo Endpoint address and the mapped Function * is capable of converting the UserInfo Response to either an * {@link OAuth2User} (for a standard OAuth 2.0 Provider) or * {@link UserInfo} (for an OpenID Connect 1.0 Provider). @@ -57,14 +57,13 @@ import java.util.Map; * @see AuthenticatedPrincipal * @see OAuth2User * @see UserInfo - * @see Converter * @see Nimbus OAuth 2.0 SDK */ public class NimbusOAuth2UserService implements OAuth2UserService { private static final String INVALID_USER_INFO_RESPONSE_ERROR_CODE = "invalid_user_info_response"; - private final Map> userInfoTypeConverters; + private final Map> userInfoTypeConverters; - public NimbusOAuth2UserService(Map> userInfoTypeConverters) { + public NimbusOAuth2UserService(Map> userInfoTypeConverters) { Assert.notEmpty(userInfoTypeConverters, "userInfoTypeConverters cannot be empty"); this.userInfoTypeConverters = new HashMap<>(userInfoTypeConverters); } @@ -84,7 +83,7 @@ public class NimbusOAuth2UserService implements OAuth2UserService { clientRegistration.getProviderDetails().getUserInfoUri(), ex); } - Converter userInfoConverter = this.userInfoTypeConverters.get(userInfoUri); + Function userInfoConverter = this.userInfoTypeConverters.get(userInfoUri); if (userInfoConverter == null) { throw new IllegalArgumentException("There is no available User Info converter for " + userInfoUri.toString()); } @@ -118,7 +117,7 @@ public class NimbusOAuth2UserService implements OAuth2UserService { throw new OAuth2AuthenticationException(oauth2Error, oauth2Error.toString()); } - user = userInfoConverter.convert(new NimbusClientHttpResponse(httpResponse)); + user = userInfoConverter.apply(new NimbusClientHttpResponse(httpResponse)); } catch (ParseException ex) { // This error occurs if the User Info Response is not well-formed or invalid diff --git a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/converter/AuthorizationCodeAuthorizationResponseAttributesConverter.java b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/converter/AuthorizationCodeAuthorizationResponseAttributesConverter.java index 9c893bc119..149208ce99 100644 --- a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/converter/AuthorizationCodeAuthorizationResponseAttributesConverter.java +++ b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/converter/AuthorizationCodeAuthorizationResponseAttributesConverter.java @@ -15,15 +15,15 @@ */ package org.springframework.security.oauth2.client.web.converter; -import org.springframework.core.convert.converter.Converter; import org.springframework.security.oauth2.core.endpoint.AuthorizationCodeAuthorizationResponseAttributes; import org.springframework.security.oauth2.core.endpoint.OAuth2Parameter; import org.springframework.util.Assert; import javax.servlet.http.HttpServletRequest; +import java.util.function.Function; /** - * An implementation of a {@link Converter} that converts an OAuth 2.0 Authorization Code Grant Response + * A Function that converts an OAuth 2.0 Authorization Code Grant Response * (in the form of a {@link HttpServletRequest}) to a {@link AuthorizationCodeAuthorizationResponseAttributes}. * * @author Joe Grandja @@ -31,10 +31,10 @@ import javax.servlet.http.HttpServletRequest; * @see AuthorizationCodeAuthorizationResponseAttributes * @see Section 4.1.2 Authorization Code Grant Response */ -public final class AuthorizationCodeAuthorizationResponseAttributesConverter implements Converter { +public final class AuthorizationCodeAuthorizationResponseAttributesConverter implements Function { @Override - public AuthorizationCodeAuthorizationResponseAttributes convert(HttpServletRequest request) { + public AuthorizationCodeAuthorizationResponseAttributes apply(HttpServletRequest request) { AuthorizationCodeAuthorizationResponseAttributes response; String code = request.getParameter(OAuth2Parameter.CODE); diff --git a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/converter/ErrorResponseAttributesConverter.java b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/converter/ErrorResponseAttributesConverter.java index 6bee0b37a4..68fffd29e5 100644 --- a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/converter/ErrorResponseAttributesConverter.java +++ b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/converter/ErrorResponseAttributesConverter.java @@ -15,25 +15,25 @@ */ package org.springframework.security.oauth2.client.web.converter; -import org.springframework.core.convert.converter.Converter; import org.springframework.security.oauth2.core.endpoint.ErrorResponseAttributes; import org.springframework.security.oauth2.core.endpoint.OAuth2Parameter; import org.springframework.util.StringUtils; import javax.servlet.http.HttpServletRequest; +import java.util.function.Function; /** - * An implementation of a {@link Converter} that converts an OAuth 2.0 Error Response + * A Function that converts an OAuth 2.0 Error Response * (in the form of a {@link HttpServletRequest}) to a {@link ErrorResponseAttributes}. * * @author Joe Grandja * @since 5.0 * @see ErrorResponseAttributes */ -public final class ErrorResponseAttributesConverter implements Converter { +public final class ErrorResponseAttributesConverter implements Function { @Override - public ErrorResponseAttributes convert(HttpServletRequest request) { + public ErrorResponseAttributes apply(HttpServletRequest request) { ErrorResponseAttributes response; String errorCode = request.getParameter(OAuth2Parameter.ERROR); diff --git a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/converter/package-info.java b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/converter/package-info.java index 1678695af9..4c9b2584c2 100644 --- a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/converter/package-info.java +++ b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/converter/package-info.java @@ -14,7 +14,6 @@ * limitations under the License. */ /** - * {@link org.springframework.core.convert.converter.Converter} implementations - * for OAuth 2.0 Protocol Endpoint Messages. + * Support classes for converting OAuth 2.0 Protocol Endpoint Messages. */ package org.springframework.security.oauth2.client.web.converter; diff --git a/samples/boot/oauth2login/README.adoc b/samples/boot/oauth2login/README.adoc index 0b6cb04832..dd6f7e7826 100644 --- a/samples/boot/oauth2login/README.adoc +++ b/samples/boot/oauth2login/README.adoc @@ -410,9 +410,9 @@ NOTE: Non-standard scopes may be defined by a standard _OAuth 2.0 Provider_. Ple - *authorization-uri* - the URI used by the client to redirect the end-user's user-agent to the _Authorization Server_ in order to obtain authorization from the end-user (the _Resource Owner_). - *token-uri* - the URI used by the client when exchanging an _Authorization Grant_ (for example, Authorization Code) for an _Access Token_ at the _Authorization Server_. - *user-info-uri* - the URI used by the client to access the protected resource *UserInfo Endpoint*, in order to obtain attributes of the end-user. -- *user-info-converter* - the `Converter` implementation class used to convert the *UserInfo Response* to a `UserInfo` (_OpenID Connect 1.0 Provider_) or `OAuth2User` instance (_Standard OAuth 2.0 Provider_). +- *user-info-converter* - the `java.util.function.Function` implementation class used to convert the *UserInfo Response* to a `UserInfo` (_OpenID Connect 1.0 Provider_) or `OAuth2User` instance (_Standard OAuth 2.0 Provider_). -TIP: The `Converter` implementation class for an _OpenID Connect 1.0 Provider_ is *org.springframework.security.oauth2.client.user.converter.UserInfoConverter* +TIP: The `java.util.function.Function` implementation class for an _OpenID Connect 1.0 Provider_ is *org.springframework.security.oauth2.client.user.converter.UserInfoConverter* and for a standard _OAuth 2.0 Provider_ it's *org.springframework.security.oauth2.client.user.converter.OAuth2UserConverter*. - *user-info-name-attribute-key* - the _key_ used to retrieve the *Name* of the end-user from the `Map` of available attributes in `UserInfo` or `OAuth2User`. diff --git a/samples/boot/oauth2login/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2LoginAutoConfiguration.java b/samples/boot/oauth2login/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2LoginAutoConfiguration.java index ebf6cac6b4..654ff66c08 100644 --- a/samples/boot/oauth2login/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2LoginAutoConfiguration.java +++ b/samples/boot/oauth2login/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2LoginAutoConfiguration.java @@ -23,7 +23,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration; import org.springframework.context.annotation.Configuration; -import org.springframework.core.convert.converter.Converter; import org.springframework.core.env.Environment; import org.springframework.http.client.ClientHttpResponse; import org.springframework.security.config.annotation.web.builders.HttpSecurity; @@ -39,6 +38,7 @@ import org.springframework.util.ClassUtils; import java.lang.reflect.Constructor; import java.net.URI; import java.util.Set; +import java.util.function.Function; import static org.springframework.boot.autoconfigure.security.oauth2.client.ClientRegistrationAutoConfiguration.CLIENT_PROPERTY_PREFIX; import static org.springframework.boot.autoconfigure.security.oauth2.client.ClientRegistrationAutoConfiguration.resolveClientPropertyKeys; @@ -87,18 +87,18 @@ public class OAuth2LoginAutoConfiguration { String userInfoUriValue = this.environment.getProperty(fullClientPropertyKey + "." + USER_INFO_URI_PROPERTY); String userInfoConverterTypeValue = this.environment.getProperty(fullClientPropertyKey + "." + USER_INFO_CONVERTER_PROPERTY); if (userInfoUriValue != null && userInfoConverterTypeValue != null) { - Class userInfoConverterType = ClassUtils.resolveClassName( - userInfoConverterTypeValue, this.getClass().getClassLoader()).asSubclass(Converter.class); - Converter userInfoConverter = null; + Class userInfoConverterType = ClassUtils.resolveClassName( + userInfoConverterTypeValue, this.getClass().getClassLoader()).asSubclass(Function.class); + Function userInfoConverter = null; if (AbstractOAuth2UserConverter.class.isAssignableFrom(userInfoConverterType)) { - Constructor oauth2UserConverterConstructor = ClassUtils.getConstructorIfAvailable(userInfoConverterType, String.class); + Constructor oauth2UserConverterConstructor = ClassUtils.getConstructorIfAvailable(userInfoConverterType, String.class); if (oauth2UserConverterConstructor != null) { String userInfoNameAttributeKey = this.environment.getProperty(fullClientPropertyKey + "." + USER_INFO_NAME_ATTR_KEY_PROPERTY); - userInfoConverter = (Converter)oauth2UserConverterConstructor.newInstance(userInfoNameAttributeKey); + userInfoConverter = (Function)oauth2UserConverterConstructor.newInstance(userInfoNameAttributeKey); } } if (userInfoConverter == null) { - userInfoConverter = (Converter)userInfoConverterType.newInstance(); + userInfoConverter = (Function)userInfoConverterType.newInstance(); } oauth2LoginConfigurer.userInfoEndpoint().userInfoTypeConverter(userInfoConverter, new URI(userInfoUriValue)); }