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

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.

%[https://gist.github.com/a-blank-slate/c5b63d250761f16dbef336f9f443af9a] 

Same way, other permissions under the [`Privilege`](https://developer.adobe.com/experience-manager/reference-materials/spec/jsr170/javadocs/jcr-2.0/javax/jcr/security/Privilege.html)`interface` can be added.

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