Last update: 2011-06-23

org.proteios.core
Class User

java.lang.Object
  extended by org.proteios.core.BasicItem<UserData>
      extended by org.proteios.core.User
All Implemented Interfaces:
Principal, AccessControlled, Identifiable, Nameable, Removable, SystemItem

public class User
extends BasicItem<UserData>
implements Nameable, Removable, SystemItem, Principal

This class is used to represent a user in Proteios.

Version:
2.0
Author:
Nicklas
Last modified
$Date: 2009-04-09 08:48:11 +0200 (Thu, 09 Apr 2009) $

Field Summary
static int MAX_ADDRESS_LENGTH
          The maximum length of the address that can be stored in the database.
static int MAX_EMAIL_LENGTH
          The maximum length of the email address that can be stored in the database.
static int MAX_EXTERNAL_ID_LENGTH
          The maximum length of the external ID that can be stored in the database.
static int MAX_FAX_LENGTH
          The maximum length of the fax that can be stored in the database.
static int MAX_LOGIN_LENGTH
          The maximum length of the login that can be stored in the database.
static int MAX_ORGANISATION_LENGTH
          The maximum length of the organisation that can be stored in the database.
static int MAX_PHONE_LENGTH
          The maximum length of the phone that can be stored in the database.
static int MAX_URL_LENGTH
          The maximum length of the url that can be stored in the database.
static String ROOT
          The system id for the User representing the root account.
static Item TYPE
          The type of item represented by this class.
 
Fields inherited from interface org.proteios.core.Nameable
MAX_DESCRIPTION_LENGTH, MAX_NAME_LENGTH
 
Method Summary
 String getAddress()
          Get the address for the user, or null if unknown.
static User getById(DbControl dc, int id)
          Get a User item when you know the ID.
 String getDescription()
          Get the description for the item.
 long getDiskUsage(QuotaType quotaType, Location location)
          Get the used number of bytes for the specified quota type and location.
 String getEmail()
          Get the email address to the user, or null if unknown.
 Date getExpirationDate()
          Get the expire date of the account.
 String getExternalId()
          Get the external id for the user account.
 String getFax()
          Get the fax number to the user, or null if unknown.
 ItemQuery<Group> getGroups()
          Get a query that returns the groups where this user is a member.
 Directory getHomeDirectory()
          Get the home Directory for this user.
 String getLogin()
          Get the login for the user account.
 ItemQuery<Message> getMessages()
          Get a query that returns all messages for the user.
 String getName()
          Get the name of the item.
 String getOrganisation()
          Get the organisation this user works for, or null if unknown.
 String getPhone()
          Get the phone number to the user, or null if unknown.
 ItemQuery<Project> getProjects()
          Get a query that returns the projects where this user is a member.
