Class CmsUser

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<I_CmsPrincipal>, java.security.Principal, I_CmsPrincipal

    public class CmsUser
    extends CmsPrincipal
    implements java.lang.Cloneable
    A user principal in the OpenCms permission system.

    A user in OpenCms is uniquely defined by its user named returned by CmsPrincipal.getName().

    Basic users in OpenCms are users that can access the OpenCms Workplace. Moreover, the user must be created by another user with the CmsRole.ACCOUNT_MANAGER role. These users are "content managers" that actually have write permissions in at last some parts of the VFS.

    Another possibility is to have users in a 'Guests' group. These users do not have access to the OpenCms Workplace. However, an user in a 'Guests' group can be created by every user, for example the "Guest" user. The main use case is that these users are used for users of the website that can generate their own accounts, in a "please register your account..." scenario. These user accounts can then be used to build personalized web sites.

    Since:
    6.0.0
    See Also:
    CmsGroup, Serialized Form
    • Constructor Detail

      • CmsUser

        public CmsUser()
        Creates a new, empty OpenCms user principal.

        Mostly intended to be used with the org.opencms.workplace.tools.accounts.A_CmsEditUserDialog.

      • CmsUser

        public CmsUser​(CmsUUID id,
                       java.lang.String name,
                       java.lang.String password,
                       java.lang.String firstname,
                       java.lang.String lastname,
                       java.lang.String email,
                       long lastlogin,
                       int flags,
                       long dateCreated,
                       java.util.Map<java.lang.String,​java.lang.Object> additionalInfo)
        Creates a new OpenCms user principal.

        Parameters:
        id - the unique id of the new user
        name - the fully qualified name of the new user
        password - the password of the user
        firstname - the first name
        lastname - the last name
        email - the email address
        lastlogin - time stamp
        flags - flags
        dateCreated - the creation date
        additionalInfo - user related information
    • Method Detail

      • checkEmail

        public static void checkEmail​(java.lang.String email)
        Validates an email address.

        That means, the parameter should only be composed by digits and standard english letters, points, underscores and exact one "At" symbol.

        Parameters:
        email - the email to validate
      • checkZipCode

        public static void checkZipCode​(java.lang.String zipcode)
        Validates a zip code.

        That means, the parameter should only be composed by digits and standard english letters.

        Parameters:
        zipcode - the zip code to validate
      • getFullName

        public static java.lang.String getFullName​(CmsUser user)
        Returns the "full" name of the given user in the format "{firstname} {lastname} ({username})", or the empty String "" if the user is null.

        Parameters:
        user - the user to get the full name from
        Returns:
        the "full" name the user
        See Also:
        getFullName()
      • hasChangedAdditionalInfos

        public static boolean hasChangedAdditionalInfos​(int changes)
        Checks whether the flag indicates additional info changes.

        Parameters:
        changes - the changes flags
        Returns:
        true in case the additional infos changed
      • hasChangedCoreData

        public static boolean hasChangedCoreData​(int changes)
        Checks whether the flag indicates core data changes.

        Parameters:
        changes - the changes flags
        Returns:
        true in case the core data changed
      • hasChangedLastLogin

        public static boolean hasChangedLastLogin​(int changes)
        Checks whether the flag indicates last login date changes.

        Parameters:
        changes - the changes flags
        Returns:
        true in case the last login date changed
      • hasPrefix

        public static boolean hasPrefix​(java.lang.String principalName)
        Checks if the given String starts with I_CmsPrincipal.PRINCIPAL_USER followed by a dot.

        • Works if the given String is null.
        • Removes white spaces around the String before the check.
        • Also works with prefixes not being in upper case.
        • Does not check if the user after the prefix actually exists.
        Parameters:
        principalName - the user name to check
        Returns:
        true in case the String starts with I_CmsPrincipal.PRINCIPAL_USER followed by a dot
      • removePrefix

        public static java.lang.String removePrefix​(java.lang.String principalName)
        Removes the prefix if the given String starts with I_CmsPrincipal.PRINCIPAL_USER followed by a dot.

        • Works if the given String is null.
        • If the given String does not start with I_CmsPrincipal.PRINCIPAL_USER followed by a dot it is returned unchanged.
        • Removes white spaces around the user name.
        • Also works with prefixes not being in upper case.
        • Does not check if the user after the prefix actually exists.
        Parameters:
        principalName - the user name to remove the prefix from
        Returns:
        the given String with the prefix I_CmsPrincipal.PRINCIPAL_USER and the following dot removed
      • clone

        public CmsUser clone()
        Overrides:
        clone in class java.lang.Object
        See Also:
        Object.clone()
      • deleteAdditionalInfo

        public void deleteAdditionalInfo​(java.lang.String key)
        Deletes a value from this users "additional information" storage map.

        Parameters:
        key - the additional user information to delete
        See Also:
        getAdditionalInfo()
      • getAdditionalInfo

        public java.util.Map<java.lang.String,​java.lang.Object> getAdditionalInfo()
        Returns this users complete "additional information" storage map.

        The "additional information" storage map is a simple Map that can be used to store any key / value pairs for the user. Some information parts of the users address are stored in this map by default.

        Returns:
        this users complete "additional information" storage map
      • getAdditionalInfo

        public java.lang.Object getAdditionalInfo​(java.lang.String key)
        Returns a value from this users "additional information" storage map, or null if no value for the given key is available.

        Parameters:
        key - selects the value to return from the "additional information" storage map
        Returns:
        the selected value from this users "additional information" storage map
        See Also:
        getAdditionalInfo()
      • getAddress

        public java.lang.String getAddress()
        Returns the address line of this user.

        Returns:
        the address line of this user
      • getChanges

        public int getChanges​(CmsUser oldUser)
        Returns the changes of this user compared to the previous user data.

        Parameters:
        oldUser - the old user
        Returns:
        the changes flags
      • getCity

        public java.lang.String getCity()
        Returns the city information of this user.

        This information is stored in the "additional information" storage map using the key CmsUserSettings.ADDITIONAL_INFO_CITY.

        Returns:
        the city information of this user
      • getCountry

        public java.lang.String getCountry()
        Returns the country information of this user.

        This information is stored in the "additional information" storage map using the key CmsUserSettings.ADDITIONAL_INFO_COUNTRY.

        Returns:
        the country information of this user
      • getDateCreated

        public long getDateCreated()
        Returns the creation date.

        Returns:
        the creation date
      • getDescription

        public java.lang.String getDescription​(java.util.Locale locale)
        Returns the description of this organizational unit.

        Specified by:
        getDescription in interface I_CmsPrincipal
        Parameters:
        locale - the locale
        Returns:
        the description of this organizational unit
      • getEmail

        public java.lang.String getEmail()
        Returns the email address of this user.

        Returns:
        the email address of this user
      • getFirstname

        public java.lang.String getFirstname()
        Returns the first name of this user.

        Returns:
        the first name of this user
      • getFullName

        public java.lang.String getFullName()
        Returns the "full" name of the this user in the format "{firstname} {lastname} ({username})".

        Returns:
        the "full" name this user
      • getInstitution

        public java.lang.String getInstitution()
        Returns the institution information of this user.

        This information is stored in the "additional information" storage map using the key CmsUserSettings.ADDITIONAL_INFO_INSTITUTION.

        Returns:
        the institution information of this user
      • getLastlogin

        public long getLastlogin()
        Returns the time of the last login of this user.

        Returns:
        the time of the last login of this user
      • getLastname

        public java.lang.String getLastname()
        Returns the last name of this user.

        Returns:
        the last name of this user
      • getPassword

        public java.lang.String getPassword()
        Returns the encrypted user password.

        Returns:
        the encrypted user password
      • getZipcode

        public java.lang.String getZipcode()
        Returns the zip code information of this user.

        This information is stored in the "additional information" storage map using the key CmsUserSettings.ADDITIONAL_INFO_ZIPCODE.

        Returns:
        the zip code information of this user
      • isGuestUser

        public boolean isGuestUser()
        Checks if this user is the default guest user.

        Returns:
        true if this user is the default guest user
      • isManaged

        public boolean isManaged()
        Returns true if this user is not able to manage itself.

        Returns:
        true if this user is not able to manage itself
      • isTouched

        public boolean isTouched()
        Returns true if this user was touched.

        Returns:
        boolean true if this user was touched
      • isWebuser

        public boolean isWebuser()
        Checks if the user is marked as webuser.

        Returns:
        true if the user is marked as webuser
      • setAdditionalInfo

        public void setAdditionalInfo​(java.util.Map<java.lang.String,​java.lang.Object> additionalInfo)
        Sets this users complete "additional information" storage map to the given value.

        Parameters:
        additionalInfo - the complete "additional information" map to set
        See Also:
        getAdditionalInfo()
      • setAdditionalInfo

        public void setAdditionalInfo​(java.lang.String key,
                                      java.lang.Object value)
        Stores a value in this users "additional information" storage map with the given access key.

        Parameters:
        key - the key to store the value under
        value - the value to store in the users "additional information" storage map
        See Also:
        getAdditionalInfo()
      • setAddress

        public void setAddress​(java.lang.String address)
        Sets the address line of this user.

        Parameters:
        address - the address line to set
      • setCity

        public void setCity​(java.lang.String city)
        Sets the city information of this user.

        Parameters:
        city - the city information to set
      • setCountry

        public void setCountry​(java.lang.String country)
        Sets the country information of this user.

        Parameters:
        country - the city information to set
      • setEmail

        public void setEmail​(java.lang.String email)
        Sets the email address of this user.

        Parameters:
        email - the email address to set
      • setFirstname

        public void setFirstname​(java.lang.String firstname)
        Sets the first name of this user.

        Parameters:
        firstname - the name to set
      • setInstitution

        public void setInstitution​(java.lang.String institution)
        Sets the institution information of this user.

        Parameters:
        institution - the institution information to set
      • setLastlogin

        public void setLastlogin​(long value)
        Sets the last login time stamp of this user.

        Parameters:
        value - the last login time stamp to set
      • setLastname

        public void setLastname​(java.lang.String lastname)
        Sets the last name of this user.

        Parameters:
        lastname - the name to set
      • setManaged

        public void setManaged​(boolean value)
        Sets the managed flag for this user to the given value.

        Parameters:
        value - the value to set
      • setPassword

        public void setPassword​(java.lang.String value)
        Sets the password of this user.

        Parameters:
        value - the password to set
      • setZipcode

        public void setZipcode​(java.lang.String zipcode)
        Sets the zip code information of this user.

        Parameters:
        zipcode - the zip code information to set
      • toString

        public java.lang.String toString()
        Specified by:
        toString in interface java.security.Principal
        Overrides:
        toString in class java.lang.Object
        See Also:
        Object.toString()
      • touch

        public void touch()
        Sets the "touched" status of this user to true.