org.opencms.file
Class CmsUser

java.lang.Object
  extended byorg.opencms.security.CmsPrincipal
      extended byorg.opencms.file.CmsUser
All Implemented Interfaces:
java.lang.Cloneable, I_CmsPrincipal, java.security.Principal

public class CmsUser
extends CmsPrincipal
implements I_CmsPrincipal, java.lang.Cloneable

A user principal in the OpenCms permission system.

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

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

Another possible type of users is USER_TYPE_WEBUSER. These users do not have access to the OpenCms Workplace. However, a web user can be created by every user, for example the "Guest" user. The main use case is that web users are used for users of the website that can generate their own accounts, in a "please register your account..." scenario. These web user accounts can then be used to build personalized web sites. A web user is created using CmsObject.addWebUser(String, String, String, String, Map).

Since:
6.0.0
Version:
$Revision: 1.34 $
Author:
Alexander Kandzior, Michael Emmerich
See Also:
CmsGroup

Field Summary
static int USER_TYPE_SYSTEMUSER
          Identifies the system user type.
static int USER_TYPE_WEBUSER
          Identifies the web user type.
 
Fields inherited from class org.opencms.security.CmsPrincipal
m_description, m_flags, m_id, m_name
 
Fields inherited from interface org.opencms.security.I_CmsPrincipal
FLAG_CORE_LIMIT, FLAG_DISABLED, FLAG_ENABLED, FLAG_GROUP_PROJECT_MANAGER, FLAG_GROUP_PROJECT_USER, FLAG_GROUP_WORKFLOW_ROLE, PRINCIPAL_GROUP, PRINCIPAL_USER
 
Constructor Summary
CmsUser()
          Creates a new, empty OpenCms user principal.
CmsUser(CmsUUID id, java.lang.String name, java.lang.String description)
          Creates a new OpenCms user principal.
CmsUser(CmsUUID id, java.lang.String name, java.lang.String password, java.lang.String description, java.lang.String firstname, java.lang.String lastname, java.lang.String email, long lastlogin, int flags, java.util.Map additionalInfo, java.lang.String address, int type)
          Creates a new OpenCms user principal.
 
Method Summary
static void checkEmail(java.lang.String email)
          Validates an email address.
 void checkName(java.lang.String name)
          Checks if the provided user name is a valid user name and can be used as an argument value for CmsPrincipal.setName(String).
static void checkZipCode(java.lang.String zipcode)
          Validates a zip code.
 java.lang.Object clone()
           
 void deleteAdditionalInfo(java.lang.String key)
          Deletes a value from this users "additional information" storage map.
 java.util.Map getAdditionalInfo()
          Returns this users complete "additional information" storage map.
 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.
 java.lang.String getAddress()
          Returns the address line of this user.
 java.lang.String getCity()
          Returns the city information of this user.
 java.lang.String getCountry()
          Returns the country information of this user.
 boolean getDisabled()
          Deprecated. use CmsPrincipal.isEnabled() instead
 java.lang.String getEmail()
          Returns the email address of this user.
 java.lang.String getFirstname()
          Returns the firstname of this user.
 java.lang.String getFullName()
          Returns the "full" name of the this user in the format "{firstname} {lastname} ({username})".
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.
 long getLastlogin()
          Returns the time of the last login of this user.
 java.lang.String getLastname()
          Returns the lastname of this user.
 java.lang.String getPassword()
          Returns the encrypted user password.
 int getType()
          Returns the type of this user.
 java.lang.String getZipcode()
          Returns the zip code information of this user.
 boolean isGroup()
          Returns true if this principal is of type CmsGroup.
 boolean isGuestUser()
          Returns true if this user is the default guest user.
 boolean isSystemUser()
          Returns true if this user is a "system user".
static boolean isSystemUser(int type)
          Returns true if the provided user type indicates a system user.
 boolean isTouched()
          Returns true if this user was touched.
 boolean isUser()
          Returns true if this principal is of type CmsUser.
 boolean isWebUser()
          Returns true if this user is a "web user".
static boolean isWebUser(int type)
          Returns true if the provided user type indicates a web user.
 void setAdditionalInfo(java.util.Map additionalInfo)
          Sets this users complete "additional information" storage map to the given value.
 void setAdditionalInfo(java.lang.String key, java.lang.Object value)
          Stores a value in this users "additional information" storage map with the gicen access key.
 void setAddress(java.lang.String address)
          Sets the address line of this user.
 void setCity(java.lang.String city)
          Sets the city information of this user.
 void setCountry(java.lang.String country)
          Sets the country information of this user.
 void setDisabled()
          Deprecated. use CmsPrincipal.setEnabled(boolean) instead
 void setEmail(java.lang.String email)
          Sets the email address of this user.
 void setEnabled()
          Deprecated. use CmsPrincipal.setEnabled(boolean) instead
 void setFirstname(java.lang.String firstname)
          Sets the first name of this user.
 void setLastlogin(long value)
          Sets the last login timestamp of this user.
 void setLastname(java.lang.String lastname)
          Sets the last name of this user.
 void setPassword(java.lang.String value)
          Sets the password of this user.
protected  void setType(int value)
          Sets the type of this user.
 void setZipcode(java.lang.String zipcode)
          Sets the zip code information of this user.
 java.lang.String toString()
           
 void touch()
          Sets the "touched" status of this user to true.
 
