Record Class User

java.lang.Object
java.lang.Record
net.tangly.core.domain.User
Record Components:
username - username is the identifier of the user in the context of a tenant
passwordHash - password hash is the encrypted password of the user
active - true if the user is active and can log in the application
naturalPersonId - optional identifier of the natural person associated with the user
accessRights - list of access rights for the user on the different domains of the application
gravatarEmail - email address used to retrieve the avatar of the user through the gravatar service

public record User(@NotNull String username, @NotNull String passwordHash, @NotNull String passwordSalt, boolean active, String naturalPersonId, @NotNull List<AccessRights> accessRights, String gravatarEmail) extends Record
An application user can log in the application and access to domain data based on domain access rights. A user is defined in the context of a tenant.
  • Constructor Details

    • User

      public User(@NotNull @NotNull String username, @NotNull @NotNull String passwordHash, @NotNull @NotNull String passwordSalt, boolean active, String naturalPersonId, @NotNull @NotNull List<AccessRights> accessRights, String gravatarEmail)
      Creates an instance of a User record class.
      Parameters:
      username - the value for the username record component
      passwordHash - the value for the passwordHash record component
      passwordSalt - the value for the passwordSalt record component
      active - the value for the active record component
      naturalPersonId - the value for the naturalPersonId record component
      accessRights - the value for the accessRights record component
      gravatarEmail - the value for the gravatarEmail record component
  • Method Details

    • encryptPassword

      public static String encryptPassword(@NotNull @NotNull String password, @NotNull @NotNull String salt)
      Encrypts the password of a user using a salt.
      Parameters:
      password - password to encrypt
      salt - salt used to encrypt the password
      Returns:
      encrypted password
    • newSalt

      public static String newSalt()
      Generates a new salt value with a JDK provided random generator.
      Returns:
      new salt value
    • avatar

      public static byte[] avatar(@NotNull @NotNull String gravatarEmail)
      Returns the avatar of a user based on the email address of the user.
      Parameters:
      gravatarEmail - email address of the user registered in the gravatar service
      Returns:
      avatar picture of the user
    • accessRightsFor

      public Optional<AccessRights> accessRightsFor(@NotNull @NotNull String domain)
      Returns the access rights of a user for a specific domain.
      Parameters:
      domain - domain for which the access rights are requested
      Returns:
      access rights of the user for the domain
    • hasAdminRightsFor

      public boolean hasAdminRightsFor(@NotNull @NotNull String domain)
    • authenticate

      public boolean authenticate(@NotNull @NotNull String password)
      Authenticates the user based on the password provided.
      Parameters:
      password - password to authenticate the user
      Returns:
      true if the password is correct
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • username

      @NotNull public @NotNull String username()
      Returns the value of the username record component.
      Returns:
      the value of the username record component
    • passwordHash

      @NotNull public @NotNull String passwordHash()
      Returns the value of the passwordHash record component.
      Returns:
      the value of the passwordHash record component
    • passwordSalt

      @NotNull public @NotNull String passwordSalt()
      Returns the value of the passwordSalt record component.
      Returns:
      the value of the passwordSalt record component
    • active

      public boolean active()
      Returns the value of the active record component.
      Returns:
      the value of the active record component
    • naturalPersonId

      public String naturalPersonId()
      Returns the value of the naturalPersonId record component.
      Returns:
      the value of the naturalPersonId record component
    • accessRights

      @NotNull public @NotNull List<AccessRights> accessRights()
      Returns the value of the accessRights record component.
      Returns:
      the value of the accessRights record component
    • gravatarEmail

      public String gravatarEmail()
      Returns the value of the gravatarEmail record component.
      Returns:
      the value of the gravatarEmail record component