Search in sources :

Example 11 with MCRAccessInterface

use of org.mycore.access.MCRAccessInterface in project mycore by MyCoRe-Org.

the class MCRLayoutUtilities method itemAccess.

/**
 * Verifies a single item on access according to $permission and for a given
 * user
 *
 * @param permission an ACL permission
 * @param item element to check
 * @param access
 *            initial value
 * @param userID a user id
 */
public static boolean itemAccess(String permission, Element item, boolean access, String userID) {
    MCRAccessInterface am = MCRAccessManager.getAccessImpl();
    String objID = getWebpageACLID(item);
    if (am.hasRule(objID, permission)) {
        access = am.checkPermission(objID, permission, userID);
    }
    return access;
}
Also used : MCRAccessInterface(org.mycore.access.MCRAccessInterface)

Example 12 with MCRAccessInterface

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

Example 13 with MCRAccessInterface

use of org.mycore.access.MCRAccessInterface in project mycore by MyCoRe-Org.

the class MCRSwordUtil method createDerivate.

public static MCRDerivate createDerivate(String documentID) throws MCRPersistenceException, IOException, MCRAccessException {
    final String projectId = MCRObjectID.getInstance(documentID).getProjectId();
    MCRObjectID oid = MCRObjectID.getNextFreeId(projectId, "derivate");
    final String derivateID = oid.toString();
    MCRDerivate derivate = new MCRDerivate();
    derivate.setId(oid);
    derivate.setLabel("data object from " + documentID);
    String schema = CONFIG.getString("MCR.Metadata.Config.derivate", "datamodel-derivate.xml").replaceAll(".xml", ".xsd");
    derivate.setSchema(schema);
    MCRMetaLinkID linkId = new MCRMetaLinkID();
    linkId.setSubTag("linkmeta");
    linkId.setReference(documentID, null, null);
    derivate.getDerivate().setLinkMeta(linkId);
    MCRMetaIFS ifs = new MCRMetaIFS();
    ifs.setSubTag("internal");
    ifs.setSourcePath(null);
    derivate.getDerivate().setInternals(ifs);
    LOGGER.debug("Creating new derivate with ID {}", derivateID);
    MCRMetadataManager.create(derivate);
    if (CONFIG.getBoolean("MCR.Access.AddDerivateDefaultRule", true)) {
        MCRAccessInterface AI = MCRAccessManager.getAccessImpl();
        Collection<String> configuredPermissions = AI.getAccessPermissionsFromConfiguration();
        for (String permission : configuredPermissions) {
            MCRAccessManager.addRule(derivateID, permission, MCRAccessManager.getTrueRule(), "default derivate rule");
        }
    }
    final MCRPath rootDir = MCRPath.getPath(derivateID, "/");
    if (Files.notExists(rootDir)) {
        rootDir.getFileSystem().createRoot(derivateID);
    }
    return derivate;
}
Also used : MCRAccessInterface(org.mycore.access.MCRAccessInterface) MCRMetaLinkID(org.mycore.datamodel.metadata.MCRMetaLinkID) MCRDerivate(org.mycore.datamodel.metadata.MCRDerivate) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRMetaIFS(org.mycore.datamodel.metadata.MCRMetaIFS) MCRPath(org.mycore.datamodel.niofs.MCRPath)

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