static ItemQuery<User> getQuery()
          Get a query configured to retrieve users.
 Quota getQuota()
          Get the Quota that applies to the user.
 Group getQuotaGroup()
          Get the Group whose Quota also applies to the user.
 ItemQuery<Role> getRoles()
          Get a query that returns the roles where this user is a member.
 String getSystemId()
          Get the system id for the item.
 Item getType()
          Get the type of item represented by the object.
 String getUrl()
          Get the URL to the user's homepage, or null if unknown.
 boolean isDisabled()
          Check if this account has been disabled.
 boolean isMultiuserAccount()
          Check if the user account is a multiuser account or not.
 boolean isRemoved()
          Check if the removed flag is set for this item.
 boolean isSystemItem()
          Check if the item is a system item or not.
 boolean isUsed()
          Checks if: any Ownable item is owned by this user A user can also be referenced from groups, roles, projects, item keys, sessions and settings, but those references are automatically deleted if the user is deleted and aren't inclued in this check.
 void setAddress(String address)
          Set the address for the user, or null if unknown.
 void setBase1Password(String md5Password)
          Set the encrypted password from Proteios 1.
 void setDescription(String description)
          Set the description for the item.
 void setDisabled(boolean disabled)
          Disables or enables the account.
 void setEmail(String email)
          Set the email address to the user, or null if unknown.
 void setExpirationDate(Date expirationDate)
          Sets the expiration date of the account.
 void setExternalId(String externalId)
          Set the external id for the user account.
 void setFax(String fax)
          Set the fax number to the user, or null if unknown.
 void setHomeDirectory(Directory homeDirectory)
          Set the home directory for the user.
 void setLogin(String login)
          Set the login for the user account.
 void setMultiuserAccount(boolean multiuserAccount)
          Sets if the user account is multiuser account.
 void setName(String name)
          Set the name of the item.
 void setOrganisation(String organisation)
          Set the organisation this user works for, or null if unknown.
 void setPassword(String password)
          Set the password.
 void setPhone(String phone)
          Set the phone number to the user, or null if unknown.
 void setQuota(Quota quota)
          Set the quota for the user.
 void setQuotaGroup(Group quotaGroup)
          Set the group whose quota should be checked for disk consuming items.
 void setRemoved(boolean removed)
          Set the removed flag for this item.
 void setUrl(String url)
          Set the URL to the user's homepage, or null if unknown.
 
Methods inherited from class org.proteios.core.BasicItem
checkPermission, equals, getDbControl, getId, getPermissions, getSessionControl, getVersion, hashCode, hasPermission, isDetached, isInDatabase, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.proteios.core.Identifiable
getId, getVersion
 
Methods inherited from interface org.proteios.core.AccessControlled
checkPermission, hasPermission
 
Methods inherited from interface java.security.Principal
equals, hashCode, toString
 

Field Detail

TYPE

public static final Item TYPE
The type of item represented by this class.

See Also:
Item.USER, getType()

ROOT

public static final String ROOT
The system id for the User representing the root account. The root user has full access to everything in Proteios.

See Also:
Constant Field Values

MAX_EXTERNAL_ID_LENGTH

public static final int MAX_EXTERNAL_ID_LENGTH
The maximum length of the external ID that can be stored in the database.

See Also:
setExternalId(String), Constant Field Values

MAX_LOGIN_LENGTH

public static final int MAX_LOGIN_LENGTH
The maximum length of the login that can be stored in the database.

See Also:
setLogin(String), Constant Field Values

MAX_ORGANISATION_LENGTH

public static final int MAX_ORGANISATION_LENGTH
The maximum length of the organisation that can be stored in the database.

See Also:
setOrganisation(String), Constant Field Values

MAX_ADDRESS_LENGTH

public static final int MAX_ADDRESS_LENGTH
The maximum length of the address that can be stored in the database.

See Also:
setAddress(String), Constant Field Values

MAX_PHONE_LENGTH

public static final int MAX_PHONE_LENGTH
The maximum length of the phone that can be stored in the database.

See Also:
setPhone(String), Constant Field Values

MAX_FAX_LENGTH

public static final int MAX_FAX_LENGTH
The maximum length of the fax that can be stored in the database.

See Also:
setFax(String), Constant Field Values

MAX_EMAIL_LENGTH

public static final int MAX_EMAIL_LENGTH
The maximum length of the email address that can be stored in the database.

See Also:
setEmail(String), Constant Field Values

MAX_URL_LENGTH

public static final int MAX_URL_LENGTH
The maximum length of the url that can be stored in the database.

See Also:
setUrl(String), Constant Field Values
Method Detail

getById

public static User getById(DbControl dc,
                           int id)
                    throws ItemNotFoundException,
                           PermissionDeniedException,
                           BaseException
Get a User item when you know the ID.

Parameters:
dc - The DbControl which will be used for permission checking and database access.
id - The ID of the item to load
Returns:
The User item
Throws:
ItemNotFoundException - If an item with the specified ID is not found
PermissionDeniedException - If the logged in user doesn't have Permission.READ permission to the item
BaseException - If there is another error

getQuery

