org.meshcms.core
Class UserInfo

java.lang.Object
  extended byorg.meshcms.core.UserInfo
All Implemented Interfaces:
java.io.Serializable

public class UserInfo
extends java.lang.Object
implements java.io.Serializable

Profile of a user. Modifications made by calling the set methods are not stored until you use store(org.meshcms.core.WebSite).

See Also:
Serialized Form

Field Summary
static int ADMIN
          Permissions for an administrator (full permissions).
static int CAN_ADD_USERS
          Permission to add other users.
static int CAN_BROWSE_FILES
          Permission to browse files.
static int CAN_DO_ADMINTASKS
          Permission to do maintainance operations.
static int CAN_EDIT_PAGES
          Permission to edit pages (in the home path of the user profile).
static int CAN_MANAGE_FILES
          Permission to manage files.
static int CAN_VIEW_OTHER_USERINFO
          Permission to view other user profiles.
static java.lang.String[] DETAILS
          Names for user detail fields.
protected static java.lang.String E_MAIL
           
static int EDITOR
          Permissions for an editor (can edit files, but is not an administrator).
protected  boolean global
           
static int GUEST
          Permissions for guest user (non-logged in).
protected static java.lang.String HOME_PATH
           
protected  java.util.Properties info
           
protected static java.lang.String LANGUAGE
           
