org.davesag.generica.core
Class User

java.lang.Object
  extended byorg.davesag.generica.core.User
All Implemented Interfaces:
Persistable, Serializable

public class User
extends Object
implements Persistable, Serializable

The User bean represents the bare information we know about the user of the system. The User is the core of the core objects really. The user's password is converted to an MD5 hash code for privacy. There are protected methods for setting and getting the user's hashed password. These are there to support Hibernate only and can be ignored by most developers. This User object also provides a mechanism for providing a simple password helper, invalidating the user's password and so forth. In addition users may be inactive, ie they exist but can not log in or do anything.

Since:
Generica 1.0
Version:
CVS Revision $Id: User.java,v 1.19 2004/04/08 13:19:08 davesag Exp $
Author:
Dave Sag http://www.davesag.com
See Also:
Serialized Form
Peristable via Hibernate:
table = "users"

Field Summary
protected  Boolean isActive
          is the user an active user, or has their access been disabled?
protected  String theEmail
          the email address for this user
protected  Long theId
          user's id used as a key by hibernate
protected  String theLastIp
          a security measure, this is the last IP number the user logged in from
protected  String thePassword
          the MD5Hash of the password of this user
protected  PasswordHelper thePasswordHelper
          the user's password helper
protected  Boolean thePasswordRequiresReset
          A flag that determins id the password requires resetting.
protected  String theUsername
          the user's username - must not contain chars that can not be used in a uri
 
Constructor Summary
User()
          null constructor required by hibernate.
User(String username, String ctpassword)
          constructor takes a member and populates this summary object with the values required in common to all member displays.
 
Method Summary
 void activate()
          A user may be activated, in which case they may log-in.
 void deactivate()
          A user may be deactivated.
 boolean equals(Object o)
          Tests if the supplied object is equal to this User.
 Boolean getActive()
          Get the active status of the user.
 String getEmail()
          Get the user's email address.
 Long getId()
          the id number.
 String getLastIp()
          the user's last known IP number.
 String getPassword()
          Get the hashed password.
 PasswordHelper getPasswordHelper()
          Get the user's PasswordHelper.
 Boolean getPasswordRequiresReset()
          Essentially the same as isPasswordRequiresReset but expressed in a form more useful for Struts.
 String getUsername()
          Get the user's username.
 int hashcode()
          An object must override the hashcode if it overrides the equals method.
 void invalidatePassword()
          Invalidate the user's password.
 boolean isActive()
          Is the user active, ie are they allowed to log-in?
 boolean isPasswordRequiresReset()
          Tests to see if the user's password is valid.
 void setActive(Boolean b)
          Set the validity of the user's password.
 void setClearTextPassword(String ctpassword)
          set the user's password by creating an MD5 hash of the clear text password supplied.
 void setEmail(String email)
          Set the user's email address.
protected  void setId(Long id)
          Sets the The User's Id number.
 void setLastIp(String ip)
          Sets the The User's IP number.
 void setPassword(String password)
          Set the user's password directly.
 void setPasswordHelper(PasswordHelper ph)
          Set the user's PasswordHelper.
protected  void setPasswordRequiresReset(Boolean b)
          Set the validity of the user's password.
 void setTemplateId(Long id)
          Sets the The User's ID number directly.
 void setUsername(String username)
          Set the user's username.
 String toString()
          Get the user's details as a string.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

theId

protected Long theId
user's id used as a key by hibernate


theUsername

protected String theUsername
the user's username - must not contain chars that can not be used in a uri


thePassword

protected String thePassword
the MD5Hash of the password of this user


thePasswordRequiresReset

protected Boolean thePasswordRequiresReset
A flag that determins id the password requires resetting. Usually set after the user has requested a new password. If false then the password must be reset.


thePasswordHelper

protected PasswordHelper thePasswordHelper
the user's password helper


theEmail

protected String theEmail
the email address for this user


isActive

protected Boolean isActive
is the user an active user, or has their access been disabled?


theLastIp

protected String theLastIp
a security measure, this is the last IP number the user logged in from

Constructor Detail

User

public User()
null constructor required by hibernate.


User

