org.mycore.user
Class MCRUser

java.lang.Object
  extended by org.mycore.user.MCRUserObject
      extended by org.mycore.user.MCRUser
All Implemented Interfaces:
Principal, MCRPrincipal

public class MCRUser
extends MCRUserObject
implements MCRPrincipal, Principal

Instances of this class represent MyCoRe users.

Version:
$Revision: 14994 $ $Date: 2008-10-09 11:30:08 +0200 (Do, 09. Okt 2008) $
Author:
Detlev Degenhardt, Jens Kupferschmidt, Thomas Scheffler (yagee), Heiko Helmbrecht
See Also:
MCRUserMgr, MCRUserObject, MCRUserContact, MCRUserMgr

Field Summary
protected  List<String> groupIDs
          A list of groups (IDs) where this user is a member of
protected  boolean idEnabled
          Specify whether the user ID is enabled or disabled
protected  int numID
          The numerical ID of the MyCoRe user unit (either user ID or group ID)
protected  String passwd
          The password of the MyCoRe user
protected  String primaryGroupID
          The primary group ID of the user
protected  boolean updateAllowed
          Specify whether the user is allowed to update the user object
protected  MCRUserContact userContact
          Object representing user address information
 
Fields inherited from class org.mycore.user.MCRUserObject
config, creationDate, creator, description, description_len, ID, id_len, logger, modifiedDate, password_len, privilege_len
 
Constructor Summary
MCRUser()
          Default constructor.
MCRUser(Element elm)
          This constructor creates the data of this object from a given JDOM element.
MCRUser(Element elm, boolean useEncryption)
          It the passes the given JDOM element to a different constructor and after that encrypts the password if the flag useEncryption is true.
MCRUser(int numID, String ID, String creator, Timestamp creationDate, Timestamp modifiedDate, boolean idEnabled, boolean updateAllowed, String description, String passwd, String primaryGroupID, List<String> groupIDs, String salutation, String firstname, String lastname, String street, String city, String postalcode, String country, String state, String institution, String faculty, String department, String institute, String telephone, String fax, String email, String cellphone)
          This constructor takes all attributes of this class as single variables.
MCRUser(String id)
          This minimal constructor only takes the user ID as a parameter.
MCRUser(String userid, String passwd)
           
 
Method Summary
 void addGroupID(String groupID)
          This method adds a group to the groups list of the user object.
 void debug()
          This method writes debug data to the logger (for the debug mode).
 boolean equals(Object obj)
           
 List<String> getAllGroupIDs()
          Deprecated. use getGroupIDs instead
 int getGroupCount()
           
 List<String> getGroupIDs()
           
 String getID()
          This method must be implemented by a subclass and returns the the ID of the object.
 String getName()
           
 int getNumID()
           
 String getPassword()
           
 String getPrimaryGroupID()
           
 MCRUserContact getUserContact()
           
 int hashCode()
           
 boolean isAuthenticated()
          This method checks if the user is authenticated.
 boolean isEnabled()
           
 boolean isMemberOf(MCRGroup group)
          This method checks if the user is member of a given group.
 boolean isUpdateAllowed()
           
 boolean isValid()
          This method checks if all required fields have been provided.
 boolean modificationIsAllowed()
          This private helper method checks if the modification of the user object is allowed for the current user/session.
 void removeGroupID(String groupID)
          This method removes a group from the groups list of the user object.
 void setEnabled(boolean flag)
          This method sets the "enabled" attribute to a boolean value.
 boolean setPassword(String newPassword)
          This method sets the password of the user.
 Document toJDOMDocument()
          This method must be implemented by a subclass and then returns the user or group object as a JDOM document.
 Element toJDOMElement()
          This method returns the user object as a JDOM element.
 String toString()
          This method is only used for providing error messages in the access control component and should be removed later.
 void update(MCRUser newuser)
          This method updates this instance with the data of the given MCRUser.
 
