br.com.arsmachina.authentication.entity
Class User

java.lang.Object
  extended by br.com.arsmachina.authentication.entity.User
All Implemented Interfaces:
Serializable, Comparable<User>

public final class User
extends Object
implements Comparable<User>, Serializable

Class that represents an application user. Each user can belong to any number of Permissions. When a given user belongs to a Permission, but cannot be granted some Permission in that group, this permission must be added to the list of removed permissions (removedPermissions property).

Author:
Thiago H. de Paula Figueiredo
See Also:
Serialized Form

Field Summary
static int MAXIMUM_EMAIL_LENGTH
          Minimum e-mail length.
static int MAXIMUM_LOGIN_LENGTH
          Maximum e-mail length.
static int MAXIMUM_NAME_LENGTH
          Maximum name length.
static int MAXIMUM_PASSWORD_LENGTH
          Maximum name length.
static int MINIMUM_EMAIL_LENGTH
          Minimum e-mail length.
static int MINIMUM_LOGIN_LENGTH
          Minimum login length.
static int MINIMUM_NAME_LENGTH
          Minimum name length.
static int MINIMUM_PASSWORD_LENGTH
          Minimum name length.
 
Constructor Summary
User()
           
 
Method Summary
 void add(PermissionGroup permissionGroup)
          Adds a permission group to this user.
 void add(Role role)
          Adds a role to this user.
 void addRemovedPermission(Permission permission)
          Adds a removed permission to this user.
 int compareTo(User o)
           
 boolean equals(Object obj)
           
 String getEmail()
          Returns the value of the email property.
 Integer getId()
          Returns the value of the id property.
 String getLogin()
          Returns the value of the login property.
 String getName()
          Returns the value of the name property.
 String getPassword()
          Returns the value of the password property.
 List<PermissionGroup> getPermissionGroups()
          Returns the value of the permissionGroups property.
 List<Permission> getPermissions()
          Returns an unmodifiable list containing all the permissions granted to this user.
 List<Permission> getRemovedPermissions()
          Returns the value of the removedPermissions property.
<T extends Role>
T
getRole(Class<T> clasz)
          Given a Class object, returns the corresponding Role instance or null if this user has no such role.
 List<Role> getRoles()
          Returns the value of the roles property.
 int hashCode()
           
<R extends Role>
boolean
hasRole(Class<R> roleClass)
          Tells if this user has some a given role type.
 boolean isCredentialsExpired()
          Is this user's credentials expired?
 boolean isEnabled()
          Is this user's account enabled?.
 boolean isExpired()
          Is this user's account expired?
 boolean isLocked()
          Is this user's account locked?
 boolean isLoggedIn()
          Is this user's logged in now?
 void remove(PermissionGroup permissionGroup)
          Removes a permission group from this user.
 void remove(Role role)
          Removes a role from this user.
 void removeRemovedPermission(Permission permission)
          Removes a removed permission from this user.
<T extends Role>
void
removeRole(Class<T> roleClass)
          Removes all roles from a given type from this user.
 void setCredentialsExpired(boolean credentialsExpired)
          Changes the value of the credentialsExpired property.
 void setEmail(String email)
          Changes the value of the email property.
 void setEnabled(boolean enabled)
          Changes the value of the enabled property.
 void setExpired(boolean accountExpired)
          Changes the value of the expired property.
 void setId(Integer id)
          Changes the value of the id property.
 void setLocked(boolean accountLocked)
          Changes the value of the locked property.
 void setLoggedIn(boolean loggedIn)
          Changes the value of the loggedIn property.
 void setLogin(String login)
          Changes the value of the login property.
 void setName(String name)
          Changes the value of the name property.
 void setPassword(String password)
          Changes the value of the password property.
 void setPermissionGroups(List<PermissionGroup> permissionGroups)
          Deprecated. Use add(PermissionGroup) and remove(PermissionGroup) instead.
 void setRemovedPermissions(List<Permission> removedRoles)
          Deprecated. Use addRemovedPermission(Permission) and #removeRemovedPermisson(Permission) instead.
 void setRoles(List<Role> roles)
          Deprecated. Use add(Role) and remove(Role) instead.
 String toString()
          Returns the name property.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MINIMUM_EMAIL_LENGTH

public static final int MINIMUM_EMAIL_LENGTH
Minimum e-mail length.

See Also:
Constant Field Values

MAXIMUM_EMAIL_LENGTH

public static final int MAXIMUM_EMAIL_LENGTH
Minimum e-mail length.

See Also:
Constant Field Values

MINIMUM_LOGIN_LENGTH

public static final int MINIMUM_LOGIN_LENGTH
Minimum login length.

See Also:
Constant Field Values

MAXIMUM_LOGIN_LENGTH

public static final int MAXIMUM_LOGIN_LENGTH
Maximum e-mail length.

See Also:
Constant Field Values

MINIMUM_NAME_LENGTH

public static final int MINIMUM_NAME_LENGTH
Minimum name length.

See Also:
Constant Field Values

MAXIMUM_NAME_LENGTH

public static final int MAXIMUM_NAME_LENGTH
Maximum name length.

See Also:
Constant Field Values

MINIMUM_PASSWORD_LENGTH

public static final int MINIMUM_PASSWORD_LENGTH
Minimum name length.

See Also:
Constant Field Values

MAXIMUM_PASSWORD_LENGTH

public static final int MAXIMUM_PASSWORD_LENGTH
Maximum name length.

See Also:
Constant Field Values
Constructor Detail

User

public User()
Method Detail

add

public void add(PermissionGroup permissionGroup)
Adds a permission group to this user.

