pulse - the web application framework Get pulse at SourceForge.net. Fast, secure and Free Open Source software downloads Ohloh project report for pulse-java

org.torweg.pulse.accesscontrol
Class User

java.lang.Object
  extended by org.torweg.pulse.util.entity.AbstractBasicEntity
      extended by org.torweg.pulse.util.entity.AbstractNamedEntity
          extended by org.torweg.pulse.util.entity.AbstractNamableEntity
              extended by org.torweg.pulse.accesscontrol.AbstractAccessControlObject
                  extended by org.torweg.pulse.accesscontrol.AbstractUserBase
                      extended by org.torweg.pulse.accesscontrol.User
All Implemented Interfaces:
java.io.Serializable, JDOMable, INameable, INamed
Direct Known Subclasses:
User.Everybody

@Entity
public class User
extends AbstractUserBase
implements INameable

A User is an entity representing a user in the pulse container.

Every User consists of a unique name and a password that are both used for authentication.

Version:
$Revision: 2032 $
Author:
Thomas Weber, Christian Schatt, Daniel Dietz
See Also:
Serialized Form

Nested Class Summary
static class User.Everybody
          is a dummy User used for non-logged-in users to provide them the "~Everybody" Role for access checks.
static class User.State
          the state of the User.
 
Field Summary
 
Fields inherited from class org.torweg.pulse.accesscontrol.AbstractUserBase
EVERYBODY, PASSWORD_CHARACTERS
 
Constructor Summary
protected User()
          Deprecated. 
  User(PreliminaryUser p)
          creates a new User from a given PreliminaryUser .
  User(java.lang.String newName, java.lang.String newEmail, java.lang.String newPassword)
          The Constructor that sets name, email-address and password of the User.
 
Method Summary
protected  boolean addAttribute(UserAttribute att)
          sets an attribute of the User.
 boolean addGroup(Group grp)
          Adds a Group to the User's Set of Groups.
 boolean addPermission(Permission permission)
          Adds a Permission to the User's Set of Permissions.
 boolean addPersistentRole(Role rl)
          Adds a Role to the User's Set of Roles.
 boolean addSessionRole(Role rl)
          Adds a Role to the User's Set of Session -valid-only Roles.
 boolean checkPassword(java.lang.String pwd)
          Checks if a String pwd is equal to the User's password.
protected  void clearAttributes()
          clears all attributes of the User.
 org.jdom.Element deserializeToJDOM()
          Serializes the state of the User as a JDOM Element.
 org.jdom.Element deserializeToJDOMShallow()
          serialises the User without Group, Role, Permission and Attribute information.
 boolean expunge()
          expunges the User.
 java.util.Set<UserAttribute> getAttributes()
          Deprecated. 
 AbstractValue<?> getAttributeValue(AbstractAttribute<?> a)
          returns the user's value for the given attribute, or null, if the user does not have a stored value for the given attribute.
 java.util.Set<? extends AbstractValue<?>> getAttributeValues()
          returns the user's values.
 java.lang.String getEmail()
          Returns the email-address of the User.
 java.util.Set<Group> getGroups()
          Returns a shallow copy of the User's Collection of Groups.
 java.util.Date getLastLoginTime()
          Returns the Date indicating the last login time of the User.
 java.lang.String getPassword()
          returns the digested password.
 java.util.Set<Permission> getPermissions()
          Returns a shallow copy of the User's Collection of Permissions.
 java.util.Set<Role> getPersistentRoles()
          Returns a shallow copy of the User's Collection of Roles.
 java.util.Set<Role> getRoles()
          Returns all Roles associated with the current User, which can be Session-valid-only Roles as well as the persisted Roles.
 java.util.Set<Role> getSessionRoles()
           
 java.util.Locale getSignUpLocale()
          returns the sign-up locale.
 boolean hasAllowanceFor(Command command)
          Checks if the associated User has the necessary Permissions for executing a Command.
 boolean hasAllowanceFor(SitemapNode node)
          Checks if the associated User has the necessary Roles for accessing a SitemapNode.
 java.lang.Boolean isActive()
          Returns the active-flag of the User.
 boolean isExpunged()
          returns whether the User is expunged.
 java.lang.Boolean isSuperuser()
          Returns the superuser-flag of the User.
 boolean isWebdavEnabled()
          returns whether the user is enabled for WebDAV.
