use of javax.jcr.security.AccessControlList in project jackrabbit by apache.
the class AccessControlManagerImplTest method testRemovePolicyAfterASetPoliciesCall.
/**
* This should be able to return the policies that has been transiently added
* to the node at testRoot, as the getPolicies api specifies that the method should
* take the transient changes into account.
* @throws Exception
*/
public void testRemovePolicyAfterASetPoliciesCall() throws Exception {
try {
AccessControlPolicyIterator policies = acMgr.getApplicablePolicies(testRoot);
while (policies.hasNext()) {
AccessControlList acl = (AccessControlListImpl) policies.nextAccessControlPolicy();
// GRANT read privilege
acl.addAccessControlEntry(getUnknownPrincipal(), privilegesFromName(Privilege.JCR_READ));
acMgr.setPolicy(testRoot, acl);
AccessControlPolicy[] transientPolicy = acMgr.getPolicies(testRoot);
acMgr.removePolicy(testRoot, transientPolicy[0]);
assertEquals(0, acMgr.getPolicies(testRoot).length);
}
} finally {
superuser.refresh(false);
}
}
use of javax.jcr.security.AccessControlList in project jackrabbit by apache.
the class AccessControlManagerImplTest method testRemovePolicyAfterASaveCall.
/**
* Test removing an effective policy.
*/
public void testRemovePolicyAfterASaveCall() throws Exception {
try {
AccessControlList[] acl = (AccessControlList[]) acMgr.getPolicies(testRoot);
if (acl.length > 0) {
acMgr.removePolicy(testRoot, acl[0]);
} else {
AccessControlPolicy policy = acMgr.getApplicablePolicies(testRoot).nextAccessControlPolicy();
acMgr.setPolicy(testRoot, policy);
acMgr.removePolicy(testRoot, policy);
}
// transient removal
AccessControlPolicy[] noPolicies = acMgr.getPolicies(testRoot);
assertEquals(0, noPolicies.length);
// save changes -> removal of protected items on jcr-server
superuser.save();
} catch (Exception e) {
throw new RepositoryException(e.getMessage());
} finally {
superuser.refresh(false);
}
}
use of javax.jcr.security.AccessControlList in project jackrabbit by apache.
the class AccessControlManagerImpl method getPolicies.
public AccessControlPolicy[] getPolicies(String absPath) throws RepositoryException {
checkValidNodePath(absPath);
List<AccessControlList> policies = new ArrayList<AccessControlList>();
NodeState aclNode = getAclNode(absPath);
AccessControlList acl;
if (aclNode != null) {
acl = new AccessControlListImpl(aclNode, absPath, npResolver, qvf, this);
policies.add(acl);
}
return policies.toArray(new AccessControlList[policies.size()]);
}
use of javax.jcr.security.AccessControlList in project kylo by Teradata.
the class JcrAccessControlUtil method getAllPrivileges.
public static Map<Principal, Set<Privilege>> getAllPrivileges(Session session, String path) {
try {
Map<Principal, Set<Privilege>> map = new HashMap<>();
AccessControlManager acm = session.getAccessControlManager();
AccessControlList acl = getAccessControlList(path, acm);
for (AccessControlEntry entry : acl.getAccessControlEntries()) {
Principal principal = derivePrincipal(entry);
map.put(principal, new HashSet<>(Arrays.asList(entry.getPrivileges())));
}
return map;
} catch (AccessDeniedException e) {
throw new AccessControlException(e.getMessage());
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to get the privileges for node " + path, e);
}
}
use of javax.jcr.security.AccessControlList in project kylo by Teradata.
the class JcrAccessControlUtil method removePermissions.
public static boolean removePermissions(Session session, String path, Principal principal, Privilege... removes) {
try {
// There should always be an ACL entry for "admin".
if (removes.length > 0 && !principal.getName().equals(ModeShapeRoles.ADMIN)) {
AccessControlManager acm = session.getAccessControlManager();
AccessControlPolicy[] aclArray = acm.getPolicies(path);
if (aclArray.length > 0) {
AccessControlList acl = (AccessControlList) aclArray[0];
boolean removed = false;
for (AccessControlEntry entry : acl.getAccessControlEntries()) {
if (matchesPrincipal(principal, entry)) {
Privilege[] newPrivs = Arrays.stream(entry.getPrivileges()).filter(p -> !Arrays.stream(removes).anyMatch(r -> r.equals(p))).toArray(Privilege[]::new);
if (entry.getPrivileges().length != newPrivs.length) {
acl.removeAccessControlEntry(entry);
if (newPrivs.length != 0) {
acl.addAccessControlEntry(entry.getPrincipal(), newPrivs);
}
removed = true;
}
}
}
acm.setPolicy(path, acl);
return removed;
} else {
return false;
}
} else {
return false;
}
} catch (AccessDeniedException e) {
throw new AccessControlException(e.getMessage());
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to remove permission(s) from node " + path + ": " + Arrays.toString(removes), e);
}
}
Aggregations