Search code examples
jackrabbitaemjcrslingcrx

How can I automate applying permissions for a JCR node?


For the CQ5 environment I work on we have a farm of publisher servers. Some of the content on these servers is restricted so only users who belong to certain groups can see the content. I'd like to script the setting of permissions for the folders (nodes) that are to be secured so I don't have to manually repeat the steps of applying security using the Access Control Editor of Content Explorer (This Adobe documentation has instructions for doing it manually via Access Control Editor). The scenario is that sometimes new folders are to be created to hold secure pages, and we want to apply permissions to the folders prior to activating any content into those folders.

Since the environment has several publishers, it is repetitive, manual, and error-prone work to open Content Explorer and set the permissions on each one. I'd like to do be able to automate this so I could roll out permissions to all the servers via a script--perhaps via a curl command or some other mechanism (perhaps a package?) that can be automated.

I found the Sling jackrabbit-accessmanager bundle that seems like it will facilitate automation of this, but it seems like it opens a security hole. If I put this bundle on my publishers, it seems like I would be providing an REST interface to let anyone modify the permissions and grant access to folders/nodes that should be secured or to add security restrictions on nodes that should have none.

How can I automate the creation/modification of node permissions via a script--and do so in a way that only allows an administrator to apply the permissions changes?


Solution

  • I found one alternative I hadn't considered before: using the Day CQ ACL Setup Service. It is mentioned at http://dev.day.com/docs/en/cq/5-5/developing/security_model_changes.html.

    AclSetupService allows one to add permission to a single path or a given user/group. This will be applied on each restart of CQ to guaranteed a certain permission state within CQ. For example, "allow;inherit;everyone;/" prevent everyone from accessing CQ (i.e. it forces all users to login first). As noted in the description of AclSetupService, you will need the following pattern per entry:

    ( "allow" | "deny" ) ";" ( privileges | "inherit" ) ";" principal ";" path

    1. Choose either "allow" or "deny" for the first part.
    2. Next enter one of the privilege below or set it to inherit permission from ancestor.
    3. Then enter a single user/group.
    4. Finally enter a single path to apply the permission to.

    Using this will replace permission set within the repository when you restart CQ. These could be scripted by using the process outlined here and here.

    Privileges can be:
    jcr:read
    rep:write
    jcr:all
    crx:replicate
    imp:setComplete
    jcr:addChildNodes
    jcr:lifecycleManagement
    jcr:lockManagement
    jcr:modifyAccessControl
    jcr:modifyProperties
    jcr:namespaceManagement
    jcr:nodeTypeDefinitionManagement
    jcr:nodeTypeManagement
    jcr:readAccessControl
    jcr:removeChildNodes
    jcr:removeNode
    jcr:retentionManagement
    jcr:versionManagement
    jcr:workspaceManagement
    jcr:write
    rep:privilegeManagement