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 Link icon

    • LOGGER Link icon

      private static final org.slf4j.Logger LOGGER
    • username Link icon

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

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

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

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

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

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

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

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

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

      private Set<Email> emailAddresses
      Email addresses.
    • userDetails Link icon

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

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

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

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

    • User Link icon

      protected User()
      Dear JPA...
    • User Link icon

      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 Link icon

      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 Link icon

    • postLoad Link icon

      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 Link icon

      protected void loadLazy()
    • setPersistentKey Link icon

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

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

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

      public boolean addNewEmailAddress(Email email)
    • removeEmailAddress Link icon

      public boolean removeEmailAddress(Email email)
    • getUsername Link icon

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

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

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

      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 Link icon

      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 Link icon

      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 Link icon

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

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

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

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

      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 Link icon

      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 Link icon

      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 Link icon

      private void storeOldPassword(String oldPassword)
    • isEnabled Link icon

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

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

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

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

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

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

      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 Link icon

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

      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 Link icon

      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 Link icon

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

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

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

      private Set<Email> getEmailAddressesInternal()
    • getEmailAddresses Link icon

      public Set<Email> getEmailAddresses()
    • setEmailAddresses Link icon

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

      public Optional<Email> getPrimaryEmailAddress()
    • supplyPrimaryEmailAddress Link icon

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

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

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

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

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

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

      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 Link icon

      public boolean equals(Object obj)

      Uses the username for comparison.

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

      public String toString()
      Overrides:
      toString in class Object