Map restrictions = new HashMap();
restrictions.put(session.getJCRName(ACLTemplate.P_NODE_PATH), vf.createValue(root.getPath(), PropertyType.PATH));
restrictions.put(session.getJCRName(ACLTemplate.P_GLOB), vf.createValue(GlobPattern.WILDCARD_ALL));
PrincipalManager pMgr = session.getPrincipalManager();
AccessControlManager acMgr = session.getAccessControlManager();
Principal administrators;
String pName = SecurityConstants.ADMINISTRATORS_NAME;
if (pMgr.hasPrincipal(pName)) {
administrators = pMgr.getPrincipal(pName);
} else {
log.warn("Administrators principal group is missing.");
administrators = new PrincipalImpl(pName);
}
AccessControlPolicy[] acls = editor.editAccessControlPolicies(administrators);
ACLTemplate acl = (ACLTemplate) acls[0];
if (acl.isEmpty()) {
log.info("... Privilege.ALL for administrators principal.");
acl.addEntry(administrators,
new Privilege[] {acMgr.privilegeFromName(Privilege.JCR_ALL)},
true, restrictions);
editor.setPolicy(acl.getPath(), acl);
} else {
log.info("... policy for administrators principal already present.");
}
Principal everyone = pMgr.getEveryone();
acls = editor.editAccessControlPolicies(everyone);
acl = (ACLTemplate) acls[0];
if (acl.isEmpty()) {
log.info("... Privilege.READ for everyone principal.");
acl.addEntry(everyone,
new Privilege[] {acMgr.privilegeFromName(Privilege.JCR_READ)},
true, restrictions);
editor.setPolicy(acl.getPath(), acl);
} else {
log.info("... policy for everyone principal already present.");
}