Methods inherited from class org.mycore.user.MCRUserObject
debugDefault, getCreationDate, getCreator, getDescription, getModifiedDate, setCreationDate, setCreationDate, setCreator, setDescription, setModifiedDate, setModifiedDate, trim, trim
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

numID

protected int numID
The numerical ID of the MyCoRe user unit (either user ID or group ID)


idEnabled

protected boolean idEnabled
Specify whether the user ID is enabled or disabled


updateAllowed

protected boolean updateAllowed
Specify whether the user is allowed to update the user object


passwd

protected String passwd
The password of the MyCoRe user


primaryGroupID

protected String primaryGroupID
The primary group ID of the user


userContact

protected MCRUserContact userContact
Object representing user address information


groupIDs

protected List<String> groupIDs
A list of groups (IDs) where this user is a member of

Constructor Detail

MCRUser

public MCRUser()
Default constructor. It is used to create a user object with empty fields. This is useful for constructing an XML representation of a user without specialized data which is used e.g. by MCRUserServlet just to get an XML-representation. The XML representation is used by the XSLT-Stylesheet to create HTML output for the presentation. This empty user object will not be created in the persistent data store.


MCRUser

public MCRUser(String id)
This minimal constructor only takes the user ID as a parameter. For all other attributes the default constructor is invoked. This constructor is used by the access control system.

Parameters:
id - the named user ID

MCRUser

public MCRUser(int numID,
               String ID,
               String creator,
               Timestamp creationDate,
               Timestamp modifiedDate,
               boolean idEnabled,
               boolean updateAllowed,
               String description,
               String passwd,
               String primaryGroupID,
               List<String> groupIDs,
               String salutation,
               String firstname,
               String lastname,
               String street,
               String city,
               String postalcode,
               String country,
               String state,
               String institution,
               String faculty,
               String department,
               String institute,
               String telephone,
               String fax,
               String email,
               String cellphone)
        throws MCRException,
               Exception
This constructor takes all attributes of this class as single variables.

Parameters:
numID - (int) the numerical user ID
ID - the named user ID
idEnabled - (boolean) specifies whether the account is disabled or enabled
updateAllowed - (boolean) specifies whether the user may update his or her data
description - description of the user
passwd - password of the user (encrypted or not encrypted, depending on property)
primaryGroupID - the ID of the primary group of the user
groupIDs - a ArrayList of groups (IDs) the user belongs to
salutation - contact information
firstname - contact information
lastname - contact information
street - contact information
city - contact information
postalcode - contact information
country - contact information
state - contact information
institution - contact information
faculty - contact information
department - contact information
institute - contact information
telephone - telephone number
fax - fax number
email - email address
cellphone - number of cellular phone, if available
Throws:
MCRException
Exception

MCRUser

public MCRUser(String userid,
               String passwd)
        throws MCRException,
               Exception
Throws:
MCRException
Exception

MCRUser

public MCRUser(Element elm,
               boolean useEncryption)
It the passes the given JDOM element to a different constructor and after that encrypts the password if the flag useEncryption is true. This constructor must only be used if a cleartext password is provided in the JDOM element user data.

Parameters:
elm - JDOM Element defining a user
useEncryption - flag to determine if the password has to be encrypted

MCRUser

public MCRUser(Element elm)
This constructor creates the data of this object from a given JDOM element.

Parameters:
elm - JDOM Element defining a user
Method Detail

getUserContact

public MCRUserContact getUserContact()
Returns:
This method returns the contact object of the user

getID

public final String getID()
Description copied from class: MCRUserObject
This method must be implemented by a subclass and returns the the ID of the object.

Specified by:
getID in interface MCRPrincipal
Specified by:
getID in class MCRUserObject
Returns:
This method returns the ID (user ID or group ID) of the user object.

removeGroupID

public void removeGroupID(String groupID)
                   throws MCRException
This method removes a group from the groups list of the user object. This list is the list of group IDs where this user or group itself is a member of, not the list of groups this user or group has as members.

