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)); }
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()); }
/** Retrieves the MyCoRe object, transforms it to ORCID work xml and validates */ private Document buildWorkXMLFrom(MCRObjectID objectID) throws IOException, SAXParseException { MCRContent mcrObject = MCRXMLMetadataManager.instance().retrieveContent(objectID); MCRContent workXML = T_MCR2WORK.transform(mcrObject); return MCRXMLParserFactory.getValidatingParser().parseXML(workXML); }
/** * 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()); } }
/** * 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); }