Holger's
Java API

com.antelmann.db
Class UserImpl

java.lang.Object
  extended by com.antelmann.db.AbstractDBEntry
      extended by com.antelmann.db.PropertyEntryImpl
          extended by com.antelmann.db.UserImpl
All Implemented Interfaces:
DBEntry, PropertyEntry, User, DetailedString, Enabled, Serializable, Comparable<User>, Principal
Direct Known Subclasses:
GUser, SecureUserImpl

public class UserImpl
extends PropertyEntryImpl
implements User

This class represents a default User implementation that can serve as the basis for more specific implementations. The password is stored as a hash value.

Author:
Holger Antelmann
See Also:
Strings.hash(String), Serialized Form

Field Summary
protected  HashSet<Object> accessList
          used to store actions that can be accessed
 
Fields inherited from class com.antelmann.db.PropertyEntryImpl
propertyChangeSupport, props, um, vcs
 
Fields inherited from interface com.antelmann.db.DBEntry
ENTRY_FLAVOR, ENTRY_LIST_FLAVOR
 
Fields inherited from interface com.antelmann.util.Enabled
FILTER
 
Constructor Summary
UserImpl(Object idAndName)
           
UserImpl(Object id, String name)
           
UserImpl(Object id, String name, String passwordHash, boolean active)
           
UserImpl(Object id, String name, String passwordHash, boolean enabled, String description)
           
UserImpl(Object id, User user)
           
 
Method Summary
 boolean checkPassword(char[] password)
          returns true only if the provided password matches the one of this user
 void clearAllAccess()
           
 int compareTo(User user)
          first compares the name, then the id (using a UniversalComparator in both cases)
 void copyAccessRightsFrom(UserImpl user)
          copies all accessible objects from the given user into this user and removes all accessible objects that are not accessible by that user.
 boolean equals(Object obj)
          returns true if the given Object is some User instance and its id is equal
 Filter<Object> getAccessFilter()
           
 Set<Object> getAccessibleObjects()
          returns an unmodifiable view over all actions that can be accessed by this user - provided that the hasAccess(Object) method is not overridden.
 String getEmail()
           
 String getName()
           
 String getPasswordHash()
          returns the password representation suitable for serialization or other permanent storage
 String getUserDescription()
           
 boolean hasAccess(Object action)
          determines whether this user is allowed to access the given resource
protected  String hashPassword(char[] password)
          provides the hashing used in this implementation (which a subclass may override)
 boolean isEnabled()
          determines whether this object is currently enabled
 void resetPassword()
          sets the password to null
 void setAccess(Object action, boolean flag)
          grants/denies access to the given action
 void setAccessFilter(Filter<Object> accessFilter)
          allows to customize the way hasAccess(Object) works.
 void setEmail(String email)
           
 void setEnabled(boolean flag)
          allows to enable/disable this instance
 void setName(String name)
          name must not be null
 void setPassword(char[] password)
          sets the password for this user (the password itself is not stored, but a hashed version of it)
 void setPasswordHash(String passwordHash)
          directly sets the hashed version of the password (so that the password can be changed to that of another user without knowing it)
 void setUserDescription(String desc)
           
 String toString()
           
 
Methods inherited from class com.antelmann.db.PropertyEntryImpl
addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, asProperties, canRedo, canUndo, checkPropertyChange, clearProperties, containsPropertyText, containsValuePattern, equalWithProperties, equalWithProperties, getBoolean, getNumber, getProperties, getProperty, getProperty, getPropertyChangeListeners, getPropertyComparator, getPropertyExtractor, getPropertyExtractor, getPropertyKeys, getStringExtractor, getVetoableChangeListeners, isCaseInsensitive, isChangeListenerSupportEnabled, isKeyIn, isUndoSupport, isVetoableChangeSupportEnabled, putAll, redo, removeProperty, removePropertyChangeListener, removeVetoableChangeListener, setAllFrom, setCaseInsensitive, setChangeListenerSupport, setProperty, setUndoSupported, setVetoableChangeSupport, toDetailedString, undo, verifyProperties
 
Methods inherited from class com.antelmann.db.AbstractDBEntry
getID, hashCode, hashEntry, sameEntry
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.antelmann.db.DBEntry
getID
 
Methods inherited from interface java.security.Principal
hashCode
 