Parameters:
permissionGroup - a PermissionGroup.

add

public void add(Role role)
Adds a role to this user.

Parameters:
role - a Role.

hasRole

public <R extends Role> boolean hasRole(Class<R> roleClass)
Tells if this user has some a given role type.

Type Parameters:
R - a Role subclass.
Parameters:
roleClass - a Class.
Returns:
a boolean.

addRemovedPermission

public void addRemovedPermission(Permission permission)
Adds a removed permission to this user.

Parameters:
permission - a PermissionGroup.

compareTo

public int compareTo(User o)
Specified by:
compareTo in interface Comparable<User>
See Also:
Comparable.compareTo(java.lang.Object)

equals

public boolean equals(Object obj)
Overrides:
equals in class Object
See Also:
Object.equals(java.lang.Object)

getEmail

@Email
@Length(min=3,
        max=50)
public String getEmail()
Returns the value of the email property.

Returns:
a String.

getId

public Integer getId()
Returns the value of the id property.

Returns:
a Integer.

getLogin

@NotNull
@Length(min=2,
        max=50)
public String getLogin()
Returns the value of the login property.

Returns:
a String.

getName

@NotNull
@Length(min=2,
        max=50)
public String getName()
Returns the value of the name property.

Returns:
a String.

getPassword

@NotNull
@Length(min=6,
        max=40)
public String getPassword()
Returns the value of the password property.

Returns:
a String.

getPermissionGroups

public List<PermissionGroup> getPermissionGroups()
Returns the value of the permissionGroups property.

Returns:
a List.

getPermissions

public final List<Permission> getPermissions()
Returns an unmodifiable list containing all the permissions granted to this user. It is comprised by the sum of all permissions in its permission groups, except the ones in its removed permissions list.

Returns:
a List of Permissions.

getRemovedPermissions

public List<Permission> getRemovedPermissions()
Returns the value of the removedPermissions property.

Returns:
a List.

getRole

public final <T extends Role> T getRole(Class<T> clasz)
Given a Class object, returns the corresponding Role instance or null if this user has no such role.

Type Parameters:
T - a Role subclass.
Parameters:
clasz - a Class.
Returns:
a #T.

getRoles

public List<Role> getRoles()
Returns the value of the roles property.

Returns:
a List.

hashCode

public int hashCode()
Overrides:
hashCode in class Object
See Also:
Object.hashCode()

isCredentialsExpired

public boolean isCredentialsExpired()
Is this user's credentials expired?

Returns:
a boolean.

isEnabled

public boolean isEnabled()
Is this user's account enabled?.

Returns:
a boolean.

isExpired

public boolean isExpired()
Is this user's account expired?

Returns:
a boolean.

isLocked

public boolean isLocked()
Is this user's account locked?

Returns:
a boolean.

isLoggedIn

public boolean isLoggedIn()
Is this user's logged in now?

Returns:
a boolean.

remove

public void remove(Role role)
Removes a role from this user.

Parameters:
role - a Role.

removeRole

public <T extends Role> void removeRole(Class<T> roleClass)
Removes all roles from a given type from this user.

Parameters:
roleClass - a Class.

remove

public void remove(PermissionGroup permissionGroup)
Removes a permission group from this user.

Parameters:
permissionGroup - a PermissionGroup.

removeRemovedPermission

public void removeRemovedPermission(Permission permission)
Removes a removed permission from this user.

Parameters:
permission - a Permission.

setCredentialsExpired

public void setCredentialsExpired(boolean credentialsExpired)
Changes the value of the credentialsExpired property.

Parameters:
credentialsExpired - a boolean.

setEmail

public void setEmail(String email)
Changes the value of the email property.

Parameters:
email - a String.

setEnabled

public void setEnabled(boolean enabled)
Changes the value of the enabled property.

Parameters:
enabled - a boolean.

setExpired

public void setExpired(boolean accountExpired)
Changes the value of the expired property.

Parameters:
expired - a boolean.

setId

public void setId(Integer id)
Changes the value of the id property.

Parameters:
id - a Integer.

setLocked

public void setLocked(boolean accountLocked)
Changes the value of the locked property.

Parameters:
locked - a boolean.

setLoggedIn

public void setLoggedIn(boolean loggedIn)
Changes the value of the loggedIn property.

Parameters:
loggedIn - a boolean.

setLogin

public void setLogin(String login)
Changes the value of the login property.

Parameters:
login - a String.

setName

public void setName(String name)
Changes the value of the name property.

Parameters:
name - a String.

setPassword

public void setPassword(String password)
Changes the value of the password property.

Parameters:
password - a String.

setPermissionGroups

@Deprecated
public void setPermissionGroups(List<PermissionGroup> permissionGroups)
Deprecated. Use add(PermissionGroup) and remove(PermissionGroup) instead.

Changes the value of the permissionGroups property.

Parameters:
permissionGroups - a List.

setRemovedPermissions

@Deprecated
public void setRemovedPermissions(List<Permission> removedRoles)
Deprecated. Use addRemovedPermission(Permission) and #removeRemovedPermisson(Permission) instead.

Changes the value of the removedPermissions property.

Parameters:
removedPermissions - a List.

setRoles

@Deprecated
public void setRoles(List<Role> roles)
Deprecated. Use add(Role) and remove(Role) instead.

Changes the value of the roles property.

Parameters:
roles - a List.

toString

public String toString()
Returns the name property.

Overrides:
toString in class Object
Returns:
a String.


Copyright © 2008-2009 Thiago H. de Paula Figueiredo. All Rights Reserved.