Class User

java.lang.Object
com.alpaca.entity.User

@Entity public class User extends Object
Represents a User entity in the system. This entity is mapped to the "users" table in the database and stores authentication and authorization details. It includes information about roles, entity status, and authentication settings.
  • 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 Advertiser
    The Advertiser entity associated with the User.
    private boolean
    Indicates whether the User's credentials are not expired.
    private String
    The User's email address.
    private boolean
    Indicates whether the User's email has been verified.
    private boolean
    Indicates whether the User's entity is enabled.
    private boolean
    Indicates whether the User has connected their account to Google.
    private UUID
    Unique identifier for the User.
    private String
    The User's encrypted password.
    private Profile
    The Profile entity associated with the User.
    private Set<UserRole>
    Indicates the set of Role has the User.
  • Constructor Summary

    Constructors
    Constructor
    Description
    User(String email, String password, boolean enabled, boolean accountNoExpired, boolean accountNoLocked, boolean credentialNoExpired, boolean emailVerified, boolean googleConnected, Set<Role> roles)
    Constructs an instance of a new User object with the specified attributes.
    User(String email, String password, Set<Role> roles)
    Constructs an instance of a new User object with the specified attributes.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
     
    Set<org.springframework.security.core.authority.SimpleGrantedAuthority>
    Retrieves the authorities granted to the User based on their assigned roles.
    Retrieves the list of roles assigned to the User.
    int
     
    boolean
    Determines whether the user account is allowed to be used based on its status.
    private Set<UserRole>
    Converts a set of Role objects into a set of UserRole objects associated with the current User.
    void
     

    Methods inherited from class java.lang.Object

    clone, getClass, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • id

      private UUID id
      Unique identifier for the User. This value is automatically generated using a UUID strategy.
    • email

      private String email
      The User's email address. This field is unique and cannot be null.
    • password

      private String password
      The User's encrypted password. This field cannot be null.
    • 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.
    • emailVerified

      private boolean emailVerified
      Indicates whether the User's email has been verified. Defaults to false.
    • googleConnected

      private boolean googleConnected
      Indicates whether the User has connected their account to Google. Defaults to false.
    • userRoles

      private Set<UserRole> userRoles
      Indicates the set of Role has the User.

      A User has a many-to-many relationship with an Role through UserRole

    • profile

      private Profile profile
      The Profile entity associated with the User.

      A User has a one-to-one relationship with a Profile.

    • advertiser

      private Advertiser advertiser
      The Advertiser entity associated with the User.

      A User has a one-to-one relationship with an Advertiser.

  • Constructor Details

    • User

      public User(String email, String password, Set<Role> roles)
      Constructs an instance of a new User object with the specified attributes. The generated object is ready to be used by default.
      Parameters:
      email - the User's email - must not be null
      password - the User's encrypted password - must not be null
      roles - Set of Roles assigned to the User
    • User

      public User(String email, String password, boolean enabled, boolean accountNoExpired, boolean accountNoLocked, boolean credentialNoExpired, boolean emailVerified, boolean googleConnected, Set<Role> roles)
      Constructs an instance of a new User object with the specified attributes. The generated object is ready to be used and stored in the database.
      Parameters:
      email - the User's email - must not be null
      password - the User's encrypted password - must not be null
      enabled - indicates whether the entity is enabled
      accountNoExpired - indicates whether the entity is not expired
      accountNoLocked - indicates whether the entity is not locked
      credentialNoExpired - indicates whether the credentials are not expired
      emailVerified - indicates whether the email has been verified
      googleConnected - indicates whether the User has connected with Google
      roles - Set of Roles assigned to the User
  • Method Details

    • setUserRoles

      public void setUserRoles(Collection<Role> roles)
    • rolesToUserRoles

      private Set<UserRole> rolesToUserRoles(Collection<Role> roles)
      Converts a set of Role objects into a set of UserRole objects associated with the current User.
      Parameters:
      roles - the set of Role objects to be converted.
      Returns:
      a set of UserRole objects associated with the User.
    • getRoles

      public List<Role> getRoles()
      Retrieves the list of roles assigned to the User.
      Returns:
      a List of Role objects representing the User's roles.
    • getAuthorities

      public Set<org.springframework.security.core.authority.SimpleGrantedAuthority> getAuthorities()
      Retrieves the authorities granted to the User based on their assigned roles. Each role is prefixed with "ROLE_" as per Spring Security conventions.
      Returns:
      Set of SimpleGrantedAuthority representing the User's permissions.
    • isAllowUser

      public boolean isAllowUser()
      Determines whether the user account is allowed to be used based on its status.

      This method checks multiple conditions to determine if the account is active and can be used for authentication. A user account is considered allowed if:

      • The account is enabled.
      • The account is not expired.
      • The account is not locked.
      • The credentials are not expired.
      Returns:
      true if the account meets all the conditions to be considered active; false otherwise.
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object