Class UserPrincipal

java.lang.Object
com.alpaca.model.UserPrincipal
All Implemented Interfaces:
Serializable, org.springframework.security.core.AuthenticatedPrincipal, org.springframework.security.core.userdetails.UserDetails, org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal, org.springframework.security.oauth2.core.user.OAuth2User

public class UserPrincipal extends Object implements org.springframework.security.oauth2.core.user.OAuth2User, org.springframework.security.core.userdetails.UserDetails
Represents the Principal User Details in the security context. This class implements both OAuth2User and UserDetails to support authentication via OAuth2 and traditional login mechanisms.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private boolean
    Indicates whether the User's entity is not expired.
    private boolean
    Indicates whether the User's entity is not locked.
    private UUID
    Unique identifier for the associated advertiser account, if available.
    private Map<String,Object>
    Additional attributes provided by an OAuth2 authentication provider.
    private Collection<? extends org.springframework.security.core.GrantedAuthority>
    The authorities granted to the user for authorization purposes.
    private boolean
    Indicates whether the User's credentials are not expired.
    private boolean
    Indicates whether the User's entity is enabled.
    private UUID
    Unique identifier for the user.
    private String
    The encrypted password of the user.
    private UUID
    Unique identifier for the associated profile, if available.
    private String
    The username of the user, typically the email address.
  • Constructor Summary

    Constructors
    Constructor
    Description
    UserPrincipal(User user, Map<String,Object> attributes)
    Constructs a new UserPrincipal instance using a User entity.
    UserPrincipal(UUID userId, UUID profileId, UUID advertiserId, String username, String password, Collection<? extends org.springframework.security.core.GrantedAuthority> authoritiesList, Map<String,Object> attributes)
    Constructs a new UserPrincipal instance using a decoded JWT token values.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
     
    Retrieves the attributes associated with the user from an OAuth2 provider.
    Retrieves the name of the user.
    int
     
    boolean
     
    boolean
     
    boolean
     
    boolean
     

    Methods inherited from class java.lang.Object

    clone, getClass, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal

    getAttribute, getAuthorities

    Methods inherited from interface org.springframework.security.core.userdetails.UserDetails

    getAuthorities, getPassword, getUsername
  • Field Details

    • id

      private UUID id
      Unique identifier for the user.
    • profileId

      private UUID profileId
      Unique identifier for the associated profile, if available.
    • advertiserId

      private UUID advertiserId
      Unique identifier for the associated advertiser account, if available.
    • username

      private String username
      The username of the user, typically the email address.
    • password

      private String password
      The encrypted password of the user.
    • enabled

      private boolean enabled
      Indicates whether the User's entity is enabled. Defaults to true.
    • accountNoExpired

      private boolean accountNoExpired
      Indicates whether the User's entity is not expired. Defaults to true.
    • accountNoLocked

      private boolean accountNoLocked
      Indicates whether the User's entity is not locked. Defaults to true.
    • credentialNoExpired

      private boolean credentialNoExpired
      Indicates whether the User's credentials are not expired. Defaults to true.
    • authorities

      private Collection<? extends org.springframework.security.core.GrantedAuthority> authorities
      The authorities granted to the user for authorization purposes.
    • attributes

      private Map<String,Object> attributes
      Additional attributes provided by an OAuth2 authentication provider.
  • Constructor Details

    • UserPrincipal

      public UserPrincipal(User user, Map<String,Object> attributes)
      Constructs a new UserPrincipal instance using a User entity. This constructor extracts relevant information from the User object and assigns it to the corresponding fields in UserPrincipal.
      Parameters:
      user - the User entity containing user details.
      attributes - additional attributes obtained from an OAuth2 authentication provider.
    • UserPrincipal

      public UserPrincipal(UUID userId, UUID profileId, UUID advertiserId, String username, String password, Collection<? extends org.springframework.security.core.GrantedAuthority> authoritiesList, Map<String,Object> attributes)
      Constructs a new UserPrincipal instance using a decoded JWT token values. This constructor extracts relevant information from the User object and assigns it to the corresponding fields in UserPrincipal.
      Parameters:
      userId - the UUID id of the User.
      profileId - the UUID id of the Profile.
      advertiserId - the UUID id of the Advertiser.
      username - the username of the User.
      password - the encoded password of the User.
      authoritiesList - the list of authorities of the User.
      attributes - additional attributes obtained from an OAuth2 authentication provider.
  • Method Details

    • getAttributes

      public Map<String,Object> getAttributes()
      Retrieves the attributes associated with the user from an OAuth2 provider.
      Specified by:
      getAttributes in interface org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal
      Returns:
      a map of user attributes.
    • getName

      public String getName()
      Retrieves the name of the user.
      Specified by:
      getName in interface org.springframework.security.core.AuthenticatedPrincipal
      Returns:
      the username of the user.
    • isAccountNonExpired

      public boolean isAccountNonExpired()
      Specified by:
      isAccountNonExpired in interface org.springframework.security.core.userdetails.UserDetails
    • isAccountNonLocked

      public boolean isAccountNonLocked()
      Specified by:
      isAccountNonLocked in interface org.springframework.security.core.userdetails.UserDetails
    • isCredentialsNonExpired

      public boolean isCredentialsNonExpired()
      Specified by:
      isCredentialsNonExpired in interface org.springframework.security.core.userdetails.UserDetails
    • isEnabled

      public boolean isEnabled()
      Specified by:
      isEnabled in interface org.springframework.security.core.userdetails.UserDetails
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public final boolean equals(Object o)
      Overrides:
      equals in class Object