protected  boolean removeAttribute(UserAttribute att)
          removes an attribute from the User.
 AbstractValue<?> removeAttributeValue(AbstractAttribute<?> a)
          removes the value of a given attribute form the user.
 boolean removeGroup(Group grp)
          Removes a Group from the User's Set of Groups if it is part of it.
 boolean removePermission(Permission permission)
          Removes a Permission from the User's Set of Permissions if it is part of it.
 boolean removePersistentRole(Role rl)
          Removes a Role from the User's Set of Roles if it is part of it.
 boolean removeSessionRole(Role rl)
          Removes a Role from the User's Set of Session-valid-only Roles if it is part of it.
 void setAttributeValue(AbstractValue<?> v)
          sets the given value for the user.
 void setEmail(java.lang.String newEmail)
          Sets the email-address of the User.
 void setLastLoginTime()
          Sets the Date indicating the last login time of the User to the present moment.
 void setLastModificationTime()
          Sets the Date indicating the last modification time of the User to the present moment.
 void setName(java.lang.String newName)
          Sets the name of the User.
 void setPassword(java.lang.String newPassword)
          Sets the password of the User.
 void setSignUpLocale(java.util.Locale l)
          sets the sign-up locale.
 void setSuperuser(java.lang.Boolean newFlag)
          Sets the superuser-flag of the User.
 void setWebdavEnabled(boolean b)
          sets whether the user is enabled for WebDAV.
 void toggleActive()
          Toggles the active-flag of the User.
 net.sf.json.JSONObject toJSON()
          Serialises the state of the User as a JSONObject.
 
Methods inherited from class org.torweg.pulse.accesscontrol.AbstractUserBase
generatePassword, generateToken, getCommandMatchers, getEveryBodyId, getEverybodyRole, getSuperUser, getUser, getUser, initEverybodyRole
 
Methods inherited from class org.torweg.pulse.accesscontrol.AbstractAccessControlObject
getAssociatedAbstractAccessControlObjects, getLoadCriteriaForClassWithAlias
 
Methods inherited from class org.torweg.pulse.util.entity.AbstractNamedEntity
getName
 
Methods inherited from class org.torweg.pulse.util.entity.AbstractBasicEntity
compareTo, equals, getFullQualifiedClassNameJAXB, getId, hashCode
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.torweg.pulse.util.INamed
getName
 

Constructor Detail

User

@Deprecated
protected User()
Deprecated. 

used for HibernateTM.


User

public User(java.lang.String newName,
            java.lang.String newEmail,
            java.lang.String newPassword)
The Constructor that sets name, email-address and password of the User.

Parameters:
newName - the name of the User
newEmail - the email-address of the User
newPassword - the password of the User

User

public User(PreliminaryUser p)
creates a new User from a given PreliminaryUser .

Parameters:
p - the preliminary user
Method Detail

setName

public final void setName(java.lang.String newName)
Sets the name of the User.

Specified by:
setName in interface INameable
Overrides:
setName in class AbstractNamableEntity
Parameters:
newName - the new name of the User
See Also:
INameable.setName(java.lang.String)

getEmail

public final java.lang.String getEmail()
Returns the email-address of the User.

Returns:
the email-address of the User

setEmail

public final void setEmail(java.lang.String newEmail)
Sets the email-address of the User.

Parameters:
newEmail - the new email-address of the User

checkPassword

public final boolean checkPassword(java.lang.String pwd)
Checks if a String pwd is equal to the User's password.

Parameters:
pwd - the String used for the equality check
Returns:
true if the String pwd is equal to the User's password

getPassword

public final java.lang.String getPassword()
returns the digested password.

Returns:
the digested password

setPassword

public final void setPassword(java.lang.String newPassword)
Sets the password of the User.

