SPT Core API

com.sptci.jdo
Class User

java.lang.Object
  extended by com.sptci.jdo.JDOObject
      extended by com.sptci.jdo.User
All Implemented Interfaces:
Serializable, Cloneable, Comparable<JDOObject>, javax.jdo.InstanceCallbacks, javax.jdo.listener.ClearCallback, javax.jdo.listener.DeleteCallback, javax.jdo.listener.LoadCallback, javax.jdo.listener.StoreCallback

public class User
extends JDOObject

The base class for all objects representing a user in a data store. This is usually used to provide data store based authentication and authorisation. Sub-classes must use an inheritance strategy InheritanceStrategy.SUPERCLASS_TABLE since this class maintains a Discriminator.

Note: Password values are stored encrypted in the data store. By default passwords are encrypted using the password itself as the key. This behaviour can be changed to use a standard key by setting a system property with name PROPERTY_NAME to false. You can always explicitly specify the key to use to encrypt the password by using setPassword( String, String ) method instead of setPassword( String ).

The following shows sample use of this class:

   import com.sptci.jdo.User;
   import com.sptci.jdo.UserFactory;

     ...
     User u1 = new User( "joeuser" );
     u1.setPassword( "mysecretkey", "mypassword" );
     ...
     String password = u1.getPassword( "mysecretkey" );

     User u2 = new User( "anotherone" );
     u2.setPassword( "securepassword" );
     ...
     u2.getPassword( "securepassword" );
 

Version:
$Id: User.java 4618 2009-02-10 00:49:30Z rakesh $
Author:
Rakesh Vidyadharan 2006-11-11
See Also:

© Copyright 2006 Sans Pareil Technologies, Inc.

, Serialized Form

Field Summary
protected  Collection<Group> groups
          The collection of groups to which the user belongs.
protected  byte[] password
          The password for the user.
static String PROPERTY_NAME
          The system property used to indicate whether to use secure password or less secure password.
static boolean USE_SECURE_PASSWORD
          A flag used to track whether we are using secure passwords or not.
protected  String userName
          The user name used as part of the login credential pair.
 
Fields inherited from class com.sptci.jdo.JDOObject
hash, HASH, logger, startLetter
 
Constructor Summary
User()
          Default constructor.
User(String userName)
          Create a new instance of the bean with the specified userName.
 
Method Summary
 void addGroup(Group group)
          Add this user as a member of the specified group.
 int compareTo(JDOObject object)
          Compare the specified object with this instance.
 boolean equals(Object object)
          Check to see if the specified object is equivalent to this object.
 Collection<Group> getGroups()
          Returns groups.
 String getPassword()
          Deprecated. Use getPassword( String ) for proper results. This method still has to be used if used in non-secure mode.
 String getPassword(String key)
          Returns password.
 String getUserName()
          Returns userName.
 int hashCode()
          Return a hash code for this object.
 void removeGroup(Group group)
          Remove this user from being a member of the specified group.
 void setGroups(Collection<Group> groups)
          Update the groups with the objects specified in the collection.
 void setPassword(String password)
          Set password.
 void setPassword(String key, String password)
          Set password.
 void setUserName(String userName)
          Set userName.
 
Methods inherited from class com.sptci.jdo.JDOObject
clone, createXStream, fromXML, getObjectId, getPersistenceManager, getStartLetter, jdoPostLoad, jdoPreClear, jdoPreDelete, jdoPreStore, resetHash, toString, toXML
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

PROPERTY_NAME

public static final String PROPERTY_NAME
The system property used to indicate whether to use secure password or less secure password. Secure passwords are stored encrypted using the password itself as the key, while less secure passwords are encrypted using PASSWORD_KEY as the key.


USE_SECURE_PASSWORD

public static final boolean USE_SECURE_PASSWORD
A flag used to track whether we are using secure passwords or not.

Note: Changing this with an existing data store will lead to passwords not being properly decrypted. This property should be set for the lifetime of a data store.


userName

protected String userName
The user name used as part of the login credential pair.


password

protected transient byte[] password
The password for the user.


groups

protected Collection<Group> groups
The collection of groups to which the user belongs.

Constructor Detail

User

public User()
Default constructor. No special actions required.


User

public User(String userName)
Create a new instance of the bean with the specified userName.

Parameters:
userName - The userName value to use to create the new instance
Method Detail

equals

public boolean equals(Object object)
Check to see if the specified object is equivalent to this object. Two instances are considered the same if they have the same ObjectId.

Overrides:
equals in class JDOObject
Parameters:
object - The object that is to be checked for equality with this object.
Returns:
boolean Returns true if the specied object is the same as this object.

hashCode

public int hashCode()
Return a hash code for this object. Compute the hash value based on the ObjectId.

Overrides:
hashCode in class JDOObject
Returns:
int The hash code value for the object.

compareTo

public int compareTo(JDOObject object)
Compare the specified object with this instance. Compares based upon the userName value.

Specified by:
compareTo in interface Comparable<JDOObject>
Overrides:
compareTo in class JDOObject
Parameters:
object - That object that is to be compared with this instance.
Returns:
Returns positive, 0 or negative based upon the relative values of userName.

getUserName

public final String getUserName()
Returns userName.

Returns:
String The reference to userName.

setUserName

public final void setUserName(String userName)
Set userName.

Parameters:
userName - The value to set.
Throws:
IllegalArgumentException - If the userName value specified is null or empty.

getPassword

@Deprecated
public final String getPassword()
Deprecated. Use getPassword( String ) for proper results. This method still has to be used if used in non-secure mode.

Returns password. This method works only if the class is configured to use non-secure passwords.

Returns:
String The string value of password

getPassword

public final String getPassword(String key)
Returns password.

Parameters:
key - The secret key used to encrypt the password. The original password value itself is used to encrypt the password. Hence the key specified must be the same as the users password.
Returns:
String The string value of password. Returns null if the specified key cannot be used to decrypt the password.
See Also:
Encrypt.decrypt(java.lang.String, byte[])

setPassword

public final void setPassword(String password)
                       throws javax.jdo.JDOFatalUserException
Set password.

Parameters:
password - The value to set.
Throws:
javax.jdo.JDOFatalUserException - If exceptions are raised when encrypting the password.
See Also:
setPassword( String, String )

setPassword

public final void setPassword(String key,
                              String password)
                       throws javax.jdo.JDOFatalUserException
Set password.

Parameters:
key - The key to use to encrypt the password.
password - The value to set.
Throws:
javax.jdo.JDOFatalUserException - If NoSuchAlgorithmException, InvalidKeyException, or IllegalBlockSizeException exceptions are raised when encrypting the password.
See Also:
Encrypt.encrypt(java.lang.String, java.lang.String)

getGroups

public Collection<Group> getGroups()
Returns groups.

Returns:
The value/reference of/to groups.

setGroups

public void setGroups(Collection<Group> groups)
Update the groups with the objects specified in the collection.

Parameters:
groups - The new collection of values to set.

addGroup

public void addGroup(Group group)
Add this user as a member of the specified group.

Parameters:
group - The group to which this user is being added.

removeGroup

public void removeGroup(Group group)
Remove this user from being a member of the specified group.

Parameters:
group - The group from which membership is being removed.

SPT Core API