Parameters:
groupID - ID of the group removed from the user object
Throws:
MCRException

addGroupID

public void addGroupID(String groupID)
                throws MCRException
This method adds a group to the groups list of the user object. This is the list of group IDs where this user or group itself is a member of, not the list of groups this user or group has as members.

Parameters:
groupID - ID of the group added to the user object
Throws:
MCRException

getAllGroupIDs

public final List<String> getAllGroupIDs()
Deprecated. use getGroupIDs instead

This method determines the list of all groups the user is a member of, including the implicit ones. That means: if user u is a member of group G1 and G1 is member of group G2 and G2 itself is member of G3, then user u is considered to be an implicit member of groups G2 and G3.

Returns:
list of all groups the user is a member of

getNumID

public int getNumID()
Returns:
This method returns the numerical ID of the user object.

getPassword

public String getPassword()
Returns:
This method returns the password of the user.

getPrimaryGroupID

public final String getPrimaryGroupID()
Returns:
This method returns the ID of the primary group of the user.

isAuthenticated

public final boolean isAuthenticated()
This method checks if the user is authenticated. It does so by querying the user manager. This information is needed to assign categories in the access control subsystem.

Returns:
returns true if the user is authenticated

isEnabled

public boolean isEnabled()
Returns:
This method returns true if the user is enabled and may login.

isMemberOf

public boolean isMemberOf(MCRGroup group)
This method checks if the user is member of a given group.

Parameters:
group - Is the user a member of this group?
Returns:
Returns true if the user is a member of the given group.

isUpdateAllowed

public boolean isUpdateAllowed()
Returns:
This method returns true if the user may update his or her data.

isValid

public boolean isValid()
This method checks if all required fields have been provided. In a later stage of the software development a User Policy object will be asked, which fields exactly are the required fields. This will be configurable.

Specified by:
isValid in class MCRUserObject
Returns:
returns true if all required fields have been provided

setPassword

public boolean setPassword(String newPassword)
This method sets the password of the user.

Parameters:
newPassword - The new password of the user

setEnabled

public final void setEnabled(boolean flag)
This method sets the "enabled" attribute to a boolean value.

Parameters:
flag - the boolean data

update

public final void update(MCRUser newuser)
This method updates this instance with the data of the given MCRUser.

Parameters:
newuser - the data for the update.

toJDOMDocument

public Document toJDOMDocument()
                        throws MCRException
Description copied from class: MCRUserObject
This method must be implemented by a subclass and then returns the user or group object as a JDOM document.

Specified by:
toJDOMDocument in class MCRUserObject
Returns:
This method returns the user or group object as a JDOM document.
Throws:
MCRException

toJDOMElement

public Element toJDOMElement()
                      throws MCRException
This method returns the user object as a JDOM element. This is needed if one wants to get a representation of several user objects in one xml document.

Specified by:
toJDOMElement in class MCRUserObject
Returns:
this user data as JDOM element
Throws:
MCRException

debug

public final void debug()
This method writes debug data to the logger (for the debug mode).


modificationIsAllowed

public final boolean modificationIsAllowed()
                                    throws MCRException
This private helper method checks if the modification of the user object is allowed for the current user/session.

Throws:
MCRException

getGroupIDs

public final List<String> getGroupIDs()
Returns:
This method returns the list of groups as a ArrayList of strings. These are the groups where the object itself is a member of.

getGroupCount

public final int getGroupCount()

getName

public String getName()
Specified by:
getName in interface Principal
See Also:
getID()

toString

public String toString()
Description copied from class: MCRUserObject
This method is only used for providing error messages in the access control component and should be removed later.

Specified by:
toString in interface Principal
Overrides:
toString in class MCRUserObject
See Also:
getID()

equals

public boolean equals(Object obj)
Specified by:
equals in interface Principal
Overrides:
equals in class Object

hashCode

public int hashCode()
Specified by:
hashCode in interface Principal
Overrides:
hashCode in class Object