Search in sources :

Example 6 with MCRAccessInterface

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);
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) MCRAccessInterface(org.mycore.access.MCRAccessInterface) Element(org.jdom2.Element) FileOutputStream(java.io.FileOutputStream) Document(org.jdom2.Document) File(java.io.File) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 7 with MCRAccessInterface

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);
        }
    }
}
Also used : Document(org.jdom2.Document) MCRException(org.mycore.common.MCRException) MCRAccessInterface(org.mycore.access.MCRAccessInterface) MCRFileContent(org.mycore.common.content.MCRFileContent) Element(org.jdom2.Element) Element(org.jdom2.Element)

Example 8 with MCRAccessInterface

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);
    }
}
Also used : MCRAccessInterface(org.mycore.access.MCRAccessInterface) Element(org.jdom2.Element) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 9 with MCRAccessInterface

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);
}
Also used : MCRAccessInterface(org.mycore.access.MCRAccessInterface) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 10 with MCRAccessInterface

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 "";
    }
}
Also used : MCRAccessInterface(org.mycore.access.MCRAccessInterface)

Aggregations

MCRAccessInterface (org.mycore.access.MCRAccessInterface)13 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)7 Element (org.jdom2.Element)5 Document (org.jdom2.Document)2 XMLOutputter (org.jdom2.output.XMLOutputter)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 MCRException (org.mycore.common.MCRException)1 MCRFileContent (org.mycore.common.content.MCRFileContent)1 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)1 MCRMetaIFS (org.mycore.datamodel.metadata.MCRMetaIFS)1 MCRMetaLinkID (org.mycore.datamodel.metadata.MCRMetaLinkID)1 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)1 MCRPath (org.mycore.datamodel.niofs.MCRPath)1