use of org.mycore.common.content.MCRFileContent in project mycore by MyCoRe-Org.
the class MCRRealmFactory method getRealms.
private static Document getRealms() throws JDOMException, TransformerException, SAXException, IOException {
if (realmsFile == null) {
return MCRSourceContent.getInstance(realmsURI.toASCIIString()).asXML();
}
if (!realmsFile.exists() || realmsFile.length() == 0) {
LOGGER.info("Creating {}...", realmsFile.getAbsolutePath());
MCRSourceContent realmsContent = MCRSourceContent.getInstance(RESOURCE_REALMS_URI);
realmsContent.sendTo(realmsFile);
}
updateLastModified();
return MCRXMLParserFactory.getNonValidatingParser().parseXML(new MCRFileContent(realmsFile));
}
use of org.mycore.common.content.MCRFileContent in project mycore by MyCoRe-Org.
the class MCRAccessCommands method getRuleFromFile.
private static Element getRuleFromFile(String fileName) throws Exception {
if (!checkFilename(fileName)) {
LOGGER.warn("Wrong file format or file doesn't exist");
return null;
}
Document ruleDom = MCRXMLParserFactory.getParser().parseXML(new MCRFileContent(fileName));
Element rule = ruleDom.getRootElement();
if (!rule.getName().equals("condition")) {
LOGGER.warn("ROOT element is not valid, a valid rule would be for example:");
LOGGER.warn("<condition format=\"xml\"><boolean operator=\"true\" /></condition>");
return null;
}
return rule;
}
use of org.mycore.common.content.MCRFileContent 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.common.content.MCRFileContent in project mycore by MyCoRe-Org.
the class MCRUserCommands method getMCRUserFromFile.
private static MCRUser getMCRUserFromFile(String filename) throws SAXParseException, IOException {
File inputFile = getCheckedFile(filename);
if (inputFile == null) {
return null;
}
LOGGER.info("Reading file {} ...", inputFile.getAbsolutePath());
Document doc = MCRXMLParserFactory.getNonValidatingParser().parseXML(new MCRFileContent(inputFile));
return MCRUserTransformer.buildMCRUser(doc.getRootElement());
}
use of org.mycore.common.content.MCRFileContent 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());
}
}
Aggregations