org.openwms.core.domain.system.usermanagement
Class User

java.lang.Object
  extended by org.openwms.core.domain.AbstractEntity
      extended by org.openwms.core.domain.system.usermanagement.User
All Implemented Interfaces:
Serializable, DomainObject<Long>
Direct Known Subclasses:
SystemUser

public class User
extends AbstractEntity
implements DomainObject<Long>

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.

Since:
0.1
Version:
$Revision: 1595 $
Author:
Heiko Scherrer
See Also:
UserDetails, UserPreference, UserPassword, Role, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.openwms.core.domain.AbstractEntity
AbstractEntity.AbstractEntityListener
 
Field Summary
static String NQ_FIND_ALL
          Query to find all Users.
static String NQ_FIND_ALL_ORDERED
          Query to find all Users sorted by userName.
static String NQ_FIND_BY_USERNAME
          Query to find one User by his userName.
static String NQ_FIND_BY_USERNAME_PASSWORD
          Query to find one User by his userName and password.
static short NUMBER_STORED_PASSWORDS
          The number of passwords to be stored in the password history.
 
Fields inherited from class org.openwms.core.domain.AbstractEntity
FIND_ALL, FIND_BY_ID
 
Constructor Summary
protected User()
          Accessed by persistence provider.
  User(String username)
          Create a new User with an username.
protected User(String username, String password)
          Create a new User with an username.
 
Method Summary
 boolean addRole(Role role)
          Add a new Role to the list of Roles.
 void changePassword(String password)
          Checks if the new password is a valid and change the password of this User.
 boolean equals(Object obj)
           Compare the uid property field.
 Date getExpirationDate()
          Return the date when the account expires.
 String getFullname()
          Return the fullname of the User.
 List<SecurityObject> getGrants()
          Flatten Roles and Grants and return an unmodifiable list of all Grants assigned to this User.
 Long getId()
          Return the technical key value.
 Date getLastPasswordChange()
          Return the date when the password has changed recently.
 String getPassword()
          Returns the current password of the User.
 List<UserPassword> getPasswords()
          Return a list of recently used passwords.
 Set<UserPreference> getPreferences()
          Get all UserPreferences of this User.
 List<Role> getRoles()
          Returns a list of granted Roles.
 UserDetails getUserDetails()
          Return the details of the User.
 String getUsername()
          Return the unique username of the User.
 long getVersion()
          Return the value of the optimistic locking field.
 int hashCode()
           Use the uid to calculate the hashCode.
 boolean hasPasswordChanged()
          Checks whether the password is going to be changed from the application side.
 boolean isEnabled()
          Determines whether the User is enabled or not.
 boolean isExternalUser()
          Is the User authenticated by an external system?
 boolean isLocked()
          Check if the User is locked.
 boolean isNew()
          Check whether the instance is a transient or persisted one.
protected  boolean isPasswordValid(String pwd)
          Check whether the new password is in the history of former passwords.
 void onLoad()
          After load, the saved password is copied to the transient one.
 void setEnabled(boolean enabled)
          Enable or disable the User.
 void setExpirationDate(Date expirationDate)
          Change the date when the account expires.
 void setExternalUser(boolean externalUser)
          Change the authentication method of the User.
 void setFullname(String fullname)
          Change the fullname of the User.
 void setLocked(boolean locked)
          Lock the User.
 void setPassword(String password)
          Set the password that shall be stored as new password.
 void setPreferences(Set<UserPreference> preferences)
          Set all UserPreferences of the User.
 void setRoles(List<Role> roles)
          Set the Roles of this User.
 void setUserDetails(UserDetails userDetails)
          Assign some details to the User.
protected  void setUsername(String username)
          Change the username of the User.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NQ_FIND_ALL

public static final String NQ_FIND_ALL
Query to find all Users. Name is "User.findAll" .

See Also:
Constant Field Values

NQ_FIND_ALL_ORDERED

public static final String NQ_FIND_ALL_ORDERED
Query to find all Users sorted by userName. Name is "User.findAllOrdered" .

See Also:
Constant Field Values

