Class MCRUser

java.lang.Object
org.mycore.user2.MCRUser
All Implemented Interfaces:
Serializable, Cloneable, MCRUserInformation
Direct Known Subclasses:
MCRTransientUser

@Entity public class MCRUser extends Object implements MCRUserInformation, Cloneable, Serializable
Represents a login user. Each user has a unique numerical ID. Each user belongs to a realm. The user name must be unique within a realm. Any changes made to an instance of this class does not persist automatically. Use MCRUserManager.updateUser(MCRUser) to achieve this.
Author:
Frank Lützenkirchen, Thomas Scheffler (yagee), René Adler (eagle)
See Also:
  • Constructor Details

    • MCRUser

      protected MCRUser()
    • MCRUser

      public MCRUser(String userName, MCRRealm mcrRealm)
      Creates a new user.
      Parameters:
      userName - the login user name
      mcrRealm - the realm this user belongs to
    • MCRUser

      public MCRUser(String userName, String realmID)
      Creates a new user.
      Parameters:
      userName - the login user name
      realmID - the ID of the realm this user belongs to
    • MCRUser

      public MCRUser(String userName)
      Creates a new user in the default realm.
      Parameters:
      userName - the login user name
  • Method Details

    • isLocked

      public boolean isLocked()
    • setLocked

      public void setLocked(Boolean locked)
    • isDisabled

      public boolean isDisabled()
      Returns:
      the disabled
    • setDisabled

      public void setDisabled(Boolean disabled)
      Parameters:
      disabled - the disabled to set
    • getUserName

      public String getUserName()
      Returns the login user name. The user name is unique within its realm.
      Returns:
      the login user name.
    • getRealm

      public MCRRealm getRealm()
      Returns the realm the user belongs to.
      Returns:
      the realm the user belongs to.
    • getRealmID

      public String getRealmID()
      Returns the ID of the realm the user belongs to.
      Returns:
      the ID of the realm the user belongs to.
    • getPassword

      public String getPassword()
      Returns:
      the hash
    • setPassword

      public void setPassword(String password)
      Parameters:
      password - the hash value to set
    • getSalt

      public String getSalt()
      Returns:
      the salt
    • setSalt

      public void setSalt(String salt)
      Parameters:
      salt - the salt to set
    • getHashType

      public MCRPasswordHashType getHashType()
      Returns:
      the hashType
    • setHashType

      public void setHashType(MCRPasswordHashType hashType)
      Parameters:
      hashType - the hashType to set
    • getOwner

      public MCRUser getOwner()
      Returns the user that owns this user, or null if the user is independent and has no owner.
      Returns:
      the user that owns this user.
    • setOwner

      public void setOwner(MCRUser owner)
      Sets the user that owns this user. Setting this to null makes the user independent.
      Parameters:
      owner - the owner of the user.
    • hasNoOwner

      public boolean hasNoOwner()
      Returns true if this user has no owner and therefore is independent. Independent users may change their passwords etc., owned users may not, they are created to limit read access in general.
      Returns:
      true if this user has no owner
    • getRealName

      public String getRealName()
      Returns the name of the person this login user represents.
      Returns:
      the name of the person this login user represents.
    • setRealName

      public void setRealName(String realName)
      Sets the name of the person this login user represents.
      Parameters:
      realName - the name of the person this login user represents.
    • getEMailAddress

      public String getEMailAddress()
      Returns the E-Mail address of the person this login user represents.
      Returns:
      the E-Mail address of the person this login user represents.
    • setEMail

      public void setEMail(String eMail)
      Sets the E-Mail address of the person this user represents.
      Parameters:
      eMail - the E-Mail address
    • getHint

      public String getHint()
      Returns a hint the user has stored in case of forgotten hash.
      Returns:
      a hint the user has stored in case of forgotten hash.
    • setHint

      public void setHint(String hint)
      Sets a hint to store in case of hash loss.
      Parameters:
      hint - a hint for the user in case hash is forgotten.
    • getLastLogin

      public Date getLastLogin()
      Returns the last time the user has logged in.
      Returns:
      the last time the user has logged in.
    • setLastLogin

      public void setLastLogin(Date lastLogin)
      Sets the time of last login.
      Parameters:
      lastLogin - the last time the user logged in.
    • setLastLogin

      public void setLastLogin()
      Sets the time of last login to now.
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getUserID

      public String getUserID()
      Description copied from interface: MCRUserInformation
      The UserID is the information that is used in user clauses of the ACL System.
      Specified by:
      getUserID in interface MCRUserInformation
    • getUserAttribute

      public String getUserAttribute(String attribute)
      Returns additional user attributes. This methods handles MCRUserInformation.ATT_REAL_NAME and all attributes defined in getAttributes().
      Specified by:
      getUserAttribute in interface MCRUserInformation
      Parameters:
      attribute - user attribute name
      Returns:
      attribute value as String or null if no value is defined;
    • isUserInRole

      public boolean isUserInRole(String role)
      Description copied from interface: MCRUserInformation
      The role information is used in group clauses of the ACL System.
      Specified by:
      isUserInRole in interface MCRUserInformation
    • setAttributes

      public void setAttributes(SortedSet<MCRUserAttribute> attributes)
      Parameters:
      attributes - the attributes to set
    • getAttributes

      public SortedSet<MCRUserAttribute> getAttributes()
    • getSystemRoleIDs

      public Collection<String> getSystemRoleIDs()
      Returns a collection any system role ID this user is member of.
      See Also:
    • getExternalRoleIDs

      public Collection<String> getExternalRoleIDs()
      Returns a collection any external role ID this user is member of.
      See Also:
    • assignRole

      public void assignRole(String roleName)
      Adds this user to the given role.
      Parameters:
      roleName - the role the user should be added to (must already exist)
    • unassignRole

      public void unassignRole(String roleName)
      Removes this user from the given role.
      Parameters:
      roleName - the role the user should be removed from (must already exist)
    • enableLogin

      public void enableLogin()
      Enable login for this user.
    • disableLogin

      public void disableLogin()
      Disable login for this user.
    • loginAllowed

      public boolean loginAllowed()
      Returns true if logins are allowed for this user.
    • getValidUntil

      public Date getValidUntil()
      Returns a Date when this user can not login anymore.
    • setValidUntil

      public void setValidUntil(Date validUntil)
      Sets a Date when this user can not login anymore.
      Parameters:
      validUntil - the validUntil to set
    • setUserAttribute

      public void setUserAttribute(String name, String value)
    • clone

      public MCRUser clone()
      Overrides:
      clone in class Object
    • getBasicCopy

      public MCRUser getBasicCopy()
      Returns this MCRUser with basic information. Same as getSafeCopy() but without these informations:
      • real name
      • eMail
      • attributes
      • role information
      • last login
      • valid until
      • password hint
      Returns:
      a clone copy of this instance
    • getSafeCopy

      public MCRUser getSafeCopy()
      Returns this MCRUser with safe information. Same as clone() but without these informations:
      • password hash type
      • password hash value
      • password salt
      Returns:
      a clone copy of this instance