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

Ashish MishraAshish Mishra
1 min read

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.

0
Subscribe to my newsletter

Read articles from Ashish Mishra directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ashish Mishra
Ashish Mishra

I am an AEM Full Stack Developer. I like to work on different technologies, and to build different Apps, Bots. Have Created this blog to write down and share all my works.