org.marketcetera.ors.security
Class SimpleUser

java.lang.Object
  extended by org.marketcetera.persist.EntityBase
      extended by org.marketcetera.persist.NDEntityBase
          extended by org.marketcetera.ors.security.SimpleUser
All Implemented Interfaces:
Serializable, SummaryEntityBase, SummaryNDEntityBase

public class SimpleUser
extends NDEntityBase

A user that can logon to the message bus used by the system. Each user has a name, description and password.

Every user needs to have a non-empty name and password. The password is saved as hashed value created from both the name and password value. The user name needs to be set before the password is set. If the user name is changed, user's password is unset.

Author:
anshul@marketcetera.com
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.marketcetera.persist.NDEntityBase
ATTRIBUTE_DESCRIPTION, ATTRIBUTE_NAME
 
Fields inherited from class org.marketcetera.persist.EntityBase
ATTRIBUTE_ID, ATTRIBUTE_LAST_UPDATED, UNINITIALIZED
 
Constructor Summary
SimpleUser()
           
 
Method Summary
 void changePassword(char[] originalPassword, char[] newPassword)
          Changes the user's password after validating the supplied password.
 void delete()
          Deletes the user from the database.
 String getSystemData()
          Gets the system data as a String.
 String getUserData()
          Gets the user data as a String.
 UserID getUserID()
          The UserID of this user.
 boolean isActive()
          The active flag of this user.
 boolean isPasswordSet()
          Returns true if the user password is set.
 boolean isSuperuser()
          The superuser flag of this user.
 void save()
          Saves the user to the database.
 void setActive(boolean active)
          Set the active flag for this user.
 void setName(String name)
          Sets the user name.
 void setPassword(char[] password)
          Sets the user's password.
 void setSuperuser(boolean superuser)
          Set the superuser flag for this user.
 void setSystemData(String inSystemData)
          Sets the system data.
 void setUserData(String inUserData)
          Sets the user data.
 void validate()
          Validates if the attributes of this instance are valid to attempt a save operation.
 void validatePassword(char[] password)
          Verifies if the supplied password matches the configured password for the user.
 
Methods inherited from class org.marketcetera.persist.NDEntityBase
getDescription, getName, setDescription, toString
 
Methods inherited from class org.marketcetera.persist.EntityBase
applyRemote, createSaveResult, deleteLocal, deleteRemote, executeRemote, getId, getLastUpdated, getUpdateCount, isPersistent, postSaveLocal, preSaveLocal, saveLocal, saveRemote, setId, setUpdateCount
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.marketcetera.persist.SummaryEntityBase
getId, getLastUpdated, getUpdateCount
 

Constructor Detail

SimpleUser

public SimpleUser()
Method Detail

isSuperuser

public boolean isSuperuser()
The superuser flag of this user.

Returns:
The flag.

setSuperuser

public void setSuperuser(boolean superuser)
Set the superuser flag for this user.

Parameters:
superuser - the superuser flag for this user.

isActive

public boolean isActive()
The active flag of this user.

Returns:
The flag.

setActive

public void setActive(boolean active)
Set the active flag for this user.

Parameters:
active - the active flag for this user.

getUserData

public String getUserData()
Gets the user data as a String.

Returns:
a String value or null

setUserData

public void setUserData(String inUserData)
Sets the user data.

Parameters:
inUserData - a String value

getSystemData

public String getSystemData()
Gets the system data as a String.

Returns:
a String value or null

setSystemData

public void setSystemData(String inSystemData)
Sets the system data.

Parameters:
inSystemData - a String value

getUserID

public UserID getUserID()
The UserID of this user.

Returns:
The UserID.

isPasswordSet

public boolean isPasswordSet()
Returns true if the user password is set.

Returns:
true if the user password is set.

setName

public void setName(String name)
Sets the user name. The user password is emptied whenever the user name is modified. Make sure to the set the user password before attempting to save the user.

Overrides:
setName in class NDEntityBase
Parameters:
name - the user name

setPassword

public void setPassword(char[] password)
                 throws ValidationException
Sets the user's password. The user name should be set to a non-empty value before this method is invoked This method can be used to set the password when the current user password is empty. The user password is empty for a newly created user or a user who's name has been reset via setName(String)

Parameters:
password - The user password value, cannot be null.
Throws:
ValidationException - If the user password is already set, or if an empty password is supplied or if the user name is not set.

changePassword

public void changePassword(char[] originalPassword,
                           char[] newPassword)
                    throws ValidationException
Changes the user's password after validating the supplied password.

Parameters:
originalPassword - the original password. This password should match the currently configured password.

The new password is not saved to the database. To save the new password to the database, invoke save()

newPassword - the new password, cannot be empty.
Throws:
ValidationException - if there were errors validating the original or the new password password.

validatePassword

public void validatePassword(char[] password)
                      throws ValidationException
Verifies if the supplied password matches the configured password for the user. If no nonempty password is presently configured, validation succeeds regardless of the supplied password; this provides a back-door to address forgotten password problems, wherein an admin can modify the database directly and empty out the present password.

Parameters:
password - the password to test.
Throws:
ValidationException - If a nonempty password is presently configured and either an empty password value was specified, or the specified password doesn't match the currently configured user password.

validate

public void validate()
              throws PersistenceException
Validates if the attributes of this instance are valid to attempt a save operation.

This method validates if the user name is non-empty, contains only letters, numbers and space characters, and is less than 256 characters in length.

This method validates if the user password is non-empty.

Overrides:
validate in class NDEntityBase
Throws:
PersistenceException - if there were validation failures

save

public void save()
          throws PersistenceException
Saves the user to the database.

Throws:
ValidationException - if validation failed when saving the user.
EntityExistsException - if a user with the supplied name already exists in the database.
PersistenceException - If there were errors saving the user to the database.

delete

public void delete()
            throws PersistenceException
Deletes the user from the database. After a user is deleted, any attempt to login as that user fails. Do note that deleting a user will not force logout the user from the system.

Throws:
PersistenceException - if there were errors deleting the user


Copyright © 2012. All Rights Reserved.