Class DefaultOAuth2UserService

  • All Implemented Interfaces:
    OAuth2UserService<OAuth2UserRequest,​org.springframework.security.oauth2.core.user.OAuth2User>

    public class DefaultOAuth2UserService
    extends java.lang.Object
    implements OAuth2UserService<OAuth2UserRequest,​org.springframework.security.oauth2.core.user.OAuth2User>
    An implementation of an OAuth2UserService that supports standard OAuth 2.0 Provider's.

    For standard OAuth 2.0 Provider's, the attribute name used to access the user's name from the UserInfo response is required and therefore must be available via UserInfoEndpoint.getUserNameAttributeName().

    NOTE: Attribute names are not standardized between providers and therefore will vary. Please consult the provider's API documentation for the set of supported user attribute names.

    Since:
    5.0
    See Also:
    OAuth2UserService, OAuth2UserRequest, OAuth2User, DefaultOAuth2User
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.springframework.security.oauth2.core.user.OAuth2User loadUser​(OAuth2UserRequest userRequest)
      Returns an OAuth2User after obtaining the user attributes of the End-User from the UserInfo Endpoint.
      void setRequestEntityConverter​(org.springframework.core.convert.converter.Converter<OAuth2UserRequest,​org.springframework.http.RequestEntity<?>> requestEntityConverter)
      Sets the Converter used for converting the OAuth2UserRequest to a RequestEntity representation of the UserInfo Request.
      void setRestOperations​(org.springframework.web.client.RestOperations restOperations)
      Sets the RestOperations used when requesting the UserInfo resource.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DefaultOAuth2UserService

        public DefaultOAuth2UserService()
    • Method Detail

      • loadUser

        public org.springframework.security.oauth2.core.user.OAuth2User loadUser​(OAuth2UserRequest userRequest)
                                                                          throws org.springframework.security.oauth2.core.OAuth2AuthenticationException
        Description copied from interface: OAuth2UserService
        Returns an OAuth2User after obtaining the user attributes of the End-User from the UserInfo Endpoint.
        Specified by:
        loadUser in interface OAuth2UserService<OAuth2UserRequest,​org.springframework.security.oauth2.core.user.OAuth2User>
        Parameters:
        userRequest - the user request
        Returns:
        an OAuth2User
        Throws:
        org.springframework.security.oauth2.core.OAuth2AuthenticationException - if an error occurs while attempting to obtain the user attributes from the UserInfo Endpoint
      • setRequestEntityConverter

        public final void setRequestEntityConverter​(org.springframework.core.convert.converter.Converter<OAuth2UserRequest,​org.springframework.http.RequestEntity<?>> requestEntityConverter)
        Sets the Converter used for converting the OAuth2UserRequest to a RequestEntity representation of the UserInfo Request.
        Parameters:
        requestEntityConverter - the Converter used for converting to a RequestEntity representation of the UserInfo Request
        Since:
        5.1
      • setRestOperations

        public final void setRestOperations​(org.springframework.web.client.RestOperations restOperations)
        Sets the RestOperations used when requesting the UserInfo resource.

        NOTE: At a minimum, the supplied restOperations must be configured with the following:

        1. ResponseErrorHandler - OAuth2ErrorResponseErrorHandler
        Parameters:
        restOperations - the RestOperations used when requesting the UserInfo resource
        Since:
        5.1