AEM - Groovy script to add rep:policy based on Query

Manage node permissions using a Groovy script in AEM

Recently, I came across a requirement where we need to add rep:policy to a large number of nodes. We clearly understood that it wouldn't be possible to do it via the usual AEM GUI, as it would be time-consuming work. So, we tried doing it via the Groovy script, where we first found all the nodes via xpath query and then added the allow or deny policies using the AccessControlManager.

Groovy example below contains an XPath query that finds all the pages under "/content/geeksdemo" with template "/conf/geeksdemo/settings/wcm/templates/page" and adds a deny permission of delete to the admin-test group members.

Same way, other permissions under the Privilegeinterface can be added.

That's a wrap. Let me know your feedback on this. Please follow for more such tricks and tutorials.