Created
September 21, 2023 14:57
-
-
Save a-blank-slate/c5b63d250761f16dbef336f9f443af9a to your computer and use it in GitHub Desktop.
Groovy script to add rep policy for the results pulled in from xpath query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.jackrabbit.api.JackrabbitSession; | |
import org.apache.jackrabbit.api.security.JackrabbitAccessControlList; | |
import org.apache.jackrabbit.api.security.principal.PrincipalManager; | |
import org.apache.jackrabbit.commons.jackrabbit.authorization.AccessControlUtils; | |
import javax.jcr.*; | |
def queryManager = session.workspace.queryManager; | |
def statement = "/jcr:root/content/geeksdemo//*[(jcr:content/@cq:template = '/conf/geeksdemo/settings/wcm/templates/page')]" | |
def query = queryManager.createQuery(statement, 'xpath') | |
final def result = query.execute() | |
result.nodes.each { | |
node -> | |
AccessControlManager accessControlManager = session.getAccessControlManager(); | |
JackrabbitAccessControlList specificPathGroupAcl = AccessControlUtils.getAccessControlList(session, node.path); | |
if (specificPathGroupAcl != null) { | |
JackrabbitSession jackrabbitSession = (JackrabbitSession) session; | |
PrincipalManager principalManager = jackrabbitSession.getPrincipalManager(); | |
Principal principal = principalManager.getPrincipal("admin-test"); | |
Privilege[] privileges = AccessControlUtils.privilegesFromNames(session, Privilege.JCR_REMOVE_NODE); | |
specificPathGroupAcl.addEntry(principal, privileges, false); | |
accessControlManager.setPolicy(specificPathGroupAcl.getPath(), specificPathGroupAcl); | |
session.save(); | |
println "rep policy added"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment