Class User

java.lang.Object
org.ameba.integration.jpa.BaseEntity
org.ameba.integration.jpa.ApplicationEntity
org.openwms.core.uaa.impl.User
All Implemented Interfaces:
Serializable, org.ameba.integration.TypedEntity<Long>
Direct Known Subclasses:
SystemUser

@Entity public class User extends org.ameba.integration.jpa.ApplicationEntity implements Serializable
An User represents a human user of the system. Typically an User is assigned to one or more Roles to define security constraints. Users can have their own configuration settings in form of UserPreferences and certain user details, encapsulated in an UserDetails object that tend to be extended by projects.
Author:
Heiko Scherrer
See Also:
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • username

      @NotEmpty private @NotEmpty String username
      Unique identifier of this User (not nullable).
    • extern

      private boolean extern
      true if the User is authenticated by an external system, otherwise false.
    • lastPasswordChange

      private ZonedDateTime lastPasswordChange
      Date of the last password change.
    • locked

      private boolean locked
      true if this User is locked and has no permission to login.
    • password

      private String password
      The User's current password (only kept transient).
    • persistedPassword

      private String persistedPassword
      The User's current password.
    • enabled

      private boolean enabled
      true if the User is enabled. This field can be managed by the UI application to lock the User manually.
    • expirationDate

      private ZonedDateTime expirationDate
      Date when the account expires. After account expiration, the User cannot login anymore.
    • fullname

      private String fullname
      The User's fullname (doesn't have to be unique).
    • emailAddresses

      private Set<Email> emailAddresses
      Email addresses.
    • userDetails

      private UserDetails userDetails
      More detail information of the User.
    • roles

      private List<Role> roles
      List of Roles assigned to the User.
    • passwords

      private List<UserPassword> passwords
      Last passwords of the User.
    • NUMBER_STORED_PASSWORDS

      public static final short NUMBER_STORED_PASSWORDS
      The number of passwords to keep in the password history. Default: 3.
      See Also:
  • Constructor Details

    • User

      protected User()
      Dear JPA...
    • User

      public User(String username)
      Create a new User with an username.
      Parameters:
      username - The unique name of the user
      Throws:
      IllegalArgumentException - when username is null or empty
    • User

      protected User(String username, String password)
      Create a new User with a username.
      Parameters:
      username - The unique name of the user
      password - The password of the user
      Throws:
      IllegalArgumentException - when username or password is null or empty
  • Method Details

    • postLoad

      public void postLoad()
      After load, the saved password is copied to the transient one. The transient one can be overridden by the application to force a password change.
    • loadLazy

      protected void loadLazy()
    • setPersistentKey

      public void setPersistentKey(String pKey)
      Overrides:
      setPersistentKey in class org.ameba.integration.jpa.ApplicationEntity
    • setOl

      public void setOl(long ol)
      Overrides:
      setOl in class org.ameba.integration.jpa.BaseEntity
    • wipePassword

      public void wipePassword()
      Set the password and persistedPassword to null.
    • addNewEmailAddress

      public boolean addNewEmailAddress(Email email)
    • removeEmailAddress

      public boolean removeEmailAddress(Email email)
    • getUsername

      public String getUsername()
      Return the unique username of the User.
      Returns:
      The current username
    • setUsername

      public void setUsername(String username)
      Change the username of the User.
      Parameters:
      username - The new username to set
    • isExternalUser

      public boolean isExternalUser()
      Is the User authenticated by an external system?
      Returns:
      true if so, otherwise false
    • setExternalUser

      public void setExternalUser(boolean externalUser)
      Change the authentication method of the User.
      Parameters:
      externalUser - true if the User was authenticated by an external system, otherwise false.
    • getLastPasswordChange

      public ZonedDateTime getLastPasswordChange()
      Return the date when the password has been changed the last time.
      Returns:
      The date when the password has been changed the last time
    • setLastPasswordChange

      public void setLastPasswordChange(ZonedDateTime lastPasswordChange)
      Set the date when the password has been changed the last time.
      Parameters:
      lastPasswordChange - The date when the password has been changed the last time
    • supplyLastPasswordChange

      public User supplyLastPasswordChange(Consumer<ZonedDateTime> c)
      Supply lastPasswordChange to the consumer c if present.
      Parameters:
      c - The consumer
      Returns:
      This instance
    • isLocked

      public boolean isLocked()
      Check if the User is locked.
      Returns:
      true if locked, otherwise false
    • setLocked

      public void setLocked(boolean locked)
      Lock the User.
      Parameters:
      locked - true to lock the User, false to unlock
    • getPassword

      public String getPassword()
      Returns the current password of the User.
      Returns:
      The current password as String
    • changePassword

      public void changePassword(String encodedPassword, String rawPassword, org.springframework.security.crypto.password.PasswordEncoder encoder) throws InvalidPasswordException
      Checks if the new password is a valid and change the password of this User.
      Parameters:
      encodedPassword - The new encoded password of this User
      Throws:
      InvalidPasswordException - in case changing the password is not allowed or the new password is not valid
    • hasPasswordChanged

      public boolean hasPasswordChanged()
      Checks whether the password is going to change.
      Returns:
      true when password is different to the originally persisted one, otherwise false
    • validateAgainstPasswordHistory

      protected void validateAgainstPasswordHistory(String rawPassword, org.springframework.security.crypto.password.PasswordEncoder encoder) throws InvalidPasswordException
      Check whether the new password is in the history of former passwords.
      Parameters:
      rawPassword - The password to verify
      Throws:
      InvalidPasswordException
    • storeOldPassword

      private void storeOldPassword(String oldPassword)
    • isEnabled

      public boolean isEnabled()
      Determines whether the User is enabled or not.
      Returns:
      true if the User is enabled, otherwise false
    • setEnabled

      public void setEnabled(boolean enabled)
      Enable or disable the User.
      Parameters:
      enabled - true when enabled, otherwise false
    • getExpirationDate

      public ZonedDateTime getExpirationDate()
      Return the date when the account expires.
      Returns:
      The expiration date
    • setExpirationDate

      public void setExpirationDate(ZonedDateTime expDate)
      Change the date when the account expires.
      Parameters:
      expDate - The new expiration date to set
    • getRoles

      public List<Role> getRoles()
      Returns a list of granted Roles.
      Returns:
      The list of granted Roles
    • supplyRoles

      public User supplyRoles(Consumer<List<Role>> c)
      Supply roles to the consumer c if present.
      Parameters:
      c - The consumer
      Returns:
      This instance
    • getGrants

      public List<SecurityObject> getGrants()
      Flatten Roles and Grants and return a List of all Grants assigned to this User.
      Returns:
      A list of all Grants
    • supplyGrants

      public User supplyGrants(Consumer<List<SecurityObject>> c)
      Supply grants to the consumer c if present.
      Parameters:
      c - The consumer
      Returns:
      This instance
    • addRole

      public boolean addRole(Role role)
      Add a new Role to the list of Roles.
      Parameters:
      role - The new Role to add
      Returns:
      see Collection.add(Object)
    • setRoles

      public void setRoles(List<Role> roles)
      Set the Roles of this User. Existing Roles will be overridden.
      Parameters:
      roles - The new list of Roles
    • getFullname

      public String getFullname()
      Return the fullname of the User.
      Returns:
      The current fullname
    • setFullname

      public void setFullname(String fullname)
      Change the fullname of the User.
      Parameters:
      fullname - The new fullname to set
    • setFullname

      public User setFullname(Consumer<String> c)
    • getEmailAddressesInternal

      private Set<Email> getEmailAddressesInternal()
    • getEmailAddresses

      public Set<Email> getEmailAddresses()
    • setEmailAddresses

      public void setEmailAddresses(Set<Email> emailAddresses)
    • getPrimaryEmailAddress

      public Optional<Email> getPrimaryEmailAddress()
    • supplyPrimaryEmailAddress

      public User supplyPrimaryEmailAddress(Consumer<Email> c)
      Supply the primary email to the consumer c if present.
      Parameters:
      c - The consumer
      Returns:
      This instance
    • getPasswords

      public List<UserPassword> getPasswords()
      Return a list of recently used passwords.
      Returns:
      A list of recently used passwords
    • getUserDetails

      public UserDetails getUserDetails()
      Return the details of the User.
      Returns:
      The userDetails
    • supplyUserDetails

      public User supplyUserDetails(Consumer<UserDetails> c)
      Supply userDetails to the consumer c if present.
      Parameters:
      c - The consumer
      Returns:
      This instance
    • hasUserDetails

      public boolean hasUserDetails()
      Check whether this User has UserDetails set.
      Returns:
      true if set, otherwise false
    • setUserDetails

      public void setUserDetails(UserDetails userDetails)
      Assign some details to the User.
      Parameters:
      userDetails - The userDetails to set
    • hashCode

      public int hashCode()

      Does not call the superclass. Uses the username for calculation.

      Overrides:
      hashCode in class org.ameba.integration.jpa.ApplicationEntity
      See Also:
    • equals

      public boolean equals(Object obj)

      Uses the username for comparison.

      Overrides:
      equals in class org.ameba.integration.jpa.ApplicationEntity
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object