Parameters:
newPassword - the new password of the User

isSuperuser

public final java.lang.Boolean isSuperuser()
Returns the superuser-flag of the User.

Returns:
the superuser-flag of the User

setSuperuser

public final void setSuperuser(java.lang.Boolean newFlag)
Sets the superuser-flag of the User.

Parameters:
newFlag - the new superuser-flag of the User

isActive

public final java.lang.Boolean isActive()
Returns the active-flag of the User.

Returns:
the active-flag of the User

toggleActive

public final void toggleActive()
Toggles the active-flag of the User.


isExpunged

public final boolean isExpunged()
returns whether the User is expunged.

Returns:
true, if the User is expunged

expunge

public final boolean expunge()
expunges the User.

Returns:
true, if and only if the User could be expunged. Otherwise false.

setLastModificationTime

public final void setLastModificationTime()
Sets the Date indicating the last modification time of the User to the present moment.


getLastLoginTime

public java.util.Date getLastLoginTime()
Returns the Date indicating the last login time of the User.

Returns:
the Date indicating the last login time of the User

setLastLoginTime

public final void setLastLoginTime()
Sets the Date indicating the last login time of the User to the present moment.


getGroups

public final java.util.Set<Group> getGroups()
Returns a shallow copy of the User's Collection of Groups.

Attention: Since the returned Set is not a reference to the User's internal Collection, any modifications to its state will get lost. However, modifications to the state of the Set's elements will be consistent.

For example: Adding/Deleting a Group to/from the Set will not have any effect, when the User is saved. On the other hand, modifications to a Group in the Set will be made persistent, when the Group is saved.

Returns:
the Groups associated with the User

addGroup

public final boolean addGroup(Group grp)
Adds a Group to the User's Set of Groups. If it already is part of the Set, it will not be added.

Parameters:
grp - the Group to be added
Returns:
true if the Set changed as a result of the call

removeGroup

public final boolean removeGroup(Group grp)
Removes a Group from the User's Set of Groups if it is part of it.

Parameters:
grp - the Group to be removed
Returns:
true if the Set changed as a result of the call

getPermissions

public final java.util.Set<Permission> getPermissions()
Returns a shallow copy of the User's Collection of Permissions.

Attention: Since the returned Set is not a reference to the User's internal Collection, any modifications to its state will get lost. However, modifications to the state of the Set's elements will be consistent.

For example: Adding/Deleting a Permission to/from the Set will not have any effect, when the User is saved. On the other hand, modifications to a Permission in the Set will be made persistent, when the Permission is saved.

Returns:
the Permissions associated with the User

addPermission

public final boolean addPermission(Permission permission)
Adds a Permission to the User's Set of Permissions. If it already is part of the Set, it will not be added.

Parameters:
permission - the Permission to be added
Returns:
true if the Set changed as a result of the call

removePermission

public final boolean removePermission(Permission permission)
Removes a Permission from the User's Set of Permissions if it is part of it.

Parameters:
permission - the Permission to be removed
Returns:
true if the Set changed as a result of the call

getRoles

public final java.util.Set<Role> getRoles()
Returns all Roles associated with the current User, which can be Session-valid-only Roles as well as the persisted Roles.

Returns:
all Roles associated with the User which are getPersistentRoles() + getSessionRoles()

getPersistentRoles

public final java.util.Set<Role> getPersistentRoles()
Returns a shallow copy of the User's Collection of Roles.

Attention: Since the returned Set is not a reference to the User's internal Collection, any modifications to its state will get lost. However, modifications to the state of the Set's elements will be consistent.

For example: Adding/Deleting a Role to/from the Set will not have any effect, when the User is saved. On the other hand, modifications to a Role in the Set will be made persistent, when the Role is saved.

Returns:
the Roles associated with the User

addPersistentRole

public final boolean addPersistentRole(Role rl)
Adds a Role to the User's Set of Roles. If it already is part of the Set, it will not be added.

Parameters:
rl - the Role to be added
Returns:
true if the Set changed as a result of the call

removePersistentRole

