org.opencms.file
Class CmsUser

java.lang.Object
  extended by org.opencms.file.CmsUser
All Implemented Interfaces:
Cloneable, I_CmsPrincipal

public class CmsUser
extends Object
implements I_CmsPrincipal, Cloneable

A user in the OpenCms permission system.

A user in OpenCms is uniquely definded by its user named returned by 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.30 $
Author:
Alexander Kandzior, Michael Emmerich
See Also:
CmsGroup

Field Summary
static int USER_TYPE_SYSTEMUSER
          A user-type system user.
static int USER_TYPE_WEBUSER
          A user-type web user.
 
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 CmsUser object.
CmsUser(CmsUUID id, String name, String description)
          Creates a new Cms user object.
CmsUser(CmsUUID id, String name, String password, String description, String firstname, String lastname, String email, long lastlogin, int flags, Map additionalInfo, String address, int type)
          Creates a new CmsUser object.
 
Method Summary
static void checkEmail(String email)
          Validates an email address.
static void checkLogin(String login)
          Validates a login.
static void checkZipCode(String zipcode)
          Validates a zip code.
 Object clone()
          Returns a clone of this Objects instance.
 void deleteAdditionalInfo(String key)
          Delete additional information about the user.
 boolean equals(Object obj)
          Compares the given object with this principal.
static List filterCore(List users)
          Filters out all users with flags greater than I_CmsPrincipal.FLAG_CORE_LIMIT.
static List filterCoreFlag(List users, int flag)
          Filters out all users that does not have the given flag set, but leaving all users with flags less than I_CmsPrincipal.FLAG_CORE_LIMIT.
static List filterFlag(List users, int flag)
          Filters out all users that does not have the given flag set.
 Map getAdditionalInfo()
          Returns the complete Hashtable with additional information about the user.
 Object getAdditionalInfo(String key)
          Returns additional information about the user which are usually set in the users preferences.
 String getAddress()
          Gets the address.
 String getCity()
          Returns the city of the address of the user.
 String getCountry()
          Returns the country of the address of the user.
 String getDescription()
          Gets the description of this user.
 boolean getDisabled()
          Decides if this user is disabled.
 String getEmail()
          Returns the email address of this user.
 String getFirstname()
          Returns the firstname of this user.
 int getFlags()
          Returns the flags of this user.
 String getFullName()
          Returns the "full" name this user in the format "{firstname} {lastname} ({username})".
static String getFullName(CmsUser user)
          Returns the "full" name the given user in the format "{firstname} {lastname} ({username})", or the empty String "" if the user is null.
 CmsUUID getId()
          Returns the id of this user.
 long getLastlogin()
          Returns the time of the last login of this user.
 String getLastname()
          Returns the lastname of this user.
 String getName()
          Gets the (login) name of this user.
 String getPassword()
          Returns the encrypted user password.
 int getType()
          Returns the type of the user.
 String getZipcode()
          Returns the zip code of the address of the user.
 int hashCode()
          Returns the hash code of this object.
 boolean isEnabled()
          Returns the enabled flag.
 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 type.
 boolean isTouched()
          Returns true if this user was touched, e.g.
 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 type.
 void setAdditionalInfo(Map additionalInfo)
          Sets the complete Hashtable with additional information about the user.
 void setAdditionalInfo(String key, Object obj)
          Sets additional information about the user.
 void setAddress(String value)
          Sets the address.
 void setCity(String city)
          Sets the city of the address of the user.
 void setCountry(String country)
          Sets the country of the address of the user.
 void setDescription(String value)
          Sets the description of this user.
 void setDisabled()
          Disables the user flags by setting them to FLAG_DISABLED.
 void setEmail(String value)
          Sets the email.
 void setEnabled()
          Enables the user flags by setting them to FLAG_ENABLED.
 void setEnabled(boolean enabled)
          Sets the enabled flag.
 void setFirstname(String firstname)
          Sets the firstname.
 void setFlags(int value)
          Sets the flags.
 void setLastlogin(long value)
          Sets the lastlogin.
 void setLastname(String lastname)
          Gets the lastname.
 void setName(String name)
          Sets the name (login).
 void setPassword(String value)
          Sets the password.
 void setZipcode(String zipcode)
          Sets the zip code of the address of the user.
 String toString()
           
 void touch()
          Sets the "touched" status of this user to "true".
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

