public Privilege[] getPrivileges(String s) throws RepositoryException { Item item = registrySession.getItem(s); if (item instanceof Property) { throw new PathNotFoundException("No privilages can be added for Properties"); } Set<Privilege> privileges = new HashSet<Privilege>(); if (accessCtrlPolicies.get(s) instanceof RegistryAccessControlList) { AccessControlEntry[] accessNtries = ((RegistryAccessControlList) accessCtrlPolicies.get(s)).getAccessControlEntries(); for (AccessControlEntry ac : accessNtries) { if (ac != null) { privileges.addAll(Arrays.asList(ac.getPrivileges())); } } } else { // TODO check how to apply NamedAccessControlPolicy } // Read-only session must have READ privilege on test node if (RegistryJCRSpecificStandardLoderUtil.isSessionReadOnly(registrySession.getUserID()) && !privileges.contains(privilegeRegistry.getPrivilegeFromName(Privilege.JCR_READ))) { privileges.add(privilegeRegistry.getPrivilegeFromName(Privilege.JCR_READ)); } if (privileges.size() != 0) { return privileges.toArray(new Privilege[privileges.size()]); } else return new Privilege[0]; }
public boolean hasPrivileges(String s, Privilege[] privileges) throws RepositoryException { boolean hasPrivileges = true; Item item = registrySession.getItem(s); if (item instanceof Property) { throw new PathNotFoundException("No privilages can be added for Properties"); } Set<Privilege> temp = new HashSet<Privilege>(); temp.addAll(Arrays.asList(getPrivileges(s))); for (Privilege pv : privileges) { if (!temp.contains(pv)) { hasPrivileges = false; } } return hasPrivileges; }
private static Privilege[] filterPrivileges( Privilege[] privileges, List<Privilege> privilegesToFilterOut) { Set<Privilege> filteredResult = new HashSet<Privilege>(); for (Privilege privilege : privileges) { if (!privilegesToFilterOut.contains(privilege)) { if (privilege.isAggregate() && areIntersecting(privilege.getDeclaredAggregatePrivileges(), privilegesToFilterOut)) { // We de-aggregate a privilege in case any of its children are to be filtered out, since a // privilege is valid only if all its children are valid. filteredResult.addAll( Arrays.asList( filterPrivileges( privilege.getDeclaredAggregatePrivileges(), privilegesToFilterOut))); } else { filteredResult.add(privilege); } } } return filteredResult.toArray(new Privilege[filteredResult.size()]); }