Class DefaultOAuth2User

  • All Implemented Interfaces:
    java.io.Serializable, org.springframework.security.core.AuthenticatedPrincipal, OAuth2AuthenticatedPrincipal, OAuth2User
    Direct Known Subclasses:
    DefaultOidcUser

    public class DefaultOAuth2User
    extends java.lang.Object
    implements OAuth2User, java.io.Serializable
    The default implementation of an OAuth2User.

    User attribute names are not standardized between providers and therefore it is required to supply the key for the user's "name" attribute to one of the constructors. The key will be used for accessing the "name" of the Principal (user) via getAttributes() and returning it from getName().

    Since:
    5.0
    See Also:
    OAuth2User, Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultOAuth2User​(java.util.Collection<? extends org.springframework.security.core.GrantedAuthority> authorities, java.util.Map<java.lang.String,​java.lang.Object> attributes, java.lang.String nameAttributeKey)
      Constructs a DefaultOAuth2User using the provided parameters.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object obj)  
      java.util.Map<java.lang.String,​java.lang.Object> getAttributes()
      Get the OAuth 2.0 token attributes
      java.util.Collection<? extends org.springframework.security.core.GrantedAuthority> getAuthorities()
      Get the Collection of GrantedAuthoritys associated with this OAuth 2.0 token
      java.lang.String getName()  
      int hashCode()  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • DefaultOAuth2User

        public DefaultOAuth2User​(java.util.Collection<? extends org.springframework.security.core.GrantedAuthority> authorities,
                                 java.util.Map<java.lang.String,​java.lang.Object> attributes,
                                 java.lang.String nameAttributeKey)
        Constructs a DefaultOAuth2User using the provided parameters.
        Parameters:
        authorities - the authorities granted to the user
        attributes - the attributes about the user
        nameAttributeKey - the key used to access the user's "name" from getAttributes()
    • Method Detail

      • getName

        public java.lang.String getName()
        Specified by:
        getName in interface org.springframework.security.core.AuthenticatedPrincipal
      • getAuthorities

        public java.util.Collection<? extends org.springframework.security.core.GrantedAuthority> getAuthorities()
        Description copied from interface: OAuth2AuthenticatedPrincipal
        Get the Collection of GrantedAuthoritys associated with this OAuth 2.0 token
        Specified by:
        getAuthorities in interface OAuth2AuthenticatedPrincipal
        Returns:
        the OAuth 2.0 token authorities
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object