Methods inherited from class org.opencms.security.CmsPrincipal
equals, filterCore, filterCoreFlag, filterFlag, getDescription, getFlags, getId, getName, getPrefixedGroup, getPrefixedName, getPrefixedUser, hashCode, isEnabled, readPrefixedPrincipal, readPrincipal, setDescription, setEnabled, setFlags, setName
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.opencms.security.I_CmsPrincipal
equals, getDescription, getFlags, getId, getName, getPrefixedName, hashCode, isEnabled, setDescription, setEnabled, setFlags, setName
 

Field Detail

USER_TYPE_SYSTEMUSER

public static final int USER_TYPE_SYSTEMUSER
Identifies the system user type.

See Also:
Constant Field Values

USER_TYPE_WEBUSER

public static final int USER_TYPE_WEBUSER
Identifies the web user type.

See Also:
Constant Field Values
Constructor Detail

CmsUser

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

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


CmsUser

public CmsUser(CmsUUID id,
               java.lang.String name,
               java.lang.String description)
Creates a new OpenCms user principal.

Parameters:
id - the unique id of the new user
name - the unique name of the new user
description - the description of the new user

CmsUser

public CmsUser(CmsUUID id,
               java.lang.String name,
               java.lang.String password,
               java.lang.String description,
               java.lang.String firstname,
               java.lang.String lastname,
               java.lang.String email,
               long lastlogin,
               int flags,
               java.util.Map additionalInfo,
               java.lang.String address,
               int type)
Creates a new OpenCms user principal.

Parameters:
id - the unique id of the new user
name - the unique name of the new user
password - the password of the user
description - the description of the new user
firstname - the first name
lastname - the last name
email - the email address
lastlogin - time stamp
flags - flags
additionalInfo - user related information
address - the address
type - the type of this user
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 zipcode 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()

isSystemUser

public static boolean isSystemUser(int type)
Returns true if the provided user type indicates a system user.

Parameters:
type - the user type to check
Returns:
true if the provided user type indicates a system user

isWebUser

public static boolean isWebUser(int type)
Returns true if the provided user type indicates a web user.

Parameters:
type - the user type to check
Returns:
true if the provided user type indicates a web user

checkName

public void checkName(java.lang.String name)
               throws CmsIllegalArgumentException
Checks if the provided user name is a valid user name and can be used as an argument value for CmsPrincipal.setName(String).

Specified by:
checkName in interface I_CmsPrincipal
Parameters:
name - the user name to check
Throws:
CmsIllegalArgumentException - if the check fails

clone

public java.lang.Object clone()
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 getAdditionalInfo()
Returns this users complete "additional information" storage map.

The "additional information" storage map is a simple java.util#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. The map is serialized when the user is stored in the database.

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

getCity

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

This informaion 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 informaion is stored in the "additional information" storage map using the key CmsUserSettings.ADDITIONAL_INFO_COUNTRY.

Returns:
the country information of this user

getDisabled

public boolean getDisabled()
Deprecated. use CmsPrincipal.isEnabled() instead

Returns true if this user is disabled.

Returns:
true if this user is disabled

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 firstname of this user.

Returns:
the firstname 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

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 lastname of this user.

Returns:
the lastname of this user

getPassword

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

Returns:
the encrypted user password

getType

public int getType()
Returns the type of this user.

Possible options are USER_TYPE_SYSTEMUSER for a "system user", or USER_TYPE_WEBUSER for a "web user".

Returns:
the type of this user

getZipcode

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

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

Returns:
the zip code information of this user

isGroup

public boolean isGroup()
Description copied from interface: I_CmsPrincipal
Returns true if this principal is of type CmsGroup.

Specified by:
isGroup in interface I_CmsPrincipal
Overrides:
isGroup in class CmsPrincipal
See Also:
I_CmsPrincipal.isGroup()

isGuestUser

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

Returns:
true if this user is the default guest user

isSystemUser

public boolean isSystemUser()
Returns true if this user is a "system user".

Returns:
true if this user is a "system user"

isTouched

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

Returns:
boolean true if this user was touched

isUser

public boolean isUser()
Description copied from interface: I_CmsPrincipal
Returns true if this principal is of type CmsUser.

Specified by:
isUser in interface I_CmsPrincipal
Overrides:
isUser in class CmsPrincipal
See Also:
I_CmsPrincipal.isUser()

isWebUser

public boolean isWebUser()
Returns true if this user is a "web user".

Returns:
true if this user is a "web user"

setAdditionalInfo

public void setAdditionalInfo(java.util.Map 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 gicen 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

setDisabled

public void setDisabled()
Deprecated. use CmsPrincipal.setEnabled(boolean) instead

Disables this user.


setEmail

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

Parameters:
email - the email address to set

setEnabled

public void setEnabled()
Deprecated. use CmsPrincipal.setEnabled(boolean) instead

Enables this user.


setFirstname

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

Parameters:
firstname - the name to set

setLastlogin

public void setLastlogin(long value)
Sets the last login timestamp of this user.

Parameters:
value - the last login timestamp to set

setLastname

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

Parameters:
lastname - the name 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
See Also:
Object.toString()

touch

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


setType

protected void setType(int value)
Sets the type of this user.

Possible options are USER_TYPE_SYSTEMUSER for a "system user", or USER_TYPE_WEBUSER for a "web user".

Parameters:
value - the type to set