static int MEMBER
          Permissions for a member (can't edit files).
protected static java.lang.String PASSWORD
           
protected static java.lang.String PERMISSIONS
           
protected static java.lang.String SALT
           
protected static java.lang.String USERNAME
           
protected static java.lang.String VALID_USERNAME_CHARS
          Characters allowed in a username.
 
Constructor Summary
UserInfo()
          Creates a new empty instance.
 
Method Summary
 boolean canDo(int what)
          Verifies the permissions to do a certain thing.
 boolean canWrite(WebSite webSite, Path filePath)
          Verifies all permissions to write the file at a certain path in the web application.
 boolean exists(WebSite webSite, java.lang.String username)
          Checks if the user exists.
 java.lang.String getDetailName(int index)
          Returns the name of the user detail at the given index.
 java.lang.String getDetailValue(java.lang.String name)
          Returns the value of the given user detail.
 java.lang.String getDisplayName()
          Returns a string suitable to describe the user.
 java.lang.String getEmail()
          Returns the user's e-mail address.
 Path getHomePath()
          Returns the user's home path.
 java.lang.String getPassword()
          Returns the user's (encrypted) password.
 int getPermissions()
          Returns the user's permissions.
 java.lang.String getPreferredLocaleCode()
          Returns the preferred locale for the user, in a form like en_US, it or similar.
 java.lang.String getUsername()
          Returns the user's username.
 java.lang.String getValue(java.lang.String name)
          Returns the value of a specific property.
 boolean isGlobal()
           
 boolean isGuest()
          Checks if the user is a guest.
 boolean load(WebSite webSite, java.lang.String username, java.lang.String password)
          Loads a specific user.
 void loadGuest()
          Loads the guest user.
 boolean setDetail(java.lang.String name, java.lang.String value)
          Sets a user's detail.
 boolean setEmail(java.lang.String email)
          Sets the e-mail address of this user.
 void setHomePath(Path homePath)
          Sets the home path for the user.
 void setPassword(java.lang.String password)
          Sets the password for this user.
 void setPermissions(int permissions)
          Sets permissions for the user.
 void setPreferredLocaleCode(java.lang.String localeCode)
          Sets the preferred locale for the user.
 void setUsername(java.lang.String username)
          Sets the username for this user.
 boolean store(WebSite webSite)
          Stores the user's profile in a file.
 boolean updatePassword(java.lang.String oldPassword, java.lang.String newPassword)
          Sets the password for this user after verification of the old password.
 boolean verifyPassword(java.lang.String password)
          Verifies the given password agains the one in the current profile.
static boolean verifyUsername(java.lang.String username)
          Checks if the username is valid (i.e. contains characters in VALID_USERNAME_CHARS only).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CAN_ADD_USERS

public static final int CAN_ADD_USERS
Permission to add other users.

See Also:
Constant Field Values

CAN_EDIT_PAGES

public static final int CAN_EDIT_PAGES
Permission to edit pages (in the home path of the user profile).

See Also:
Constant Field Values

CAN_MANAGE_FILES

public static final int CAN_MANAGE_FILES
Permission to manage files.

See Also:
Constant Field Values

CAN_VIEW_OTHER_USERINFO

public static final int CAN_VIEW_OTHER_USERINFO
Permission to view other user profiles.

See Also:
Constant Field Values

CAN_DO_ADMINTASKS

public static final int CAN_DO_ADMINTASKS
Permission to do maintainance operations.

See Also:
Constant Field Values

CAN_BROWSE_FILES

public static final int CAN_BROWSE_FILES
Permission to browse files.

See Also:
Constant Field Values

GUEST

public static final int GUEST
Permissions for guest user (non-logged in).

See Also:
Constant Field Values

MEMBER

public static final int MEMBER
Permissions for a member (can't edit files).

See Also:
Constant Field Values

EDITOR

public static final int EDITOR
Permissions for an editor (can edit files, but is not an administrator).

See Also:
Constant Field Values

ADMIN

public static final int ADMIN
Permissions for an administrator (full permissions).

See Also:
Constant Field Values

USERNAME

protected static final java.lang.String USERNAME
See Also:
Constant Field Values

PASSWORD

protected static final java.lang.String PASSWORD
See Also:
Constant Field Values

HOME_PATH

protected static final java.lang.String HOME_PATH
See Also:
Constant Field Values

PERMISSIONS

protected static final java.lang.String PERMISSIONS
See Also:
Constant Field Values

E_MAIL

protected static final java.lang.String E_MAIL
See Also:
Constant Field Values

LANGUAGE

protected static final java.lang.String LANGUAGE
See Also:
Constant Field Values

DETAILS

public static final java.lang.String[] DETAILS
Names for user detail fields.


VALID_USERNAME_CHARS

protected static final java.lang.String VALID_USERNAME_CHARS
Characters allowed in a username.

See Also:
Constant Field Values

SALT

protected static final java.lang.String SALT
See Also:
Constant Field Values

info

protected java.util.Properties info

global

protected boolean global
Constructor Detail

UserInfo

public UserInfo()
Creates a new empty instance. Use load(org.meshcms.core.WebSite, java.lang.String, java.lang.String) to load a defined user.

Method Detail

setUsername

public void setUsername(java.lang.String username)
Sets the username for this user.


getUsername

public java.lang.String getUsername()
Returns the user's username.


setPassword

public void setPassword(java.lang.String password)
Sets the password for this user. The password will be encrypted.


updatePassword

public boolean updatePassword(java.lang.String oldPassword,
                              java.lang.String newPassword)
Sets the password for this user after verification of the old password. The password will be encrypted.

Returns:
the result of the operation

getPassword

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


setEmail

public boolean setEmail(java.lang.String email)
Sets the e-mail address of this user. Utils.checkAddress(java.lang.String) is used to verify the new address.

Returns:
the result of the operation

getEmail

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


setHomePath

public void setHomePath(Path homePath)
Sets the home path for the user. A user can't edit files outside his own home path.


getHomePath

public Path getHomePath()
Returns the user's home path.


setPermissions

public void setPermissions(int permissions)
Sets permissions for the user. This method should be called when creating the user.


getPermissions

public int getPermissions()
Returns the user's permissions.


getPreferredLocaleCode

public java.lang.String getPreferredLocaleCode()
Returns the preferred locale for the user, in a form like en_US, it or similar.


setPreferredLocaleCode

public void setPreferredLocaleCode(java.lang.String localeCode)
Sets the preferred locale for the user.


loadGuest

public void loadGuest()
Loads the guest user.


load

public boolean load(WebSite webSite,
                    java.lang.String username,
                    java.lang.String password)
Loads a specific user.


store

public boolean store(WebSite webSite)
Stores the user's profile in a file.


verifyUsername

public static boolean verifyUsername(java.lang.String username)
Checks if the username is valid (i.e. contains characters in VALID_USERNAME_CHARS only).


verifyPassword

public boolean verifyPassword(java.lang.String password)
Verifies the given password agains the one in the current profile.


canDo

public boolean canDo(int what)
Verifies the permissions to do a certain thing. Example: user.canDo(UserInfo.CAN_EDIT_PAGES)


canWrite

public boolean canWrite(WebSite webSite,
                        Path filePath)
Verifies all permissions to write the file at a certain path in the web application.


setDetail

public boolean setDetail(java.lang.String name,
                         java.lang.String value)
Sets a user's detail. Available details are specified in DETAILS. Other details can be set, but they will not be stored when store(org.meshcms.core.WebSite) is called.

See Also:
getValue(java.lang.String)

getValue

public java.lang.String getValue(java.lang.String name)
Returns the value of a specific property. It is used internally, but can be use to retrieve the value of user's details.

See Also:
setDetail(java.lang.String, java.lang.String)

getDetailValue

public java.lang.String getDetailValue(java.lang.String name)
Returns the value of the given user detail.


getDetailName

public java.lang.String getDetailName(int index)
Returns the name of the user detail at the given index.


getDisplayName

public java.lang.String getDisplayName()
Returns a string suitable to describe the user. It can be his full name, partial name or username, according to the available data.


isGuest

public boolean isGuest()
Checks if the user is a guest.


exists

public boolean exists(WebSite webSite,
                      java.lang.String username)
Checks if the user exists. A user exists when the corresponding file exists.


isGlobal

public boolean isGlobal()