public static ItemQuery<User> getQuery()
Get a query configured to retrieve users. If the logged in user doesn't have generic permission to all users, only users that are members in at least one group where the logged in user is also a member are returned. The Everyone group is not considered since all users automatically are members to that group.

Returns:
An ItemQuery object

getType

public Item getType()
Description copied from interface: Identifiable
Get the type of item represented by the object. The returned value is one of the values defined in the Item enumeration.

Specified by:
getType in interface Identifiable
Returns:
A value indicating the type of item

getName

public String getName()
Description copied from interface: Nameable
Get the name of the item.

Specified by:
getName in interface Principal
Specified by:
getName in interface Nameable
Returns:
A String with the name of the item

setName

public void setName(String name)
             throws PermissionDeniedException,
                    InvalidDataException
Description copied from interface: Nameable
Set the name of the item. The name cannot be null and mustn't be longer than the value specified by the Nameable.MAX_NAME_LENGTH constant.

Specified by:
setName in interface Nameable
Parameters:
name - The new name for the item
Throws:
PermissionDeniedException - If the logged in user doesn't have write permission
InvalidDataException - If the name is null or longer than specified by the Nameable.MAX_NAME_LENGTH constant

getDescription

public String getDescription()
Description copied from interface: Nameable
Get the description for the item.

Specified by:
getDescription in interface Nameable
Returns:
A String with a description of the item

setDescription

public void setDescription(String description)
                    throws PermissionDeniedException,
                           InvalidDataException
Description copied from interface: Nameable
Set the description for the item. The description can be null but mustn't be longer than the value specified by the Nameable.MAX_DESCRIPTION_LENGTH constant.

Specified by:
setDescription in interface Nameable
Parameters:
description - The new description for the item
Throws:
PermissionDeniedException - If the logged in user doesn't have write permission
InvalidDataException - If the description longer than specified by the Nameable.MAX_DESCRIPTION_LENGTH constant

isRemoved

public boolean isRemoved()
Description copied from interface: Removable
Check if the removed flag is set for this item.

Specified by:
isRemoved in interface Removable
Returns:
TRUE if the item is flagged as removed, FALSE otherwise

setRemoved

public void setRemoved(boolean removed)
                throws PermissionDeniedException
Description copied from interface: Removable
Set the removed flag for this item.

Specified by:
setRemoved in interface Removable
Parameters:
removed - TRUE if the item should be flagged as removed, FALSE otherwise
Throws:
PermissionDeniedException - If the logged in user doesn't have Permission.DELETE permission for setting the flag to TRUE or Permission.WRITE permission for setting the flag to FALSE

getSystemId

public String getSystemId()
Description copied from interface: SystemItem
Get the system id for the item.

Specified by:
getSystemId in interface SystemItem
Returns:
The id of the item or null if it is not a system item

isSystemItem

public boolean isSystemItem()
Description copied from interface: SystemItem
Check if the item is a system item or not. A system item have a non-null value for the system id.

Specified by:
isSystemItem in interface SystemItem
Returns:
TRUE if this item is a system item, FALSE otherwise

isUsed

public boolean isUsed()
               throws BaseException
Checks if: A user can also be referenced from groups, roles, projects, item keys, sessions and settings, but those references are automatically deleted if the user is deleted and aren't inclued in this check.

Specified by:
isUsed in class BasicItem<UserData>
Returns:
TRUE if this item is used, FALSE otherwise
Throws:
BaseException

setPassword

public void setPassword(String password)
                 throws PermissionDeniedException,
                        InvalidDataException
Set the password. A null password is not allowed.

Throws:
PermissionDeniedException - If the logged in user doesn't have restricted_write permission
InvalidDataException - If the new password is null

setBase1Password

public void setBase1Password(String md5Password)
                      throws PermissionDeniedException,
                             BaseException
Set the encrypted password from Proteios 1. This method is only intended to be used from the migration application, and will throw a PermissionDeniedException unless the logged in user is the root and the user account is a newly created account.

