use of org.mycore.access.MCRAccessInterface in project mycore by MyCoRe-Org.
the class MCRAccessCommands method exportAllPermissionsToFile.
/**
* This method just export the permissions to a file
*
* @param filename
* the file written to
*/
@MCRCommand(syntax = "export all permissions to file {0}", help = "Export all permissions from the Access Control System to the file {0}.", order = 50)
public static void exportAllPermissionsToFile(String filename) throws Exception {
MCRAccessInterface AI = MCRAccessManager.getAccessImpl();
Element mcrpermissions = new Element("mcrpermissions");
mcrpermissions.addNamespaceDeclaration(XSI_NAMESPACE);
mcrpermissions.addNamespaceDeclaration(XLINK_NAMESPACE);
mcrpermissions.setAttribute("noNamespaceSchemaLocation", "MCRPermissions.xsd", XSI_NAMESPACE);
Document doc = new Document(mcrpermissions);
Collection<String> permissions = AI.getPermissions();
for (String permission : permissions) {
Element mcrpermission = new Element("mcrpermission");
mcrpermission.setAttribute("name", permission);
String ruleDescription = AI.getRuleDescription(permission);
if (!ruleDescription.equals("")) {
mcrpermission.setAttribute("ruledescription", ruleDescription);
}
Element rule = AI.getRule(permission);
mcrpermission.addContent(rule);
mcrpermissions.addContent(mcrpermission);
}
File file = new File(filename);
if (file.exists()) {
LOGGER.warn("File {} yet exists, overwrite.", filename);
}
FileOutputStream fos = new FileOutputStream(file);
LOGGER.info("Writing to file {} ...", filename);
String mcr_encoding = CONFIG.getString("MCR.Metadata.DefaultEncoding", DEFAULT_ENCODING);
XMLOutputter out = new XMLOutputter(Format.getPrettyFormat().setEncoding(mcr_encoding));
out.output(doc, fos);
}
use of org.mycore.access.MCRAccessInterface in project mycore by MyCoRe-Org.
the class MCRAccessCommands method createPermissionsFromFile.
/**
* This method sets the new permissions given in a certain file
*
* @param filename
* the filename of the file that contains the mcrpermissions
*/
public static void createPermissionsFromFile(String filename) throws Exception {
MCRAccessInterface AI = MCRAccessManager.getAccessImpl();
if (!checkFilename(filename)) {
return;
}
LOGGER.info("Reading file {} ...", filename);
org.jdom2.Document doc = MCRXMLParserFactory.getValidatingParser().parseXML(new MCRFileContent(filename));
org.jdom2.Element rootelm = doc.getRootElement();
if (!rootelm.getName().equals("mcrpermissions")) {
throw new MCRException("The data are not for mcrpermissions.");
}
List<Element> listelm = rootelm.getChildren("mcrpermission");
for (Element mcrpermission : listelm) {
String permissionName = mcrpermission.getAttributeValue("name").trim();
String ruleDescription = mcrpermission.getAttributeValue("ruledescription");
if (ruleDescription == null) {
ruleDescription = "";
}
Element rule = mcrpermission.getChild("condition").clone();
String objectid = mcrpermission.getAttributeValue("objectid");
if (objectid == null) {
AI.addRule(permissionName, rule, ruleDescription);
} else {
AI.addRule(objectid, permissionName, rule, ruleDescription);
}
}
}
use of org.mycore.access.MCRAccessInterface in project mycore by MyCoRe-Org.
the class MCRAccessCommands method permissionUpdateForSelected.
/**
* updates the permissions for all ids of a given MCRObjectID-Type and for a
* given permission type with a given rule
*
* @param permission
* String type of permission like read, writedb, etc.
* @param strFileRule
* String the path to the xml file, that contains the rule
* @param description
* String give a special description, if the semantics of your
* rule is multiple used
*/
@MCRCommand(syntax = "update permission {0} for selected with rulefile {1} described by {2}", help = "The command updates access rule for a given permission and all ids of a given MCRObject-Type with a given special rule", order = 80)
public static void permissionUpdateForSelected(String permission, String strFileRule, String description) throws Exception {
MCRAccessInterface AI = MCRAccessManager.getAccessImpl();
Element rule = getRuleFromFile(strFileRule);
if (rule == null) {
return;
}
for (String id : MCRObjectCommands.getSelectedObjectIDs()) {
AI.addRule(id, permission, rule, description);
}
}
use of org.mycore.access.MCRAccessInterface in project mycore by MyCoRe-Org.
the class MCRAccessCommands method permissionDeleteForID.
/**
* delete a given permission for a given id
*
* @param permission
* String type of permission like read, writedb, etc.
* @param id
* String the id of the object the rule is assigned to
*/
@MCRCommand(syntax = "delete permission {0} for id {1}", help = "The command delete access rule for a given id of a given permission", order = 110)
public static void permissionDeleteForID(String permission, String id) {
MCRAccessInterface AI = MCRAccessManager.getAccessImpl();
AI.removeRule(id, permission);
}
use of org.mycore.access.MCRAccessInterface in project mycore by MyCoRe-Org.
the class MCRLayoutUtilities method getRuleDescr.
public static String getRuleDescr(String permission, String webpageID) {
MCRAccessInterface am = MCRAccessManager.getAccessImpl();
String ruleDes = am.getRuleDescription(getWebpageACLID(webpageID), permission);
if (ruleDes != null) {
return ruleDes;
} else {
return "";
}
}
Aggregations