ccc.domain
Class UserEntity

java.lang.Object
  extended by ccc.domain.Entity
      extended by ccc.domain.Principal
          extended by ccc.domain.UserEntity
All Implemented Interfaces:
Jsonable, java.io.Serializable

public class UserEntity
extends Principal

A user of the CCC system. FIXME: email should never be NULL.

Author:
Civic Computing Ltd.
See Also:
Serialized Form

Field Summary
static UserEntity SYSTEM_USER
          SYSTEM_USER : User.
 
Constructor Summary
protected UserEntity()
          Constructor.
  UserEntity(Username username, java.lang.String passwordString)
          Constructor.
  UserEntity(Username username, java.lang.String name, java.lang.String passwordString)
          Constructor.
 
Method Summary
 void addGroup(GroupEntity group)
          Adds a user to a group.
 void addMetadata(java.util.Map<java.lang.String,java.lang.String> metadata)
          Add metadata to this resource.
 void addMetadatum(java.lang.String key, java.lang.String value)
          Add new metadata for this resource.
 void clearGroups()
          Mutator - clear all groups for this user.
 void clearMetadata()
          Remove all metadata for this resource.
 void clearMetadatum(java.lang.String key)
          Remove the metadatum with the specified key.
 EmailAddress getEmail()
          Accessor for the email property.
 java.util.Set<java.util.UUID> getGroupIds()
          Query - return the IDs for all groups this user is a member of.
 java.util.Set<GroupEntity> getGroups()
          Accessor for user groups.
 java.util.Map<java.lang.String,java.lang.String> getMetadata()
          Accessor for all metadata.
 java.lang.String getMetadatum(java.lang.String key)
          Retrieve metadata for this resource.
 byte[] getPassword()
          Accessor.
 java.util.Collection<java.lang.String> getPermissions()
          Query - determines all permissions available to this user.
 Username getUsername()
          Accessor for the username property.
 boolean hasPassword(java.lang.String passwordString)
          Compares hash of the passwordString to the field hash.
 boolean hasPermission(java.lang.String permission)
          Helper method to check if the user has the specified permission.
 boolean includes(UserEntity user)
          Check if the specified user is included by this principal.
static java.util.List<User> map(java.util.Collection<UserEntity> users)
          Create summaries for a list of users.
static boolean matches(byte[] expected, java.lang.String password, java.lang.String salt)
          Test whether a hash matches the specified password.
 void setEmail(EmailAddress email)
          Mutator for the user's email.
 void setPassword(java.lang.String passwordString)
          Mutator for the password.
 void setUsername(Username username)
          Mutator for the username.
 User toDto()
          Convert a user to a DTO.
 void toJson(Json json)
          Convert to JSON.
 
Methods inherited from class ccc.domain.Principal
getName, setName
 
Methods inherited from class ccc.domain.Entity
equals, getId, getVersion, hashCode, setId, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

SYSTEM_USER

public static final UserEntity SYSTEM_USER
SYSTEM_USER : User.

Constructor Detail

UserEntity

protected UserEntity()
Constructor. N.B. This constructor should only be used for persistence.


UserEntity

public UserEntity(Username username,
                  java.lang.String name,
                  java.lang.String passwordString)
Constructor.

Parameters:
username - The user's unique name within CCC.
name - The user's full name.
passwordString - The unhashed password as a string.

UserEntity

public UserEntity(Username username,
                  java.lang.String passwordString)
Constructor.

Parameters:
username - The user's unique name within CCC.
passwordString - The unhashed password as a string.
Method Detail

getUsername

public Username getUsername()
Accessor for the username property.

Returns:
The username.

setUsername

public void setUsername(Username username)
Mutator for the username.

Parameters:
username - The username.

setEmail

public void setEmail(EmailAddress email)
Mutator for the user's email.

Parameters:
email - The email.

getEmail

public EmailAddress getEmail()
Accessor for the email property.

Returns:
The email as a string.

addGroup

public void addGroup(GroupEntity group)
Adds a user to a group.

Parameters:
group - The group to assign.

hasPermission

public boolean hasPermission(java.lang.String permission)
Helper method to check if the user has the specified permission.

Parameters:
permission - The permission to be checked.
Returns:
True if the user has the permission.

getGroups

public java.util.Set<GroupEntity> getGroups()
Accessor for user groups.

Returns:
Groups of the user.

addMetadatum

public void addMetadatum(java.lang.String key,
                         java.lang.String value)
Add new metadata for this resource.

Parameters:
key - The key by which the datum will be accessed.
value - The value of the datum. May not be NULL.

getMetadatum

public java.lang.String getMetadatum(java.lang.String key)
Retrieve metadata for this resource.

Parameters:
key - The key with which the datum was stored.
Returns:
The value of the datum. NULL if the datum doesn't exist.

clearMetadatum

public void clearMetadatum(java.lang.String key)
Remove the metadatum with the specified key.

Parameters:
key - The key with which the datum was stored.

getMetadata

public java.util.Map<java.lang.String,java.lang.String> getMetadata()
Accessor for all metadata.

Returns:
The metadata as a hash map.

clearMetadata

public void clearMetadata()
Remove all metadata for this resource.


addMetadata

public void addMetadata(java.util.Map<java.lang.String,java.lang.String> metadata)
Add metadata to this resource.

Parameters:
metadata - The metadata to add, as a hashmap.

setPassword

public void setPassword(java.lang.String passwordString)
Mutator for the password.

Parameters:
passwordString - The new password.

hasPassword

public boolean hasPassword(java.lang.String passwordString)
Compares hash of the passwordString to the field hash.

Parameters:
passwordString - The unhashed password as a string.
Returns:
True if passwordString's hash matches.

matches

public static boolean matches(byte[] expected,
                              java.lang.String password,
                              java.lang.String salt)
Test whether a hash matches the specified password.

Parameters:
expected - The expected hash.
password - The password to test.
salt - The salt to use.
Returns:
True if the hashed password matches the expected hash; false otherwise.

toJson

public void toJson(Json json)
Convert to JSON.

Specified by:
toJson in interface Jsonable
Overrides:
toJson in class Entity
Parameters:
json - The JSON object to write to.

getGroupIds

public java.util.Set<java.util.UUID> getGroupIds()
Query - return the IDs for all groups this user is a member of.

Returns:
The group IDs, as a set.

clearGroups

public void clearGroups()
Mutator - clear all groups for this user.


toDto

public User toDto()
Convert a user to a DTO.

Returns:
A DTO representation of this user.

getPermissions

public java.util.Collection<java.lang.String> getPermissions()
Query - determines all permissions available to this user.

Returns:
The collection of permissions.

map

public static java.util.List<User> map(java.util.Collection<UserEntity> users)
Create summaries for a list of users.

Parameters:
users - The users.
Returns:
The corresponding summaries.

includes

public boolean includes(UserEntity user)
Check if the specified user is included by this principal.

Specified by:
includes in class Principal
Parameters:
user - The user to check.
Returns:
True if the user is included; false otherwise.

getPassword

public byte[] getPassword()
Accessor.

Returns:
The user's password.


Copyright © 2010. All Rights Reserved.