Class MCRUserManager

java.lang.Object
org.mycore.user2.MCRUserManager

public class MCRUserManager extends Object
Manages all users using a database table.
Author:
Frank Lützenkirchen, Thomas Scheffler (yagee)
  • Constructor Details

    • MCRUserManager

      public MCRUserManager()
  • Method Details

    • getUser

      public static MCRUser getUser(String userName)
      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

      public static MCRUser getUser(String userName, MCRRealm realm)
      Returns the user with the given userName, in the given realm
      Parameters:
      userName - the unique userName within the given realm
      realm - the realm the user belongs to
      Returns:
      the user with the given login name, or null
    • getUser

      public static MCRUser getUser(String userName, String realmId)
      Returns the user with the given userName, in the given realm
      Parameters:
      userName - the unique userName within the given realm
      realmId - the ID of the realm the user belongs to
      Returns:
      the user with the given login name, or null
    • getUsers

      public static Stream<MCRUser> getUsers(String attrName, String attrValue)
      Returns a Stream of users where the user has a given attribute.
      Parameters:
      attrName - name of the user attribute
      attrValue - value of the user attribute
    • exists

      public static boolean exists(String userName)
      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

      public static boolean exists(String userName, MCRRealm realm)
      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

      public static boolean exists(String userName, String realm)
      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

      public static void createUser(MCRUser user)
      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

      public static void createUser(MCRTransientUser user)
      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

      public static boolean isInvalidUser(MCRUser user)
      Checks whether the user is invalid. MCRUser is not allowed to overwrite information returned by MCRSystemUserInformation.getGuestInstance() or MCRSystemUserInformation.getSystemUserInstance().
      Returns:
      true if createUser(MCRUser) or updateUser(MCRUser) would reject the given user
    • updateUser

      public static void updateUser(MCRUser user)
      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

      public static void deleteUser(String userName)
      Deletes a user from the given database
      Parameters:
      userName - the login name of the user to delete, in the default realm.
    • deleteUser

      public static void deleteUser(String userName, MCRRealm realm)
      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

      public static void deleteUser(String userName, String realmId)
      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

      public static void deleteUser(MCRUser user)
      Deletes a user from the given database
      Parameters:
      user - the user to delete
    • listUsers

      public static List<MCRUser> listUsers(MCRUser owner)
      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)
      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 call getUser(String, String).
      Parameters:
      userPattern - a wildcard pattern for the login user name, may be null
      realm - the realm the user belongs to, may be null
      namePattern - 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 call getUser(String, String).
      Parameters:
      userPattern - a wildcard pattern for the login user name, may be null
      realm - the realm the user belongs to, may be null
      namePattern - a wildcard pattern for the person's real name, may be null
      mailPattern - 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 call getUser(String, String).
      Parameters:
      userPattern - a wildcard pattern for the login user name, may be null
      realm - the realm the user belongs to, may be null
      namePattern - a wildcard pattern for the person's real name, may be null
      mailPattern - a wildcard pattern for the person's email, may be null
      attributeNamePattern - a wildcard pattern for person's attribute names, may be null
      offset - an offset for matching users
      limit - a limit for matching users
      Returns:
      a list of matching users in offset and limit range
    • countUsers

      @Deprecated public static int countUsers(String userPattern, String realm, String namePattern)
      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 null
      realm - the realm the user belongs to, may be null
      namePattern - 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 null
      realm - the realm the user belongs to, may be null
      namePattern - a wildcard pattern for the person's real name, may be null
      mailPattern - 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 null
      realm - the realm the user belongs to, may be null
      namePattern - a wildcard pattern for the person's real name, may be null
      mailPattern - a wildcard pattern for the person's email, may be null
      attributeNamePattern - a wildcard pattern for person's attribute names, may be null
      Returns:
      the number of matching users
    • login

      public static MCRUser login(String userName, String password)
      Checks the password of a login user in the default realm.
      Parameters:
      userName - the login user name
      password - the password entered in the GUI
      Returns:
      true, if the password matches.
    • login

      public static MCRUser login(String userName, String password, List<String> allowedRoles)
      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 name
      password - the password entered in the GUI
      allowedRoles - list of allowed roles
      Returns:
      true, if the password matches.
    • getCurrentUser

      public static MCRUser getCurrentUser()
      Returns instance of MCRUser if current user is present in this user system
      Returns:
      MCRUser instance or null
    • checkPassword

      public static MCRUser checkPassword(String userName, String password)
      Returns a MCRUser instance if the login succeeds. This method will return null if the user does not exist, no password was given or the login is disabled. If the MCRUser.getHashType() is MCRPasswordHashType.crypt, MCRPasswordHashType.md5 or MCRPasswordHashType.sha1 the hash value is automatically upgraded to MCRPasswordHashType.sha256.
      Parameters:
      userName - Name of the user to login.
      password - clear text password.
      Returns:
      authenticated MCRUser instance or null.
    • setPassword

      public static void setPassword(MCRUser user, String password)
      Sets password of 'user' to 'password'. Automatically updates the user in database.