use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRClassification2Commands method repairMissingParent.
@MCRCommand(syntax = "repair missing parent for classification {0}", help = "restores parentID from information in the given classification, if left right values are correct", order = 130)
public static void repairMissingParent(String classID) {
Session session = MCRHIBConnection.instance().getSession();
String sqlQuery = "update {h-schema}MCRCategory cat set cat.parentID=(select parent.internalID from {h-schema}MCRCategory parent WHERE parent.classid='" + classID + "' and parent.leftValue<cat.leftValue and parent.rightValue>cat.rightValue and parent.level=(cat.level-1)) WHERE cat.classid='" + classID + "' and cat.level > 0 and cat.parentID is NULL";
int updates = session.createNativeQuery(sqlQuery).executeUpdate();
LOGGER.info(() -> "Repaired " + updates + " parentID columns for classification " + classID);
}
use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRAccessCommands method permissionDeleteAllForID.
/**
* delete all permissions for a given id
*
* @param id
* String the id of the object the rule is assigned to
*/
@MCRCommand(syntax = "delete all permissions for id {1}", help = "The command delete all access rules for a given id", order = 120)
public static void permissionDeleteAllForID(String id) {
MCRAccessInterface AI = MCRAccessManager.getAccessImpl();
AI.removeAllRules(id);
}
use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRUserCommands method encryptPasswordsInXMLFile.
/**
* 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.
*
* @param oldFile
* the filename of the user data input
* @param newFile
* the filename of the user data output (encrypted passwords)
*/
@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 {
File inputFile = getCheckedFile(oldFile);
if (inputFile == null) {
return;
}
LOGGER.info("Reading file {} ...", inputFile.getAbsolutePath());
Document doc = MCRXMLParserFactory.getNonValidatingParser().parseXML(new MCRFileContent(inputFile));
Element rootelm = doc.getRootElement();
MCRUser mcrUser = MCRUserTransformer.buildMCRUser(rootelm);
if (mcrUser == null) {
throw new MCRException("These data do not correspond to a user.");
}
MCRUserManager.updatePasswordHashToSHA256(mcrUser, mcrUser.getPassword());
FileOutputStream outFile = new FileOutputStream(newFile);
saveToXMLFile(mcrUser, outFile);
}
use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRUserCommands method addRole.
/**
* Loads XML from a user and looks for roles currently not present in the system and creates them.
*
* @param fileName
* a valid user XML file
*/
@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 {
LOGGER.info("Reading file {} ...", fileName);
Document doc = MCRXMLParserFactory.getNonValidatingParser().parseXML(new MCRFileContent(fileName));
MCRRole role = MCRRoleTransformer.buildMCRRole(doc.getRootElement());
if (MCRRoleManager.getRole(role.getName()) == null) {
MCRRoleManager.addRole(role);
} else {
LOGGER.info("Role {} does already exist.", role.getName());
}
}
use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRUserCommands method unassignUserFromRole.
/**
* This method removes a member user from a role
*
* @param userID
* the ID of the user which will be removed from the role represented by roleID
* @param roleID
* the ID of the role from which the user with ID mbrUserID will be removed
*/
@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 {
try {
MCRUser user = MCRUserManager.getUser(userID);
user.unassignRole(roleID);
MCRUserManager.updateUser(user);
} catch (Exception e) {
throw new MCRException("Error while unassigning " + userID + " from role " + roleID + ".", e);
}
}
Aggregations