Class MCRUserCommands

All Implemented Interfaces:
MCRExternalCommandInterface

@MCRCommandGroup(name="User Commands") public class MCRUserCommands extends MCRAbstractCommands
This class provides a set of commands for the org.mycore.user2 management which can be used by the command line interface.
Author:
Thomas Scheffler (yagee)
  • Constructor Details

    • MCRUserCommands

      public MCRUserCommands()
  • Method Details

    • changeToUser

      @MCRCommand(syntax="change to user {0} with {1}", help="Changes to the user {0} with the given password {1}.", order=10) public static void changeToUser(String user, String password)
      This command changes the user of the session context to a new user.
      Parameters:
      user - the new user ID
      password - the password of the new user
    • login

      @MCRCommand(syntax="login {0}", help="Starts the login dialog for the user {0}.", order=20) public static void login(String user)
      This command changes the user of the session context to a new user.
      Parameters:
      user - the new user ID
    • initSuperuser

      @MCRCommand(syntax="init superuser", help="Initializes the user system. This command runs only if the user database does not exist.", order=30) public static List<String> initSuperuser()
      This method initializes the user and role system an creates a superuser with values set in mycore.properties.private As 'super' default, if no properties were set, mcradmin with password mycore will be used.
    • deleteRole

      @MCRCommand(syntax="delete role {0}", help="Deletes the role {0} from the user system, but only if it has no user assigned.", order=80) public static void deleteRole(String roleID)
      This method invokes MCRRoleManager.deleteRole(String) and permanently removes a role from the system.
      Parameters:
      roleID - the ID of the role which will be deleted
    • exportRole

      @MCRCommand(syntax="export role {0} to directory {1}", help="Export the role {0} to the directory {1}. The filename will be {0}.xml") public static void exportRole(String roleID, String directory) throws IOException
      Exports a single role to the specified directory.
      Throws:
      FileNotFoundException - if target directory does not exist
      IOException
    • addRole

      @MCRCommand(syntax="import role from file {0}", help="Imports a role from file, if that role does not exist", order=90) public static void addRole(String fileName) throws SAXParseException, IOException
      Loads XML from a user and looks for roles currently not present in the system and creates them.
      Parameters:
      fileName - a valid user XML file
      Throws:
      SAXParseException
      IOException
    • deleteUser

      @MCRCommand(syntax="delete user {0}", help="Delete the user {0}.", order=110) public static void deleteUser(String userID) throws Exception
      This method invokes MCRUserMgr.deleteUser() and permanently removes a user from the system.
      Parameters:
      userID - the ID of the user which will be deleted
      Throws:
      Exception
    • enableUser

      @MCRCommand(syntax="enable user {0}", help="Enables the user for the access.", order=60) public static void enableUser(String userID) throws Exception
      This method invokes MCRUserMgr.enableUser() that enables a user
      Parameters:
      userID - the ID of the user which will be enabled
      Throws:
      Exception
    • encryptPasswordsInXMLFile

      @MCRCommand(syntax="encrypt passwords in user xml file {0} to file {1}", help="A migration tool to change old plain text password entries to encrpted entries.", order=40) public static void encryptPasswordsInXMLFile(String oldFile, String newFile) throws SAXParseException, IOException
      A given XML file containing user data with cleartext passwords must be converted prior to loading the user data into the system. This method reads all user objects in the given XML file, encrypts the passwords and writes them back to a file with name original-file-name_encrypted.xml.
      Parameters:
      oldFile - the filename of the user data input
      newFile - the filename of the user data output (encrypted passwords)
      Throws:
      SAXParseException
      IOException
    • disableUser

      @MCRCommand(syntax="disable user {0}", help="Disables access of the user {0}", order=70) public static void disableUser(String userID) throws Exception
      This method invokes MCRUserMgr.disableUser() that disables a user
      Parameters:
      userID - the ID of the user which will be enabled
      Throws:
      Exception
    • listAllUsers

      @MCRCommand(syntax="list all users", help="Lists all users.", order=160) public static void listAllUsers() throws Exception
      This method invokes MCRUserMgr.getAllUserIDs() and retrieves a ArrayList of all users stored in the persistent datastore.
      Throws:
      Exception
    • listAllRoles

      @MCRCommand(syntax="list all roles", help="List all roles.", order=140) public static void listAllRoles() throws Exception
      This method invokes MCRRoleManager.listSystemRoles() and retrieves a list of all roles stored in the persistent datastore.
      Throws:
      Exception
    • exportUserToFile

      @MCRCommand(syntax="export user {0} to file {1}", help="Exports the data of user {0} to the file {1}.", order=180) public static void exportUserToFile(String userID, String filename) throws IOException
      This command takes a userID and file name as a parameter, retrieves the user from MCRUserMgr as JDOM document and export this to the given file.
      Parameters:
      userID - ID of the user to be saved
      filename - Name of the file to store the exported user
      Throws:
      IOException
    • exportAllUserToDirectory

      @MCRCommand(syntax="export all users to directory {0}", help="Exports the data of all users to the directory {0}.") public static List<String> exportAllUserToDirectory(String directory) throws IOException
      Throws:
      IOException
    • importAllUsersFromDirectory

      @MCRCommand(syntax="import all users from directory {0}", help="Imports all users from directory {0}.") public static List<String> importAllUsersFromDirectory(String directory) throws FileNotFoundException
      Throws:
      FileNotFoundException
    • updateAllUsersFromDirectory

      @MCRCommand(syntax="update all users from directory {0}", help="Updates all users from directory {0}.") public static List<String> updateAllUsersFromDirectory(String directory) throws FileNotFoundException
      Throws:
      FileNotFoundException
    • batchLoadFromDirectory

      public static List<String> batchLoadFromDirectory(String cmd, String directory) throws FileNotFoundException
      Throws:
      FileNotFoundException
    • importUserFromFile

      @MCRCommand(syntax="import user from file {0}", help="Imports a user from file {0}.") public static void importUserFromFile(String filename) throws SAXParseException, IOException
      This command takes a file name as a parameter, creates the MCRUser instances stores it in the database if it does not exists.
      Parameters:
      filename - Name of the file to import user from
      Throws:
      SAXParseException
      IOException
    • setPassword

      @MCRCommand(syntax="set password for user {0} to {1}", help="Sets a new password for the user. You must be this user or you must have administrator access.", order=50) public static void setPassword(String userID, String password) throws MCRException
      This method invokes MCRUserMgr.retrieveUser() and then works with the retrieved user object to change the password.
      Parameters:
      userID - the ID of the user for which the password will be set
      Throws:
      MCRException
    • listRole

      @MCRCommand(syntax="list role {0}", help="Lists the role {0}.", order=150) public static void listRole(String roleID) throws MCRException
      This method invokes MCRRoleManager.getRole(String) and then works with the retrieved role object to get an XML-Representation.
      Parameters:
      roleID - the ID of the role for which the XML-representation is needed
      Throws:
      MCRException
    • listRole

      public static void listRole(MCRRole role)
    • listUser

      @MCRCommand(syntax="list user {0}", help="Lists the user {0}.", order=170) public static void listUser(String userID) throws MCRException
      This method invokes MCRUserMgr.retrieveUser() and then works with the retrieved user object to get an XML-Representation.
      Parameters:
      userID - the ID of the user for which the XML-representation is needed
      Throws:
      MCRException
    • listUser

      public static void listUser(MCRUser user)
    • createUserFromFile

      public static void createUserFromFile(String filename) throws SAXParseException, IOException
      This method invokes MCRUserMgr.createUser() with data from a file.
      Parameters:
      filename - the filename of the user data input
      Throws:
      SAXParseException
      IOException
    • updateUserFromFile

      @MCRCommand(syntax="update user from file {0}", help="Updates a user from file {0}.", order=200) public static void updateUserFromFile(String filename) throws SAXParseException, IOException
      This method invokes MCRUserMgr.updateUser() with data from a file.
      Parameters:
      filename - the filename of the user data input
      Throws:
      SAXParseException - if file could not be parsed
      IOException
    • assignUserToRole

      @MCRCommand(syntax="assign user {0} to role {1}", help="Adds a user {0} as secondary member in the role {1}.", order=120) public static void assignUserToRole(String userID, String roleID) throws MCRException
      This method adds a user as a member to a role
      Parameters:
      userID - the ID of the user which will be a member of the role represented by roleID
      roleID - the ID of the role to which the user with ID mbrUserID will be added
      Throws:
      MCRException
    • unassignUserFromRole

      @MCRCommand(syntax="unassign user {0} from role {1}", help="Removes the user {0} as secondary member from the role {1}.", order=130) public static void unassignUserFromRole(String userID, String roleID) throws MCRException
      This method removes a member user from a role
      Parameters:
      userID - the ID of the user which will be removed from the role represented by roleID
      roleID - the ID of the role from which the user with ID mbrUserID will be removed
      Throws:
      MCRException