Parameters:
md5Password - The MD5 password from a Proteios 1 installation
Throws:
PermissionDeniedException - If it is not a new user or root isn't logged in
BaseException

getExpirationDate

public Date getExpirationDate()
Get the expire date of the account. When the expiration date have been passed the user can't login. A null value indicates that the account will never expire.


setExpirationDate

public void setExpirationDate(Date expirationDate)
                       throws PermissionDeniedException
Sets the expiration date of the account. A null value indicates that the account will never expire.

Throws:
PermissionDeniedException - If the logged in user doesn't have write permission

isDisabled

public boolean isDisabled()
Check if this account has been disabled. It is not possible to login if the account is disabled.

Returns:
TRUE if the account is disabled, FALSE otherwise

setDisabled

public void setDisabled(boolean disabled)
                 throws PermissionDeniedException
Disables or enables the account.

Parameters:
disabled - TRUE to disabled the account, FALSE to enabled it
Throws:
PermissionDeniedException - If the logged in user doesn't have write permission
See Also:
isDisabled()

isMultiuserAccount

public boolean isMultiuserAccount()
Check if the user account is a multiuser account or not. Multiuser accounts don't have write permissions for contact information and settings.

Returns:
TRUE if the user account is a multiuser account, FALSE otherwise

setMultiuserAccount

public void setMultiuserAccount(boolean multiuserAccount)
                         throws PermissionDeniedException
Sets if the user account is multiuser account.

Throws:
PermissionDeniedException - If the logged in user doesn't have write permission

getExternalId

public String getExternalId()
Get the external id for the user account. The external id is intended to be used by external applications which need to synchronize data between the Proteios database and some external database. It is not used by the core.


setExternalId

public void setExternalId(String externalId)
                   throws PermissionDeniedException,
                          InvalidDataException,
                          BaseException
Set the external id for the user account.

Throws:
PermissionDeniedException - If the logged in user doesn't have write permission
InvalidDataException - If the new value is longer than MAX_EXTERNAL_ID_LENGTH
BaseException - If there is another error

getLogin

public String getLogin()
Get the login for the user account.


setLogin

public void setLogin(String login)
              throws PermissionDeniedException,
                     InvalidDataException
Set the login for the user account.

Throws:
PermissionDeniedException - If the logged in user doesn't have write permission
InvalidDataException - If the new value is null or longer than MAX_LOGIN_LENGTH

getOrganisation

public String getOrganisation()
Get the organisation this user works for, or null if unknown.


setOrganisation

public void setOrganisation(String organisation)
                     throws PermissionDeniedException,
                            InvalidDataException
Set the organisation this user works for, or null if unknown.

Throws:
PermissionDeniedException - If the logged in user doesn't have restricted write permission
InvalidDataException - If the new value is longer than MAX_ORGANISATION_LENGTH

getAddress

public String getAddress()
Get the address for the user, or null if unknown.


setAddress

public void setAddress(String address)
                throws PermissionDeniedException,
                       InvalidDataException
Set the address for the user, or null if unknown.

Throws:
PermissionDeniedException - If the logged in user doesn't have write permission
InvalidDataException - If the new value is longer than MAX_ADDRESS_LENGTH

getPhone

public String getPhone()
Get the phone number to the user, or null if unknown.


setPhone

public void setPhone(String phone)
              throws PermissionDeniedException,
                     InvalidDataException
Set the phone number to the user, or null if unknown.

Throws:
PermissionDeniedException - If the logged in user doesn't have write permission
InvalidDataException - If the new value is longer than MAX_PHONE_LENGTH

getFax

public String getFax()
Get the fax number to the user, or null if unknown.


setFax

public void setFax(String fax)
            throws PermissionDeniedException,
                   InvalidDataException
Set the fax number to the user, or null if unknown.

Throws:
PermissionDeniedException - If the logged in user doesn't have write permission
InvalidDataException - If the new value is longer than MAX_FAX_LENGTH

