org.liquidsite.core.content
Class User

java.lang.Object
  extended byorg.liquidsite.core.content.PersistentObject
      extended byorg.liquidsite.core.content.User

public class User
extends PersistentObject

A system user.


Field Summary
static java.lang.String NAME_CHARS
          The permitted user name characters.
 
Fields inherited from class org.liquidsite.core.content.PersistentObject
BINDERS, LOWER_CASE, NUMBERS, UPPER_CASE
 
Constructor Summary
User(ContentManager manager, Domain domain, java.lang.String name)
          Creates a new user with default values.
 
Method Summary
 void addToGroup(Group group)
          Adds this user to the specified group.
protected  void doDelete(DataSource src, User user)
          Deletes the object data from the database.
protected  void doInsert(DataSource src, User user, boolean restore)
          Inserts the object data into the database.
protected  void doUpdate(DataSource src, User user)
          Updates the object data in the database.
protected  void doValidate()
          Validates the object data before writing to the database.
 boolean equals(java.lang.Object obj)
          Checks if this user equals another object.
 boolean equals(User obj)
          Checks if this user equals another user.
static java.lang.String generatePassword()
          Generates a password suggestion that should be sufficiently hard to crack.
 java.lang.String getComment()
          Returns the user comment.
 Domain getDomain()
          Returns the user domain.
 java.lang.String getDomainName()
          Returns the user domain name
 java.lang.String getEmail()
          Returns the user e-mail address.
 boolean getEnabled()
          Returns the enabled flag.
 Group[] getGroups()
          Returns the groups that this user belongs to.
 java.lang.String getName()
          Returns the user name.
 java.lang.String getPassword()
          Returns the encoded user password.
 java.lang.String getRealName()
          Returns the real user name.
 java.util.TimeZone getTimeZone()
          Returns the user time zone.
 boolean isSuperUser()
          Checks if this user is a super user.
 void removeFromGroup(Group group)
          Removes this user from the specified group.
 void setComment(java.lang.String comment)
          Sets the user comment.
 void setEmail(java.lang.String email)
          Sets the user e-mail address.
 void setEnabled(boolean enabled)
          Sets the enabled flag.
 void setPassword(java.lang.String password)
          Sets the user password.
 void setPasswordEncoded(java.lang.String password)
          Sets the encoded user password.
 void setRealName(java.lang.String realName)
          Sets the real user name.
 java.lang.String toString()
          Returns a string representation of this object.
 boolean verifyPassword(java.lang.String password)
          Verifies the user password.
 
Methods inherited from class org.liquidsite.core.content.PersistentObject
decodeMap, delete, delete, encodeMap, getContentManager, hasAdminAccess, hasPublishAccess, hasReadAccess, hasWriteAccess, isPersistent, restore, restore, save, save, validateChars, validateSize
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NAME_CHARS

public static final java.lang.String NAME_CHARS
The permitted user name characters.

See Also:
Constant Field Values
Constructor Detail

User

public User(ContentManager manager,
            Domain domain,
            java.lang.String name)
Creates a new user with default values.

Parameters:
manager - the content manager to use
domain - the domain, or null for a superuser
name - the user name
Method Detail

generatePassword

public static java.lang.String generatePassword()
Generates a password suggestion that should be sufficiently hard to crack.

Returns:
the generated password

equals

public boolean equals(java.lang.Object obj)
Checks if this user equals another object. This method will only return true if the other object is a user with the same domain and user name.

Parameters:
obj - the object to compare with
Returns:
true if the other object is an identical user, or false otherwise

equals

public boolean equals(User obj)
Checks if this user equals another user. This method will only return true if the other object is a user with the same domain and user name.

Parameters:
obj - the object to compare with
Returns:
true if the other object is an identical user, or false otherwise

toString

public java.lang.String toString()
Returns a string representation of this object.

Returns:
a string representation of this object

isSuperUser

public boolean isSuperUser()
Checks if this user is a super user. A super user should have access to all objects in the system, and does not belong to any domain.

