org.salespointframework.core.users
Class User

java.lang.Object
  extended by org.salespointframework.core.users.User
All Implemented Interfaces:
java.lang.Comparable<java.lang.Object>, Recoverable, DatasourceOnChangeListener, SpItem

public class User
extends java.lang.Object
implements java.lang.Comparable<java.lang.Object>, Recoverable, DatasourceOnChangeListener, SpItem

A user, having a name, a password for log-in purposes, and a set of capabilities.

User objects are used to store all information associated with a user. As a default users have a name, a password for log-in purposes, and a set of capabilities that can be used to restrict the users usage of the application. Additional information stored in subclasses of User could include statistics on application usage, bonus data etc.

Since:
v2.0
Version:
2.0 05/05/1999
Author:
Steffen Zschaler
See Also:
UserManager, Capability

Field Summary
private  java.awt.image.BufferedImage chUserImage
          Cacher user image
static PassWDGarbler DEFAULT_PASSWORD_GARBLER
          The default password garbler.
static java.lang.String defaultUserImage
          The default user image
protected  ListenerHelper m_lhListeners
          The list of all listeners that showed an interest in this user.
private  java.util.Map<java.lang.String,Capability> m_mpCapabilities
          The user's capabilities.
protected  java.beans.PropertyChangeSupport m_pcsPropertyListeners
          Used to fire PropertyChangeEvents.
private  java.lang.String m_sName
          The user's name.
private  java.lang.String m_sPassWd
          The user's log-in password.
private static PassWDGarbler s_pwdgGlobal
          The global password garbler.
static java.lang.String SOME_PROPERTY
          Indicates that one or more properties changed
private  byte[] userImage
          Filename of users image
 
Constructor Summary
User(java.lang.String sName)
          Create a new User with a given name.
 
Method Summary
 void addCapabilityDataListener(CapabilityDataListener cdl)
          Add a CapabilityDataListener.
 int compareTo(java.lang.Object o)
          Compares two Users.
 void DatasourceOnChange()
          free internal resources
 boolean equals(java.lang.Object o)
          Check whether the given object equals this user.
protected  void fireCapabilitiesAdded(java.util.Set<java.lang.String> stCapNames)
          Fire a capabilitiesAdded event.
protected  void fireCapabilitiesReplaced(java.util.Set<java.lang.String> stCapNames)
          Fire a capabilitiesReplaced event.
 void firePropertyChanged()
          Signals persistence layer to update objects values
 void fireUserDataChanged()
          fire a userDataChangedEvent
static java.lang.String garblePassWD(java.lang.String passWd)
          Garble a password using the global password garbler, if any.
 Capability getCapability(java.lang.String sCapName)
          Retrieve one of this user's capabilities.
 javax.swing.JCheckBox getCapabilityCheckBox(java.lang.String sCapName)
          Return a checkbox that can be used to visualize and change the value of a certain capability of this user.
static PassWDGarbler getGlobalPassWDGarbler()
          Get the global password garbler.
 java.lang.String getName()
          Retrieve the name of this user.
 java.awt.image.BufferedImage getUserImage()
          get user's image
 boolean isPassWd(java.lang.String sPassWd)
          Check whether a given string is identical to the password of this user.
 void loggedOff(java.lang.Object oFrom)
          Method called by the UserManager when the user was disassociated from some object.
 void loggedOn(java.lang.Object oTo)
          Method called by the UserManager when the user was associated with some object.
 void recover(java.util.Map<java.lang.String,java.lang.Object> data, java.lang.Object recoveryContext, boolean reInit)
          do recovery
 boolean removeCapability(Capability cap)
          Entirely removes a capability from the user.
 void removeCapabilityDataListener(CapabilityDataListener cdl)
          Remove a CapabilityDataListener.
 void renderAdditionalInfoArea(javax.swing.JPanel panel, boolean isSelected)
          Hook for displaying additional information in the userlist
 void setCapabilities(java.util.Map<java.lang.String,Capability> mpCapabilities)
          Set a range of the user's capabilities to new values.
 Capability setCapability(Capability cap)
          Set one capability.
static PassWDGarbler setGlobalPassWDGarbler(PassWDGarbler pwdgNew)
          Set the global password garbler.
 void setPassWd(java.lang.String sPassWd)
          Set the password of this user.
 void setUserImage(java.awt.image.BufferedImage image)
          Set users image for performance reason, you have to call firePropertyChanged() separately
 void setUserImage(java.net.URI filename)
          Set users image for performance reason, you have to call firePropertyChanged() separately
 java.lang.String toString()
          Return a String representation.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SOME_PROPERTY

public static final java.lang.String SOME_PROPERTY
Indicates that one or more properties changed

