Holger's
Java API

com.antelmann.mgmt
Class UserImpl

java.lang.Object
  extended by com.antelmann.mgmt.EntityImpl
      extended by com.antelmann.mgmt.UserImpl
All Implemented Interfaces:
Entity, Resource, User, Serializable, Comparable<User>
Direct Known Subclasses:
TimeUser

public class UserImpl
extends EntityImpl
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
protected  boolean active
           
protected  String description
           
protected  String name
           
protected  String passwordHash
           
 
Fields inherited from class com.antelmann.mgmt.EntityImpl
propertyChangeSupport, props
 
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)
          attention: accessible objects are copied from the given user ONLY if it is a UserImpl instance
 
Method Summary
 Set<Object> accessibleObjects()
          returns an unmodifiable view over all actions that can be accessed by this user - provided that the canAccess(Object) method is not overridden.
 boolean canAccess(Object action)
          determines whether this user is allowed to access the given resource
 boolean checkPassword(char[] password)
          returns true only if the provided password matches the one of this user
 int compareTo(User user)
          first compares the name, then the id (using a UniversalComparator in both cases)
 boolean equals(Object obj)
          returns true if the given Object is a User instance and its id is equal
 String getDescription()
           
 String getName()
          provides a String used as the login name and also suitable for display; commonly, this would also be returned by toString().
 String getPasswordHash()
          returns the password representation suitable for serialization or other permanent storage
 String hashPassword(char[] password)
          provides the hashing used in this implmenentation (which a subclass may override)
 boolean isEnabled()
          determines whether this user is currently active
 void resetPassword()
           
 void setAccess(Object action, boolean flag)
          grants/denies access to the given action
 void setDescription(String desc)
           
 void setEnabled(boolean flag)
           
 void setName(String name)
          name must not be null
 void setPassword(char[] password)
           
 void setPasswordHash(String passwordHash)
           
 String toString()
           
 
Methods inherited from class com.antelmann.mgmt.EntityImpl
addPropertyChangeListener, checkPropertyChange, containsPropertyText, enableChangeListenerSupport, equalWithProperties, getID, getProperties, getProperty, getPropertyChangeListeners, hashCode, isChangeListenerSupportEnabled, removeProperty, removePropertyChangeListener, setAll, setProperty, verifyProperties
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.antelmann.mgmt.Entity
getProperties, getProperty, removeProperty, setProperty
 
Methods inherited from interface com.antelmann.mgmt.Resource
getID
 

Field Detail

name

protected String name

passwordHash

protected String passwordHash

active

protected boolean active

description

protected String description

accessList

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

See Also:
canAccess(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

public UserImpl(Object id,
                User user)
attention: accessible objects are copied from the given user ONLY if it is a UserImpl instance

Method Detail

hashPassword

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

See Also:
Strings.hash(String)

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)
Specified by:
setPassword in interface User

resetPassword

public void resetPassword()

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)
Specified by:
setPasswordHash in interface User

getName

public String getName()
Description copied from interface: User
provides a String used as the login name and also suitable for display; commonly, this would also be returned by toString(). If the name is used as a login name, it should also be unique, just as well as the id.

Specified by:
getName in interface User

setName

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


setEnabled

public void setEnabled(boolean flag)

isEnabled

public boolean isEnabled()
Description copied from interface: User
determines whether this user is currently active

Specified by:
isEnabled in interface User

getDescription

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

setDescription

public void setDescription(String desc)

toString

public String toString()
Overrides:
toString in class Object

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:
Misc.comparator

equals

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

Overrides:
equals in class EntityImpl

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

canAccess

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

Specified by:
canAccess in interface User

accessibleObjects

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

See Also:
canAccess(Object)


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