Returns:
true if the user represents a super user, or false otherwise

getDomain

public Domain getDomain()
                 throws ContentException
Returns the user domain.

Returns:
the user domain, or null if the user is a superuser
Throws:
ContentException - if no content manager is available

getDomainName

public java.lang.String getDomainName()
Returns the user domain name

Returns:
the user domain name

getName

public java.lang.String getName()
Returns the user name.

Returns:
the user name

getPassword

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

Returns:
the encoded user password

setPassword

public void setPassword(java.lang.String password)
Sets the user password. This method will hash and encode the specified password, which is an irreversible process.

Parameters:
password - the new user password

setPasswordEncoded

public void setPasswordEncoded(java.lang.String password)
Sets the encoded user password. This method assumes that the specified password has already been hashed and encoded and should only be used when restoring user passwords from backups.

Parameters:
password - the new encoded user password

getEnabled

public boolean getEnabled()
Returns the enabled flag.

Returns:
true if the user is enabled, or false otherwise

setEnabled

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

Parameters:
enabled - the new enabled flag

verifyPassword

public boolean verifyPassword(java.lang.String password)
Verifies the user password. This method will hash and encode the specified password, and compare the result with the real password. This method can be used to verify user logins and will return false if the enabled flag isn't set.

Parameters:
password - the user password
Returns:
true if the passwords are identical, or false otherwise

getRealName

public java.lang.String getRealName()
Returns the real user name.

Returns:
the real user name

setRealName

public void setRealName(java.lang.String realName)
Sets the real user name.

Parameters:
realName - the new real user name

getEmail

public java.lang.String getEmail()
Returns the user e-mail address.

Returns:
the user e-mail address

setEmail

public void setEmail(java.lang.String email)
Sets the user e-mail address.

Parameters:
email - the new user e-mail address

getTimeZone

public java.util.TimeZone getTimeZone()
Returns the user time zone.

Returns:
the user time zone

getComment

public java.lang.String getComment()
Returns the user comment.

Returns:
the user comment

setComment

public void setComment(java.lang.String comment)
Sets the user comment.

Parameters:
comment - the new user comment

getGroups

public Group[] getGroups()
                  throws ContentException
Returns the groups that this user belongs to. This method will only return the groups registered to this user in the database. The results will also be cached to return the same list every time, until this object is written to the database.

Returns:
an array of groups this user belongs to
Throws:
ContentException - if the database couldn't be accessed properly

addToGroup

public void addToGroup(Group group)
Adds this user to the specified group. This action will not take effect until this object is saved.

Parameters:
group - the group object

removeFromGroup

public void removeFromGroup(Group group)
Removes this user from the specified group. This action will not take effect until this object is saved.

Parameters:
group - the group object

doValidate

protected void doValidate()
                   throws ContentException
Validates the object data before writing to the database.

Specified by:
doValidate in class PersistentObject
Throws:
ContentException - if the object data wasn't valid

doInsert

protected void doInsert(DataSource src,
                        User user,
                        boolean restore)
                 throws ContentException
Inserts the object data into the database. If the restore flag is set, no automatic changes should be made to the data before writing to the database.

Specified by:
doInsert in class PersistentObject
Parameters:
src - the data source to use
user - the user performing the operation
restore - the restore flag
Throws:
ContentException - if the database couldn't be accessed properly

doUpdate

protected void doUpdate(DataSource src,
                        User user)
                 throws ContentException
Updates the object data in the database.

Specified by:
doUpdate in class PersistentObject
Parameters:
src - the data source to use
user - the user performing the operation
Throws:
ContentException - if the database couldn't be accessed properly

doDelete

protected void doDelete(DataSource src,
                        User user)
                 throws ContentException
Deletes the object data from the database.

Specified by:
doDelete in class PersistentObject
Parameters:
src - the data source to use
user - the user performing the operation
Throws:
ContentException - if the database couldn't be accessed properly