See Also:
Constant Field Values

m_pcsPropertyListeners

protected java.beans.PropertyChangeSupport m_pcsPropertyListeners
Used to fire PropertyChangeEvents.


m_sName

private final java.lang.String m_sName
The user's name. This is an immutable value and cannot be changed once the user has been created.


m_sPassWd

private java.lang.String m_sPassWd
The user's log-in password. This should normally be stored in garbled form as it may be serialized and thus there is the potential risk of it being read by unauthorized persons.


defaultUserImage

public static java.lang.String defaultUserImage
The default user image


userImage

private byte[] userImage
Filename of users image


chUserImage

private java.awt.image.BufferedImage chUserImage
Cacher user image


m_mpCapabilities

private java.util.Map<java.lang.String,Capability> m_mpCapabilities
The user's capabilities.

See Also:
Capability

m_lhListeners

protected ListenerHelper m_lhListeners
The list of all listeners that showed an interest in this user.


DEFAULT_PASSWORD_GARBLER

public static final PassWDGarbler DEFAULT_PASSWORD_GARBLER
The default password garbler.

The default password garbling algorithm is very simple and should only be used if no real security concerns are present. It will convert the input char array into its MD5 representation.


s_pwdgGlobal

private static PassWDGarbler s_pwdgGlobal
The global password garbler. It defaults to DEFAULT_PASSWORD_GARBLER.

Constructor Detail

User

public User(java.lang.String sName)
Create a new User with a given name. The password will initially be the empty string and there will be no capabilities.

Parameters:
sName - the new user's name.
Method Detail

setUserImage

public void setUserImage(java.net.URI filename)
Set users image for performance reason, you have to call firePropertyChanged() separately

Parameters:
filename -

setUserImage

public void setUserImage(java.awt.image.BufferedImage image)
Set users image for performance reason, you have to call firePropertyChanged() separately

Parameters:
filename -

getUserImage

public java.awt.image.BufferedImage getUserImage()
get user's image

Returns:

renderAdditionalInfoArea

public void renderAdditionalInfoArea(javax.swing.JPanel panel,
                                     boolean isSelected)
Hook for displaying additional information in the userlist


getName

public final java.lang.String getName()
Retrieve the name of this user.

Specified by:
getName in interface SpItem
Returns:
the name of the user.

isPassWd

public final boolean isPassWd(java.lang.String sPassWd)
Check whether a given string is identical to the password of this user.

For security reasons there is no getPassWd() method. The only way to check a user's password is this method. The string you pass as a parameter will be compared to the user's password as it is stored, i.e. if the password is stored in a garbled form (recommended) the string you pass as a parameter must also be in garbled form.

Parameters:
sPassWd - the string to be compared to the user's password. Must be in the same form as the actual password, i.e. esp. it must be garbled if the actual password is.
Returns:
true if the password and the string passed as a parameter are equal.
See Also:
garblePassWD(java.lang.String)

setPassWd

public final void setPassWd(java.lang.String sPassWd)
Set the password of this user.

The password is stored exactly as given, i.e. no garbling of any kind is performed. It is strongly recommended, though, that you pass a garbled password, so that passwords are not stored as plain text.

for performance reason, you have to call firePropertyChanged() separately

Parameters:
sPassWd - the new password
See Also:
garblePassWD(java.lang.String), PassWDGarbler

equals

public boolean equals(java.lang.Object o)
Check whether the given object equals this user.

Two users are considered equal if their names are equal.

Overrides:
equals in class java.lang.Object
Parameters:
o - the object to be compared to.
Returns:
true if the given object equals this user.

compareTo

public int compareTo(java.lang.Object o)
Compares two Users.

Specified by:
compareTo in interface java.lang.Comparable<java.lang.Object>
Parameters:
o - the User to be compared with this.
Returns:
the comparison result.

toString

public java.lang.String toString()
Return a String representation.

Overrides:
toString in class java.lang.Object
Returns:
the name of the user.

setCapabilities

public void setCapabilities(java.util.Map<java.lang.String,Capability> mpCapabilities)
Set a range of the user's capabilities to new values.

Sets all capabilities from mpCapabilities to the new values. This will fire capabilitiesAdded events, and capabilitiesReplaced events if capabilities were changed.

Attention: A capability that has been set cannot be removed again. Capabilities have two states (Granted and Not Granted). If you want to remove a certain capability, set its state to Not Granted.

Parameters:
mpCapabilities - the capabilities to be set. The keys of this map must be the names of the capabilities to be set, whereas the corresponding values must be the actual Capability objects.
See Also:
Capability, setCapability(org.salespointframework.core.users.Capability), CapabilityDataListener