NQ_FIND_BY_USERNAME

public static final String NQ_FIND_BY_USERNAME
Query to find one User by his userName.
  • Query parameter index 1 : The userName of the User to search for.

  • Name is "User.findByUsername" .

    See Also:
    Constant Field Values

    NQ_FIND_BY_USERNAME_PASSWORD

    public static final String NQ_FIND_BY_USERNAME_PASSWORD
    Query to find one User by his userName and password.
  • Query parameter name username : The userName of the User to search for.
  • Query parameter name password : The current password of the User to search for.

  • Name is "User.findByUsernameAndPassword" .

    See Also:
    Constant Field Values

    NUMBER_STORED_PASSWORDS

    public static final short NUMBER_STORED_PASSWORDS
    The number of passwords to be stored in the password history. When an User changes the password, the old password is stored in a Collection. Default: 3 .

    See Also:
    Constant Field Values
    Constructor Detail

    User

    protected User()
    Accessed by persistence provider.


    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 an 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 Detail

    getId

    public Long getId()
    Return the technical key value.

    Specified by:
    getId in interface DomainObject<Long>
    Returns:
    The technical, unique key

    isNew

    public boolean isNew()
    Check whether the instance is a transient or persisted one.

    Specified by:
    isNew in interface DomainObject<Long>
    Returns:
    true if transient (not persisted before), otherwise false

    onLoad

    public void onLoad()
    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.


    getUsername

    public String getUsername()
    Return the unique username of the User.

    Returns:
    The current username

    setUsername

    protected 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 Date getLastPasswordChange()
    Return the date when the password has changed recently.

    Returns:
    The date when the password has changed recently

    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

    setPassword

    public void setPassword(String password)
    Set the password that shall be stored as new password. Note, that this password is not directly saved.

    Parameters:
    password - The password to change to

    changePassword

    public void changePassword(String password)
                        throws InvalidPasswordException
    Checks if the new password is a valid and change the password of this User.

    Parameters:
    password - The new 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 be changed from the application side.

    Returns:
    true when the password is different to the saved one, otherwise false

    isPasswordValid

    protected boolean isPasswordValid(String pwd)
    Check whether the new password is in the history of former passwords.

    Parameters:
    pwd - The password to verify
    Returns:
    true if the password is valid, otherwise false

    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 Date getExpirationDate()
    Return the date when the account expires.

    Returns:
    The expiration date

    setExpirationDate

    public void setExpirationDate(Date expirationDate)
    Change the date when the account expires.

    Parameters:
    expirationDate - The new expiration date to set

    getRoles

    public List<Role> getRoles()
    Returns a list of granted Roles.

    Returns:
    The list of granted Roles

    getGrants

    public List<SecurityObject> getGrants()
    Flatten Roles and Grants and return an unmodifiable list of all Grants assigned to this User.

    Returns:
    A list of all Grants

    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

    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

    setUserDetails

    public void setUserDetails(UserDetails userDetails)
    Assign some details to the User.

    Parameters:
    userDetails - The userDetails to set

    getPreferences

    public Set<UserPreference> getPreferences()
    Get all UserPreferences of this User.

    Returns:
    A set of all UserPreferences

    setPreferences

    public void setPreferences(Set<UserPreference> preferences)
    Set all UserPreferences of the User. Already existing UserPreferences will be overridden.

    Parameters:
    preferences - A set of UserPreferences to set

    getVersion

    public long getVersion()
    Return the value of the optimistic locking field.

    Specified by:
    getVersion in interface DomainObject<Long>
    Returns:
    the version number

    hashCode

    public int hashCode()
    Use the uid to calculate the hashCode. Does not call the superclass. Uses the username for calculation.

    Overrides:
    hashCode in class AbstractEntity
    See Also:
    Object.hashCode()

    equals

    public boolean equals(Object obj)
    Compare the uid property field. Uses the username for comparison.

    Overrides:
    equals in class AbstractEntity
    See Also:
    Object.equals(java.lang.Object)


    Copyright © 2005-2011 openwms.org. All Rights Reserved.