getEmail

public String getEmail()
Get the email address to the user, or null if unknown.


setEmail

public void setEmail(String email)
              throws PermissionDeniedException,
                     InvalidDataException
Set the email address to the user, or null if unknown.

Throws:
PermissionDeniedException - If the logged in user doesn't have write permission
InvalidDataException - If the new value is longer than MAX_EMAIL_LENGTH

getUrl

public String getUrl()
Get the URL to the user's homepage, or null if unknown.


setUrl

public void setUrl(String url)
            throws PermissionDeniedException,
                   InvalidDataException
Set the URL to the user's homepage, or null if unknown.

Throws:
PermissionDeniedException - If the logged in user doesn't have write permission
InvalidDataException - If the new value is longer than MAX_URL_LENGTH

getQuota

public Quota getQuota()
               throws PermissionDeniedException,
                      BaseException
Get the Quota that applies to the user.

Returns:
A Quota item
Throws:
PermissionDeniedException - If the logged in user doesn't have Permission.READ permission to the item
BaseException

setQuota

public void setQuota(Quota quota)
              throws PermissionDeniedException,
                     InvalidDataException
Set the quota for the user.

Parameters:
quota - The new Quota
Throws:
InvalidDataException - If the quota is null
PermissionDeniedException - If the logged in user doesn't have Permission.WRITE permission for the user or Permission.USE permission for the quota

getQuotaGroup

public Group getQuotaGroup()
                    throws PermissionDeniedException,
                           BaseException
Get the Group whose Quota also applies to the user.

Returns:
A Group item, or null if no group has been specified
Throws:
PermissionDeniedException - If the logged in user doesn't have Permission.READ permission to the item
BaseException

setQuotaGroup

public void setQuotaGroup(Group quotaGroup)
                   throws PermissionDeniedException
Set the group whose quota should be checked for disk consuming items.

Parameters:
quotaGroup - The new Group
Throws:
PermissionDeniedException - If the logged in user doesn't have Permission.WRITE permission for the user or Permission.USE permission for the group

getDiskUsage

public long getDiskUsage(QuotaType quotaType,
                         Location location)
                  throws BaseException
Get the used number of bytes for the specified quota type and location.

Parameters:
quotaType - The QuotaType
location - The location
Returns:
The number of bytes that have been used
Throws:
BaseException

getHomeDirectory

public Directory getHomeDirectory()
                           throws PermissionDeniedException,
                                  BaseException
Get the home Directory for this user.

Returns:
A Directory item, or null if no home directory has been specified
Throws:
PermissionDeniedException - If the logged in user doesn't have Permission.READ permission to the directory
BaseException

setHomeDirectory

public void setHomeDirectory(Directory homeDirectory)
                      throws PermissionDeniedException,
                             InvalidDataException
Set the home directory for the user.

Parameters:
homeDirectory - The new home Directory
Throws:
PermissionDeniedException - If the logged in user doesn't have Permission.WRITE permission for the user or Permission.USE permission for the directory
InvalidDataException - If the home directory is not a subdirectory to /root/home

getRoles

public ItemQuery<Role> getRoles()
Get a query that returns the roles where this user is a member. The query excludes roles that the logged in user doesn't have permission to read.

See Also:
Role.getQuery()

getGroups

public ItemQuery<Group> getGroups()
Get a query that returns the groups where this user is a member. The query excludes groups that the logged in user doesn't have permission to read.

See Also:
Group.getQuery()

getProjects

public ItemQuery<Project> getProjects()
Get a query that returns the projects where this user is a member. The query excludes projects that the logged in user doesn't have permission to read. The query doesn't include projects where this user is the owner.

See Also:
Project.getQuery()

getMessages

public ItemQuery<Message> getMessages()
Get a query that returns all messages for the user.

Returns:
An ItemQuery object
See Also:
Message.getQuery(User)

Last update: 2011-06-23