setCapability

public Capability setCapability(Capability cap)
Set one capability.

Attention: A capability that has been set should not be removed again. Capabilities have two states (Granted and Not Granted). If you want to remove a certain capability, set its state to Not Granted.

This will fire a capabilitiesAdded or a capabilitiesReplaced event.

Parameters:
cap - the capability to be set.
Returns:
the previous value of the capability or null if none.

removeCapability

public boolean removeCapability(Capability cap)
Entirely removes a capability from the user. Its not the same as a capability which is not granted. So don't mix them up.

Parameters:
cap - Capability to remove
Returns:
true on success

getCapability

public Capability getCapability(java.lang.String sCapName)
Retrieve one of this user's capabilities.

Retrieves the capability of this user that is identified by sCapName.

Parameters:
sCapName - the name of the capability to be returned.
Returns:
the capability associated with the given name or null if none.
See Also:
Capability

getCapabilityCheckBox

public javax.swing.JCheckBox getCapabilityCheckBox(java.lang.String sCapName)
Return a checkbox that can be used to visualize and change the value of a certain capability of this user.

The checkbox will be backed by the capability, i.e. changes of the capability will be directly reflected in the checkbox and vice-versa. There will be a NullPointerException if the specified capability does not exist.

Parameters:
sCapName - the name of the capability to be visualized by the checkbox.
Returns:
a checkbox that can be used to visualize and change the capability.
Throws:
java.lang.NullPointerException - if Capability does not exist.
See Also:
JCheckBox, Capability, Capability.getDisplayName()

addCapabilityDataListener

public void addCapabilityDataListener(CapabilityDataListener cdl)
Add a CapabilityDataListener. CapabilityDataListeners receive events whenever a user's capability list changed.

Parameters:
cdl - the CapabilityDataListener to add.

removeCapabilityDataListener

public void removeCapabilityDataListener(CapabilityDataListener cdl)
Remove a CapabilityDataListener. CapabilityDataListeners receive events whenever a user's capability list changed.

Parameters:
cdl - the CapabilityDataListener to remove.

fireCapabilitiesAdded

protected void fireCapabilitiesAdded(java.util.Set<java.lang.String> stCapNames)
Fire a capabilitiesAdded event.

Parameters:
stCapNames - the set of capability names that where added.
See Also:
CapabilityDataListener.capabilitiesAdded(org.salespointframework.core.users.events.CapabilityDataEvent)

fireCapabilitiesReplaced

protected void fireCapabilitiesReplaced(java.util.Set<java.lang.String> stCapNames)
Fire a capabilitiesReplaced event.

Parameters:
stCapNames - the set of capability names that where replaced.
See Also:
CapabilityDataListener.capabilitiesReplaced(org.salespointframework.core.users.events.CapabilityDataEvent)

fireUserDataChanged

public void fireUserDataChanged()
fire a userDataChangedEvent


loggedOn

public void loggedOn(java.lang.Object oTo)
Method called by the UserManager when the user was associated with some object.

Parameters:
oTo - the object this user was associated with.
See Also:
UserManager

loggedOff

public void loggedOff(java.lang.Object oFrom)
Method called by the UserManager when the user was disassociated from some object.

Parameters:
oFrom - the object this user was disassociated from.
See Also:
UserManager

setGlobalPassWDGarbler

public static PassWDGarbler setGlobalPassWDGarbler(PassWDGarbler pwdgNew)
Set the global password garbler.

The global password garbler can be used as a central instance for garbling your users' passwords. It defaults to DEFAULT_PASSWORD_GARBLER.

Parameters:
pwdgNew - the new global password garbler.
Returns:
the previous global password garbler.

getGlobalPassWDGarbler

public static PassWDGarbler getGlobalPassWDGarbler()
Get the global password garbler.

Returns:
the global password garbler.

garblePassWD

public static java.lang.String garblePassWD(java.lang.String passWd)
Garble a password using the global password garbler, if any.

If no global password garbler is installed, the password is returned unchanged. Otherwise the garbled password is returned.

Parameters:
passWd - the password to garble
Returns:
the garbled password.

recover

public void recover(java.util.Map<java.lang.String,java.lang.Object> data,
                    java.lang.Object recoveryContext,
                    boolean reInit)
do recovery

Specified by:
recover in interface Recoverable
Parameters:
data -
recoveryContext -
reInit - true, id recover was called more than one time on this object

DatasourceOnChange

public void DatasourceOnChange()
free internal resources

Specified by:
DatasourceOnChange in interface DatasourceOnChangeListener

firePropertyChanged

public void firePropertyChanged()
Signals persistence layer to update objects values