org.mycore.user
Class MCRUserMgr

java.lang.Object
  extended by org.mycore.user.MCRUserMgr

public class MCRUserMgr
extends Object

This class is the user (and group) manager of the MyCoRe system. It is implemented using the singleton design pattern in order to ensure that there is only one instance of this class, i.e. one user manager, running. The user manager has several responsibilities. First it serves as a facade for client classes such as MyCoRe-Servlets to retrieve objects from the persistent datastore. Then the manager is used by the user and group objects themselves to manage their existence in the underlying datastore.

Version:
$Revision: 14994 $ $Date: 2009-01-29 09:42:52 +0100 (Do, 29. Jan 2009) $
Author:
Detlev Degenhardt, Jens Kupferschmidt

Method Summary
 void checkConsistency()
          This method checks the consistency of the user and group data.
 void createGroup(MCRGroup group)
          This method creates a group in the datastore (and the group cache as well).
 void createUser(MCRUser user)
          This method creates a user in the datastore (and the user cache as well).
 void deleteGroup(String groupID)
          This method deletes a group from the datastore (and the group cache as well).
 void deleteUser(String userID)
          This method deletes a user from the datastore (and the user cache as well).
 void disableUser(String userID)
          This method disables the user.
 void enableUser(String userID)
          This method enables the user.
 boolean existGroup(String group)
          The method check that a group entry exists.
 boolean existUser(String user)
          The method check that an user entry exists.
 List<String> getAllGroupIDs()
          This method gets all group IDs from the persistent datastore and returns them as a ArrayList of strings.
 Document getAllGroups()
          This method returns a JDOM presentation of all groups of the system
 List<String> getAllUserIDs()
          This method gets all user IDs from the persistent datastore and returns them as an ArrayList of strings.
 Document getAllUsers()
          This method returns a JDOM presentation of all users of the system
 MCRUser getCurrentUser()
          The access control subsystem needs to know the current working user.
 Set<MCRGroup> getGroupsContainingUser(MCRUser user, Set<MCRGroup> groups)
          This method determines in which groups of a given set of groups a given user is a member of.
 List<String> getGroupsContainingUser(String user)
          This method determines in which groups is the user member.
 int getMaxUserNumID()
          This method returns the maximum value of the numerical user IDs
 String getPrimaryGroupIDOfUser(String userID)
          This method returns the ID of the primary group for a given userID.
 void importUserSystemFromFiles(Element groups, Element users)
          This method imports groups and user data from XML JDOM trees.
 void initializeGroup(MCRGroup group, String creator)
          This method is used by the initialization process of the user/group system to create a starting configuration without checking the consistency of the data.
 void initializeUser(MCRUser user, String creator)
          This method is used by the initialization process of the user/group system to create a starting configuration without checking the consistency of the data.
static MCRUserMgr instance()
          This method is the only way to get an instance of this class.
static boolean isAuthenticated(MCRUser user)
          This method checks if the user is authenticated, i.e.
 boolean isLocked()
          return This method returns true is if the user manager is in the locked state
 boolean login(String userID, String passwd)
          login to the system.
 MCRGroup retrieveGroup(String groupID)
          This method retrieves the group object with the given group ID.
protected  MCRGroup retrieveGroup(String groupID, boolean bFromDataStore)
          This method first looks for a given groupID in the group cache and returns this group object.
 Set<MCRGroup> retrieveGroups(Set<String> groupIDs)
          In the access control subsystem only IDs are stored, not references to user or group objects.
 MCRUser retrieveUser(String userID)
          This method first retrieves the user object with the given userID.
protected  MCRUser retrieveUser(String userID, boolean bFromDataStore)
          This method first looks for a given userID in the user cache and returns this user object.
 Set<MCRUser> retrieveUsers(Set<String> userIDs)
          In the access control subsystem only IDs are stored, not references to user or group objects.
 void setLock(boolean locked)
          This method sets the lock-status of the user manager.
 void setPassword(String userID, String password)
          This method sets a new password for the given user.
 void updateGroup(MCRGroup updGroup)
          This method updates a group in the datastore (and the cache as well).
 void updateUser(MCRUser updUser)
          This method updates a user in the datastore (and the cache as well).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

instance

public static final MCRUserMgr instance()
                                 throws MCRException
This method is the only way to get an instance of this class. It calls the private constructor to create the singleton.

Returns:
returns the one and only instance of MCRUserMgr
Throws:
MCRException

checkConsistency

public final void checkConsistency()
                            throws MCRException
This method checks the consistency of the user and group data. It should be executed after importing data from xml files, e.g.

Throws:
MCRException

createGroup

public final void createGroup(MCRGroup group)
                       throws MCRException
This method creates a group in the datastore (and the group cache as well). The logical correctness of the data is checked.

Parameters:
group - The group object to be created
Throws:
MCRException

createUser

public final void createUser(MCRUser user)
                      throws MCRException
This method creates a user in the datastore (and the user cache as well). The logical correctness of the data is checked.

Parameters:
user - The user object which will be created
Throws:
MCRException

deleteGroup

public final void deleteGroup(String groupID)
                       throws MCRException
This method deletes a group from the datastore (and the group cache as well).

Parameters:
groupID - The group ID which will be deleted
Throws:
MCRException

deleteUser

public final void deleteUser(String userID)
                      throws MCRException
This method deletes a user from the datastore (and the user cache as well).

Parameters:
userID - The user ID which will be deleted
Throws:
MCRException

disableUser

public final void disableUser(String userID)
                       throws MCRException
This method disables the user.

Parameters:
userID - The user object which will be disabled
Throws:
MCRException

enableUser

public final void enableUser(String userID)
                      throws MCRException
This method enables the user.

Parameters:
userID - The user object which will be enabled
Throws:
MCRException

getAllGroupIDs

public final List<String> getAllGroupIDs()
                                  throws MCRException
This method gets all group IDs from the persistent datastore and returns them as a ArrayList of strings.

Returns:
ArrayList of strings containing the group IDs of the system.
Throws:
MCRException

getAllGroups

public final Document getAllGroups()
                            throws MCRException
This method returns a JDOM presentation of all groups of the system

Returns:
JDOM document presentation of all groups of the system
Throws:
MCRException

getAllUserIDs

public final List<String> getAllUserIDs()
                                 throws MCRException
This method gets all user IDs from the persistent datastore and returns them as an ArrayList of strings.

Returns:
ArrayList of strings containing the user IDs of the system.
Throws:
MCRException

getAllUsers

public final Document getAllUsers()
                           throws MCRException
This method returns a JDOM presentation of all users of the system

Returns:
JDOM document presentation of all users of the system
Throws:
MCRException

getCurrentUser

public final MCRUser getCurrentUser()
The access control subsystem needs to know the current working user. This information is held in the session, so we just ask the session about it.

Returns:
the current user

getGroupsContainingUser

public final Set<MCRGroup> getGroupsContainingUser(MCRUser user,
                                                   Set<MCRGroup> groups)
This method determines in which groups of a given set of groups a given user is a member of.

Returns:
set of groups the given user is a member of

getGroupsContainingUser

public final List<String> getGroupsContainingUser(String user)
This method determines in which groups is the user member.

Returns:
an ArrayList of groups where the given user is a member of

getMaxUserNumID

public final int getMaxUserNumID()
                          throws MCRException
This method returns the maximum value of the numerical user IDs

Returns:
maximum value of the numerical user IDs
Throws:
MCRException

getPrimaryGroupIDOfUser

public final String getPrimaryGroupIDOfUser(String userID)
This method returns the ID of the primary group for a given userID.

Parameters:
userID - the userID for which the primary group ID is requested
Returns:
groupID the ID of the primary group of the user

initializeGroup

public final void initializeGroup(MCRGroup group,
                                  String creator)
                           throws MCRException
This method is used by the initialization process of the user/group system to create a starting configuration without checking the consistency of the data. It is also used when importing groups into the system.

Parameters:
group - The group object which should be created
creator - the creator
Throws:
MCRException

initializeUser

public final void initializeUser(MCRUser user,
                                 String creator)
                          throws MCRException
This method is used by the initialization process of the user/group system to create a starting configuration without checking the consistency of the data. It is also used when importing users into the system.

Parameters:
user - The user object which should be created
creator - The creator
Throws:
MCRException

importUserSystemFromFiles

public final void importUserSystemFromFiles(Element groups,
                                            Element users)
                                     throws MCRException