public User(String username,
            String ctpassword)
constructor takes a member and populates this summary object with the values required in common to all member displays.

Parameters:
username - The name of the user.
ctpassword - The clear text password of the user. It will be hashed.
Method Detail

getId

public Long getId()
the id number.

Specified by:
getId in interface Persistable
Returns:
The User's Id number.
Hibernate Unique ID Property:
generator-class = "identity"

setId

protected void setId(Long id)
Sets the The User's Id number.

Parameters:
id - The Id number to set.

setTemplateId

public void setTemplateId(Long id)
Sets the The User's ID number directly. This is only to be used when creating a template object, and is not to be used when creating actual objects that will be persisted.

Specified by:
setTemplateId in interface Persistable
Parameters:
id - The ID number to set.

getLastIp

public String getLastIp()
the user's last known IP number.

Returns:
The User's last known IP number.
Hibernate Property:
length = "30"

setLastIp

public void setLastIp(String ip)
Sets the The User's IP number.

Parameters:
ip - The IP number to set.

getUsername

public String getUsername()
Get the user's username.

Returns:
The username.
Hibernate Property:
length = "16" not-null="true" unique="true"

setUsername

public void setUsername(String username)
Set the user's username.

Parameters:
username - The username.

setClearTextPassword

public void setClearTextPassword(String ctpassword)
set the user's password by creating an MD5 hash of the clear text password supplied.

Parameters:
ctpassword - the clear text password.

getPassword

public String getPassword()
Get the hashed password.

Returns:
The hash of the users password.
Hibernate Property:
length = "32" not-null="true"

setPassword

public void setPassword(String password)
Set the user's password directly.

Parameters:
password - The already hashed password.

isPasswordRequiresReset

public boolean isPasswordRequiresReset()
Tests to see if the user's password is valid. A password may be rendered invalid, in which case the user must reset their password before being properly logged in.

Returns:
true if the password is valid.

invalidatePassword

public void invalidatePassword()
Invalidate the user's password. A password may be rendered invalid, in which case the user must reset their password before being properly logged in.


setPasswordRequiresReset

protected void setPasswordRequiresReset(Boolean b)
Set the validity of the user's password.

Parameters:
b - True if the password is valid.

getPasswordRequiresReset

public Boolean getPasswordRequiresReset()
Essentially the same as isPasswordRequiresReset but expressed in a form more useful for Struts.

Returns:
True if the password is valid.
Hibernate Property:

getPasswordHelper

public PasswordHelper getPasswordHelper()
Get the user's PasswordHelper.

Returns:
The user's PasswordHelper.
Hibernate Component:

setPasswordHelper

public void setPasswordHelper(PasswordHelper ph)
Set the user's PasswordHelper.

Parameters:
ph - The PasswordHelper.

getEmail

public String getEmail()
Get the user's email address.

Returns:
The user's email address.
Hibernate Property:
length = "53" not-null="true"

setEmail

public void setEmail(String email)
Set the user's email address.

Parameters:
email - the email address.

activate

public void activate()
A user may be activated, in which case they may log-in.


deactivate

public void deactivate()
A user may be deactivated. Their record stays on file but they can no longer log-in.


setActive

public void setActive(Boolean b)
Set the validity of the user's password.

Parameters:
b - True if the password is valid.

getActive

public Boolean getActive()
Get the active status of the user. This is the same as isActive but presented in a form more useful to Struts.

Returns:
True if the user is active.
Hibernate Property:

isActive

public boolean isActive()
Is the user active, ie are they allowed to log-in?

Returns:
true if the user is active.

toString

public String toString()
Get the user's details as a string.

Returns:
the user as a string. useful for debugging.

equals

public boolean equals(Object o)
Tests if the supplied object is equal to this User. This is done by matching ids and that is all.

Parameters:
o - The object to test against this User. Must also be a User to make sense.
Returns:
true if the two users have the same id.

hashcode

public int hashcode()
An object must override the hashcode if it overrides the equals method.

Returns:
a valid hashcode for this user.


Dave Sag Generica API version 0.5.9 - (prerelease) Copyright 2003 - 2004 Dave Sag.