Field Detail

accessList

protected final HashSet<Object> accessList
used to store actions that can be accessed

See Also:
hasAccess(Object)
Constructor Detail

UserImpl

public UserImpl(Object idAndName)

UserImpl

public UserImpl(Object id,
                String name)

UserImpl

public UserImpl(Object id,
                String name,
                String passwordHash,
                boolean active)

UserImpl

public UserImpl(Object id,
                String name,
                String passwordHash,
                boolean enabled,
                String description)

UserImpl

@Warning(value="accessible Objects are not copied if it is not a UserImpl and properties are only copied if it is a PropertyEntry")
public UserImpl(Object id,
                             User user)
Method Detail

hashPassword

protected String hashPassword(char[] password)
provides the hashing used in this implementation (which a subclass may override)

See Also:
Strings.hash(String), SecureUserImpl

checkPassword

public boolean checkPassword(char[] password)
Description copied from interface: User
returns true only if the provided password matches the one of this user

Specified by:
checkPassword in interface User

setPassword

public void setPassword(char[] password)
                 throws IllegalArgumentException
Description copied from interface: User
sets the password for this user (the password itself is not stored, but a hashed version of it)

Specified by:
setPassword in interface User
Throws:
IllegalArgumentException

resetPassword

public void resetPassword()
                   throws IllegalArgumentException
sets the password to null

Specified by:
resetPassword in interface User
Throws:
IllegalArgumentException

getPasswordHash

public String getPasswordHash()
Description copied from interface: User
returns the password representation suitable for serialization or other permanent storage

Specified by:
getPasswordHash in interface User

setPasswordHash

public void setPasswordHash(String passwordHash)
Description copied from interface: User
directly sets the hashed version of the password (so that the password can be changed to that of another user without knowing it)

Specified by:
setPasswordHash in interface User

getName

public String getName()
Specified by:
getName in interface Principal

setName

public void setName(String name)
name must not be null

Specified by:
setName in interface User

setEnabled

public void setEnabled(boolean flag)
Description copied from interface: Enabled
allows to enable/disable this instance

Specified by:
setEnabled in interface Enabled

isEnabled

public boolean isEnabled()
Description copied from interface: Enabled
determines whether this object is currently enabled

Specified by:
isEnabled in interface Enabled

getUserDescription

public String getUserDescription()
Specified by:
getUserDescription in interface User

setUserDescription

public void setUserDescription(String desc)
Specified by:
setUserDescription in interface User

getEmail

public String getEmail()
Specified by:
getEmail in interface User

setEmail

public void setEmail(String email)
Specified by:
setEmail in interface User

toString

public String toString()
Specified by:
toString in interface Principal
Overrides:
toString in class AbstractDBEntry

compareTo

public int compareTo(User user)
first compares the name, then the id (using a UniversalComparator in both cases)

Specified by:
compareTo in interface Comparable<User>
See Also:
UniversalComparator

equals

public boolean equals(Object obj)
returns true if the given Object is some User instance and its id is equal

Specified by:
equals in interface Principal
Overrides:
equals in class AbstractDBEntry

setAccess

public void setAccess(Object action,
                      boolean flag)
Description copied from interface: User
grants/denies access to the given action

Specified by:
setAccess in interface User

getAccessFilter

public Filter<Object> getAccessFilter()

setAccessFilter

public void setAccessFilter(Filter<Object> accessFilter)
allows to customize the way hasAccess(Object) works. if a non-null value is set, this filter supersedes the logic of hasAccess(Object) via the accessList. If a subclass uses this concept, it also has to take care of the implications for UserImpl(Object, User) and clearAllAccess().

See Also:
hasAccess(Object)

hasAccess

public boolean hasAccess(Object action)
Description copied from interface: User
determines whether this user is allowed to access the given resource

Specified by:
hasAccess in interface User

clearAllAccess

public void clearAllAccess()

getAccessibleObjects

public Set<Object> getAccessibleObjects()
returns an unmodifiable view over all actions that can be accessed by this user - provided that the hasAccess(Object) method is not overridden.

See Also:
hasAccess(Object)

copyAccessRightsFrom

public void copyAccessRightsFrom(UserImpl user)
copies all accessible objects from the given user into this user and removes all accessible objects that are not accessible by that user.



(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads