Package org.mycore.user2
Class MCRUserManager
java.lang.Object
org.mycore.user2.MCRUserManager
Manages all users using a database table.
- Author:
- Frank Lützenkirchen, Thomas Scheffler (yagee)
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic MCRUser
checkPassword
(String userName, String password) Returns aMCRUser
instance if the login succeeds.static int
countUsers
(String userPattern, String realm, String namePattern) Deprecated.static int
countUsers
(String userPattern, String realm, String namePattern, String mailPattern) Counts users in the database that match the given criteria.static int
countUsers
(String userPattern, String realm, String namePattern, String mailPattern, String attributeNamePattern) Counts users in the database that match the given criteria.static void
createUser
(MCRTransientUser user) Creates and store a new login user in the database, do also attribute mapping is needed.static void
createUser
(MCRUser user) Creates and stores a new login user in the database.static void
deleteUser
(String userName) Deletes a user from the given databasestatic void
deleteUser
(String userName, String realmId) Deletes a user from the given databasestatic void
deleteUser
(String userName, MCRRealm realm) Deletes a user from the given databasestatic void
deleteUser
(MCRUser user) Deletes a user from the given databasestatic boolean
Checks if a user with the given login name exists in the default realm.static boolean
Checks if a user with the given login name exists in the given realm.static boolean
Checks if a user with the given login name exists in the given realm.static MCRUser
Returns instance of MCRUser if current user is present in this user systemstatic MCRUser
Returns the user with the given userName, in the default realmstatic MCRUser
Returns the user with the given userName, in the given realmstatic MCRUser
Returns the user with the given userName, in the given realmReturns a Stream of users where the user has a given attribute.static boolean
isInvalidUser
(MCRUser user) Checks whether the user is invalid.Deprecated.UselistUsers(String, String, String, String)
instead.Searches for users in the database and returns a list of all matching users.listUsers
(String userPattern, String realm, String namePattern, String mailPattern, String attributeNamePattern, int offset, int limit) Searches for users in the database and returns a list of matching users.Returns a list of all users the given user is owner of.static MCRUser
Checks the password of a login user in the default realm.static MCRUser
Checks the password of a login user and if the user has at least one of the allowed roles in the default realm.static void
setPassword
(MCRUser user, String password) Sets password of 'user' to 'password'.static void
updateUser
(MCRUser user) Updates an existing login user in the database.
-
Constructor Details
-
MCRUserManager
public MCRUserManager()
-
-
Method Details
-
getUser
Returns the user with the given userName, in the default realm- Parameters:
userName
- the unique userName within the default realm- Returns:
- the user with the given login name, or null
-
getUser
Returns the user with the given userName, in the given realm- Parameters:
userName
- the unique userName within the given realmrealm
- the realm the user belongs to- Returns:
- the user with the given login name, or null
-
getUser
Returns the user with the given userName, in the given realm- Parameters:
userName
- the unique userName within the given realmrealmId
- the ID of the realm the user belongs to- Returns:
- the user with the given login name, or null
-
getUsers
Returns a Stream of users where the user has a given attribute.- Parameters:
attrName
- name of the user attributeattrValue
- value of the user attribute
-
exists
Checks if a user with the given login name exists in the default realm.- Parameters:
userName
- the login user name.- Returns:
- true, if a user with the given login name exists.
-
exists
Checks if a user with the given login name exists in the given realm.- Parameters:
userName
- the login user name.realm
- the realm the user belongs to- Returns:
- true, if a user with the given login name exists.
-
exists
Checks if a user with the given login name exists in the given realm.- Parameters:
userName
- the login user name.realm
- the ID of the realm the user belongs to- Returns:
- true, if a user with the given login name exists.
-
createUser
Creates and stores a new login user in the database. This will also store role membership information.- Parameters:
user
- the user to create in the database.
-
createUser
Creates and store a new login user in the database, do also attribute mapping is needed. This will also store role membership information.- Parameters:
user
- the user to create in the database.
-
isInvalidUser
Checks whether the user is invalid. MCRUser is not allowed to overwrite information returned byMCRSystemUserInformation.getGuestInstance()
orMCRSystemUserInformation.getSystemUserInstance()
.- Returns:
- true if
createUser(MCRUser)
orupdateUser(MCRUser)
would reject the given user
-
updateUser
Updates an existing login user in the database. This will also update role membership information.- Parameters:
user
- the user to update in the database.
-
deleteUser
Deletes a user from the given database- Parameters:
userName
- the login name of the user to delete, in the default realm.
-
deleteUser
Deletes a user from the given database- Parameters:
userName
- the login name of the user to delete, in the given realm.realm
- the realm the user belongs to
-
deleteUser
Deletes a user from the given database- Parameters:
userName
- the login name of the user to delete, in the given realm.realmId
- the ID of the realm the user belongs to
-
deleteUser
Deletes a user from the given database- Parameters:
user
- the user to delete
-
listUsers
Returns a list of all users the given user is owner of.- Parameters:
owner
- the user that owns other users
-
listUsers
@Deprecated public static List<MCRUser> listUsers(String userPattern, String realm, String namePattern) Deprecated.UselistUsers(String, String, String, String)
instead.Searches for users in the database and returns a list of matching users. Wildcards containing * and ? for single character may be used for searching by login user name or real name. Pay attention that no role information is attached to user data. If you need this information callgetUser(String, String)
.- Parameters:
userPattern
- a wildcard pattern for the login user name, may be nullrealm
- the realm the user belongs to, may be nullnamePattern
- a wildcard pattern for the person's real name, may be null- Returns:
- a list of all matching users
-
listUsers
public static List<MCRUser> listUsers(String userPattern, String realm, String namePattern, String mailPattern) Searches for users in the database and returns a list of all matching users. Wildcards containing * and ? for single character may be used for searching by login user name or real name. Pay attention that no role information is attached to user data. If you need this information callgetUser(String, String)
.- Parameters:
userPattern
- a wildcard pattern for the login user name, may be nullrealm
- the realm the user belongs to, may be nullnamePattern
- a wildcard pattern for the person's real name, may be nullmailPattern
- a wildcard pattern for the person's email, may be null- Returns:
- a list of all matching users
-
listUsers
public static List<MCRUser> listUsers(String userPattern, String realm, String namePattern, String mailPattern, String attributeNamePattern, int offset, int limit) Searches for users in the database and returns a list of matching users. Wildcards containing * and ? for single character may be used for searching by login user name or real name. Pay attention that no role information is attached to user data. If you need this information callgetUser(String, String)
.- Parameters:
userPattern
- a wildcard pattern for the login user name, may be nullrealm
- the realm the user belongs to, may be nullnamePattern
- a wildcard pattern for the person's real name, may be nullmailPattern
- a wildcard pattern for the person's email, may be nullattributeNamePattern
- a wildcard pattern for person's attribute names, may be nulloffset
- an offset for matching userslimit
- a limit for matching users- Returns:
- a list of matching users in offset and limit range
-
countUsers
Deprecated.UsecountUsers(String, String, String, String)
instead.Counts users in the database that match the given criteria. Wildcards containing * and ? for single character may be used for searching by login user name or real name.- Parameters:
userPattern
- a wildcard pattern for the login user name, may be nullrealm
- the realm the user belongs to, may be nullnamePattern
- a wildcard pattern for the person's real name, may be null- Returns:
- the number of matching users
-
countUsers
public static int countUsers(String userPattern, String realm, String namePattern, String mailPattern) Counts users in the database that match the given criteria. Wildcards containing * and ? for single character may be used for searching by login user name or real name.- Parameters:
userPattern
- a wildcard pattern for the login user name, may be nullrealm
- the realm the user belongs to, may be nullnamePattern
- a wildcard pattern for the person's real name, may be nullmailPattern
- a wildcard pattern for the person's email, may be null- Returns:
- the number of matching users
-
countUsers
public static int countUsers(String userPattern, String realm, String namePattern, String mailPattern, String attributeNamePattern) Counts users in the database that match the given criteria. Wildcards containing * and ? for single character may be used for searching by login user name or real name.- Parameters:
userPattern
- a wildcard pattern for the login user name, may be nullrealm
- the realm the user belongs to, may be nullnamePattern
- a wildcard pattern for the person's real name, may be nullmailPattern
- a wildcard pattern for the person's email, may be nullattributeNamePattern
- a wildcard pattern for person's attribute names, may be null- Returns:
- the number of matching users
-
login
Checks the password of a login user in the default realm.- Parameters:
userName
- the login user namepassword
- the password entered in the GUI- Returns:
- true, if the password matches.
-
login
Checks the password of a login user and if the user has at least one of the allowed roles in the default realm.- Parameters:
userName
- the login user namepassword
- the password entered in the GUIallowedRoles
- list of allowed roles- Returns:
- true, if the password matches.
-
getCurrentUser
Returns instance of MCRUser if current user is present in this user system- Returns:
- MCRUser instance or null
-
checkPassword
Returns aMCRUser
instance if the login succeeds. This method will returnnull
if the user does not exist, no password was given or the login is disabled. If theMCRUser.getHashType()
isMCRPasswordHashType.crypt
,MCRPasswordHashType.md5
orMCRPasswordHashType.sha1
the hash value is automatically upgraded toMCRPasswordHashType.sha256
.- Parameters:
userName
- Name of the user to login.password
- clear text password.- Returns:
- authenticated
MCRUser
instance ornull
.
-
setPassword
Sets password of 'user' to 'password'. Automatically updates the user in database.
-
countUsers(String, String, String, String)
instead.