Programmatically evaluating group permission against a certain node
Hi All,
I am trying to build a report to show permission(of each group) for each cq page in the repository. Basically the table row should look like
| abc_group | /path/to/page | read,write,update |
I use admin session to evaluate group permission/privilege against a cq page node.
String path = "/content/path/to/page";
String group = "abc_group";
Session adminSession = repository.loginAdministrative(null);
JackrabbitAccessControlManager acm = (JackrabbitAccessControlManager) adminSession.getAccessControlManager();
UserManager userManager = resourceResolver.adaptTo(UserManager.class);
Authorizable auth = userManager.getAuthorizable(group);
Set<Principal> principals = new HashSet<Principal>();
principals.add(auth.getPrincipal());
Privilege[] privileges = acm.getPrivileges(path, principals);
for(Privilege p : privileges){
LOGGER.info("group: "+auth.getID()+" privilege: "+p.getName());
}
The problem is that acm.getPrivileges(path, principals) always return an empty privilege.
I also tried doing below to test a given specific privilege, but always return false even if actual group has read permission.
boolean hasRead = acm.hasPrivileges(path, principals, new Privilege[]{acm.privilegeFromName(Privilege.JCR_READ) });
Any input would be helpful.
Thanks!