USER_TYPE_SYSTEMUSER

public static final int USER_TYPE_SYSTEMUSER
A user-type system user.

See Also:
Constant Field Values

USER_TYPE_WEBUSER

public static final int USER_TYPE_WEBUSER
A user-type web user.

See Also:
Constant Field Values
Constructor Detail

CmsUser

public CmsUser()
Creates a new empty CmsUser object.

Only intented to be used with the org.opencms.workplace.tools.users.CmsEditUserDialog.


CmsUser

public CmsUser(CmsUUID id,
               String name,
               String description)
Creates a new Cms user object.

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

CmsUser

public CmsUser(CmsUUID id,
               String name,
               String password,
               String description,
               String firstname,
               String lastname,
               String email,
               long lastlogin,
               int flags,
               Map additionalInfo,
               String address,
               int type)
Creates a new CmsUser object.

Parameters:
id - the id of the new user
name - the 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(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

checkLogin

public static void checkLogin(String login)
Validates a login.

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

Parameters:
login - the login to validate

checkZipCode

public static void checkZipCode(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 String getFullName(CmsUser user)
Returns the "full" name 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 type.

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

isWebUser

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

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

clone

public Object clone()
Returns a clone of this Objects instance.

Overrides:
clone in class Object
Returns:
a clone of this instance

deleteAdditionalInfo

public void deleteAdditionalInfo(String key)
Delete additional information about the user.

Additional infos are for example emailadress, adress or surname...

Parameters:
key - The key of the additional information to delete

equals

public boolean equals(Object obj)
Description copied from interface: I_CmsPrincipal
Compares the given object with this principal.

Specified by:
equals in interface I_CmsPrincipal
Overrides:
equals in class Object
Parameters:
obj - object to comapre
Returns:
true if the object is equal
See Also:
Object.equals(java.lang.Object)

getAdditionalInfo

public Map getAdditionalInfo()
Returns the complete Hashtable with additional information about the user.

Additional infos are for example emailadress, adress or surname... The additional infos must be requested via the CmsObject.

Returns:
additional information about the user

getAdditionalInfo

public Object getAdditionalInfo(String key)
Returns additional information about the user which are usually set in the users preferences.

Parameters:
key - the key to the additional information
Returns:
additional information Object about the user, if the additional info does not exists, it returns null

getAddress

public String getAddress()
Gets the address.

Returns:
the USER_ADDRESS, or null

getCity

public String getCity()
Returns the city of the address of the user.

Returns:
the city

getCountry

public String getCountry()
Returns the country of the address of the user.

Returns:
the country

getDescription

public String getDescription()
Gets the description of this user.

Returns:
the description of this user

getDisabled

public boolean getDisabled()
Decides if this user is disabled.

Returns:
USER_FLAGS == FLAG_DISABLED

getEmail

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

Returns:
the email address of this user

getFirstname

public String getFirstname()
Returns the firstname of this user.

Returns:
the firstname of this user

getFlags

public int getFlags()
Returns the flags of this user.

Returns:
the flags of this user

getFullName

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

Returns:
the "full" name this user

getId

public CmsUUID getId()
Returns the id of this user.

Specified by:
getId in interface I_CmsPrincipal
Returns:
the id 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 String getLastname()
Returns the lastname of this user.

Returns:
the lastname of this user

getName

public String getName()
Gets the (login) name of this user.

Specified by:
getName in interface I_CmsPrincipal
Returns:
the (login) name of this user

getPassword

public String getPassword()
Returns the encrypted user password.

Returns:
the encrypted user password

getType

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

Possible options are USER_TYPE_SYSTEMUSER for a system user (incliding the "Guest" user), or USER_TYPE_WEBUSER for a webuser.

Returns:
the type

getZipcode

public String getZipcode()
Returns the zip code of the address of the user.

Returns:
the zip code

hashCode

public int hashCode()
Description copied from interface: I_CmsPrincipal
Returns the hash code of this object.

Specified by:
hashCode in interface I_CmsPrincipal
Overrides:
hashCode in class Object
Returns:
the hash code
See Also:
Object.hashCode()

isEnabled

public boolean isEnabled()
Returns the enabled flag.

It should replace the getDisabled() method.

Returns:
the enabled flag

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, e.g. the last-login timestamp was changed.

Returns:
boolean true if this resource was touched

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(Map additionalInfo)
Sets the complete Hashtable with additional information about the user.

Additional infos are for example emailadress, adress or surname...

This method has package-visibility for security-reasons. It is required to because of the use of two seprate databases for user data and additional user data.

Parameters:
additionalInfo - user-related additional information

setAdditionalInfo

public void setAdditionalInfo(String key,
                              Object obj)
Sets additional information about the user.

Additional infos are for example emailadress, adress or surname...

Parameters:
key - The key to the additional information
obj - The additinoal information value

setAddress

public void setAddress(String value)
Sets the address.

Parameters:
value - The user adress

setCity

public void setCity(String city)
Sets the city of the address of the user.

Parameters:
city - the city

setCountry

public void setCountry(String country)
Sets the country of the address of the user.

Parameters:
country - the country

setDescription

public void setDescription(String value)
Sets the description of this user.

Parameters:
value - the description of this user

setDisabled

public void setDisabled()
Disables the user flags by setting them to FLAG_DISABLED.


setEmail

public void setEmail(String value)
Sets the email.

Parameters:
value - The new email adress

setEnabled

public void setEnabled()
Enables the user flags by setting them to FLAG_ENABLED.


setEnabled

public void setEnabled(boolean enabled)
Sets the enabled flag.

It should replace the setDisabled() and the setEnabled() methods.

Parameters:
enabled - the enabled flag

setFirstname

public void setFirstname(String firstname)
Sets the firstname.

Parameters:
firstname - the USER_FIRSTNAME

setFlags

public void setFlags(int value)
Sets the flags.

Parameters:
value - The new user flags

setLastlogin

public void setLastlogin(long value)
Sets the lastlogin.

Parameters:
value - The new user section

setLastname

public void setLastname(String lastname)
Gets the lastname.

Parameters:
lastname - the last name of the user

setName

public void setName(String name)
Sets the name (login).

Parameters:
name - the name (login) to set

setPassword

public void setPassword(String value)
Sets the password.

Parameters:
value - The new password

setZipcode

public void setZipcode(String zipcode)
Sets the zip code of the address of the user.

Parameters:
zipcode - the zip code

toString

public String toString()
Overrides:
toString in class Object
See Also:
Object.toString()

touch

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


filterCore

public static List filterCore(List users)
Filters out all users with flags greater than I_CmsPrincipal.FLAG_CORE_LIMIT.

Parameters:
users - the list of CmsUser
Returns:
the same filtered list

filterFlag

public static List filterFlag(List users,
                              int flag)
Filters out all users that does not have the given flag set.

Parameters:
users - the list of CmsUser
flag - the flag for filtering
Returns:
the same filtered list

filterCoreFlag

public static List filterCoreFlag(List users,
                                  int flag)
Filters out all users that does not have the given flag set, but leaving all users with flags less than I_CmsPrincipal.FLAG_CORE_LIMIT.

Parameters:
users - the list of CmsUser
flag - the flag for filtering
Returns:
the same filtered list