public final boolean removePersistentRole(Role rl)
Removes a Role from the User's Set of Roles if it is part of it.

Parameters:
rl - the Role to be removed
Returns:
true if the Set changed as a result of the call

getSessionRoles

public final java.util.Set<Role> getSessionRoles()
Returns:
the Roles associated with the User for the current Session

addSessionRole

public final boolean addSessionRole(Role rl)
Adds a Role to the User's Set of Session -valid-only Roles. If it already is part of the Set, it will not be added.

Parameters:
rl - the Role to be added
Returns:
true if the Set changed as a result of the call

removeSessionRole

public final boolean removeSessionRole(Role rl)
Removes a Role from the User's Set of Session-valid-only Roles if it is part of it.

Parameters:
rl - the Role to be removed
Returns:
true if the Set changed as a result of the call

isWebdavEnabled

public final boolean isWebdavEnabled()
returns whether the user is enabled for WebDAV.

Returns:
whether the user is enabled for WebDAV

setWebdavEnabled

public final void setWebdavEnabled(boolean b)
sets whether the user is enabled for WebDAV.

Parameters:
b - the value to set

getAttributeValues

public final java.util.Set<? extends AbstractValue<?>> getAttributeValues()
returns the user's values.

Returns:
the attribute's value or empty Set&lt;AbstractValue&gt;

getAttributeValue

public final AbstractValue<?> getAttributeValue(AbstractAttribute<?> a)
returns the user's value for the given attribute, or null, if the user does not have a stored value for the given attribute.

Parameters:
a - the attribute
Returns:
the attribute's value or null

setAttributeValue

public final void setAttributeValue(AbstractValue<?> v)
sets the given value for the user.

Parameters:
v - the value to set

removeAttributeValue

public final AbstractValue<?> removeAttributeValue(AbstractAttribute<?> a)
removes the value of a given attribute form the user.

Parameters:
a - the attribute
Returns:
either the removed value or null

hasAllowanceFor

public final boolean hasAllowanceFor(Command command)
Checks if the associated User has the necessary Permissions for executing a Command.

Parameters:
command - the Command defining the necessary Permissions
Returns:
true if the associated User has the necessary Permissions

hasAllowanceFor

public final boolean hasAllowanceFor(SitemapNode node)
Checks if the associated User has the necessary Roles for accessing a SitemapNode.

Parameters:
node - the node to check against
Returns:
true, if either the node is null, the node has no roles or the user does contain at least one of the roles attached. Otherwise false.

getAttributes

@Deprecated
public final java.util.Set<UserAttribute> getAttributes()
Deprecated. 

returns the attributes of the User.

Returns:
the attributes of the User

addAttribute

protected final boolean addAttribute(UserAttribute att)
sets an attribute of the User.

Parameters:
att - the attribute to be set
Returns:
true, if and only if, the attribute was successfully set

removeAttribute

protected final boolean removeAttribute(UserAttribute att)
removes an attribute from the User.

Parameters:
att - the attribute to be removed
Returns:
true, if and only if, the attribute was successfully removed

clearAttributes

protected final void clearAttributes()
clears all attributes of the User.


deserializeToJDOM

public final org.jdom.Element deserializeToJDOM()
Serializes the state of the User as a JDOM Element.

Specified by:
deserializeToJDOM in interface JDOMable
Returns:
the state of the User as a JDOM Element

getSignUpLocale

public final java.util.Locale getSignUpLocale()
returns the sign-up locale.

Returns:
the sign-up locale

setSignUpLocale

public final void setSignUpLocale(java.util.Locale l)
sets the sign-up locale.

Parameters:
l - the locale

deserializeToJDOMShallow

public final org.jdom.Element deserializeToJDOMShallow()
serialises the User without Group, Role, Permission and Attribute information.

Returns:
the user without group, role, permission and attribute information as a JDOM element.

toJSON

public final net.sf.json.JSONObject toJSON()
Serialises the state of the User as a JSONObject.

Overrides:
toJSON in class AbstractAccessControlObject
Returns:
the state of the User as a JSONObject