This method imports groups and user data from XML JDOM trees. It clean the old existing user and group entries. Only the administrator of from the property file is authorized to do this command.

Parameters:
groupfile - the JDOM tree of the MCRGroups data input
userfile - the JDOM tree of the MCRUsers data input
Throws:
MCRException

isAuthenticated

public static final boolean isAuthenticated(MCRUser user)
This method checks if the user is authenticated, i.e. if he or she is in the current session.

Returns:
returns true if the user is authenticated

isLocked

public final boolean isLocked()
return This method returns true is if the user manager is in the locked state


login

public boolean login(String userID,
                     String passwd)
              throws MCRException
login to the system. This method just checks the password for a given user.

Parameters:
userID - user ID for the login
passwd - password for the user
Returns:
true if the password matches the password stored, false otherwise
Throws:
MCRException

retrieveGroup

public MCRGroup retrieveGroup(String groupID)
                       throws MCRException
This method retrieves the group object with the given group ID.

Parameters:
groupID - string representing the requested group object
Returns:
MCRGroup group object (if available)
Throws:
MCRException - if group object is not known

retrieveGroup

protected MCRGroup retrieveGroup(String groupID,
                                 boolean bFromDataStore)
                          throws MCRException
This method first looks for a given groupID in the group cache and returns this group object. In case that the group object is not in the cache, the group will be retrieved from the database. Then the group object is put into the cache.

Parameters:
groupID - string representing the requested group object
bFromDataStore - boolean value, if true the group must be retrieved directly from the data store
Returns:
MCRGroup group object (if available)
Throws:
MCRException - if group object is not known

retrieveGroups

public final Set<MCRGroup> retrieveGroups(Set<String> groupIDs)
                                   throws MCRException
In the access control subsystem only IDs are stored, not references to user or group objects. Therefore the user system must provide a method to retrieve a set of groups according to a set of given group IDs.

Parameters:
groupIDs - A set of group IDs for which the group objects are to be retrieved
Returns:
set of groups according to the given set of group IDs
Throws:
MCRException

retrieveUser

public MCRUser retrieveUser(String userID)
                     throws MCRException
This method first retrieves the user object with the given userID.

Parameters:
userID - string representing the requested user object
Returns:
MCRUser user object (if available), otherwise null
Throws:
MCRException - if user object is not known

retrieveUser

protected MCRUser retrieveUser(String userID,
                               boolean bFromDataStore)
                        throws MCRException
This method first looks for a given userID in the user cache and returns this user object. In case that the user object is not in the cache, the user will be retrieved from the database. Then the user object is put into the cache.

Parameters:
userID - string representing the requested user object
bFromDataStore - boolean value, if true the user must be retrieved directly from the data store
Returns:
MCRUser user object (if available), otherwise null
Throws:
MCRException - if user object is not known

retrieveUsers

public final Set<MCRUser> retrieveUsers(Set<String> userIDs)
In the access control subsystem only IDs are stored, not references to user or group objects. Therefore the user system must provide a method to retrieve a set of users according to a set of given user IDs.

Parameters:
userIDs - A set of user IDs for which the user objects are to be retrieved
Returns:
set of users according to the given set of user IDs
Throws:
MCRException

setLock

public final void setLock(boolean locked)
This method sets the lock-status of the user manager.

Parameters:
locked - flag that determines whether write access to the data is denied (true) or allowed

setPassword

public final void setPassword(String userID,
                              String password)
                       throws MCRException
This method sets a new password for the given user.

Parameters:
userID - the userID
password - the user password
Throws:
MCRException

updateGroup

public final void updateGroup(MCRGroup updGroup)
                       throws MCRException
This method updates a group in the datastore (and the cache as well).

Parameters:
updGroup - The group object which will be updated
Throws:
MCRException

updateUser

public final void updateUser(MCRUser updUser)
                      throws MCRException
This method updates a user in the datastore (and the cache as well).

Parameters:
updUser - The user object which will be updated
Throws:
MCRException

existGroup

public final boolean existGroup(String group)
The method check that a group entry exists.

Parameters:
group - the group name as String
Returns:
true if the group exists, else return false

existUser

public final boolean existUser(String user)
The method check that an user entry exists.

Parameters:
user - the user name as String
Returns:
true if the user exists, else return false