use of javax.jcr.security.AccessControlPolicy in project jackrabbit by apache.
the class AclRemoveHandler method remove.
@Override
public boolean remove(Session session, String itemPath) throws RepositoryException {
if (canHandle(session, itemPath)) {
String controlledPath = Text.getRelativeParent(itemPath, 1);
AccessControlManager acMgr = session.getAccessControlManager();
AccessControlPolicy[] policies = acMgr.getPolicies(controlledPath);
for (AccessControlPolicy policy : policies) {
acMgr.removePolicy(controlledPath, policy);
}
return true;
}
return false;
}
use of javax.jcr.security.AccessControlPolicy in project jackrabbit-oak by apache.
the class CompositeAccessControlManagerTest method testGetPolicies.
@Test
public void testGetPolicies() throws Exception {
int len = 0;
AccessControlPolicy[] policies = acMgr.getPolicies(TEST_PATH);
assertEquals(len, policies.length);
acMgr.setPolicy(TEST_PATH, TestPolicy.INSTANCE);
len++;
policies = acMgr.getPolicies(TEST_PATH);
assertEquals(len, policies.length);
assertSame(TestPolicy.INSTANCE, policies[0]);
AccessControlPolicyIterator it = acMgr.getApplicablePolicies(TEST_PATH);
while (it.hasNext()) {
AccessControlPolicy plc = it.nextAccessControlPolicy();
if (plc == TestPolicy.INSTANCE) {
fail("TestPolicy should only be applicable at /test.");
} else {
acMgr.setPolicy(TEST_PATH, plc);
len++;
Set<AccessControlPolicy> policySet = ImmutableSet.copyOf(acMgr.getPolicies(TEST_PATH));
assertEquals(len, policySet.size());
assertTrue(policySet.contains(TestPolicy.INSTANCE));
assertTrue(policySet.contains(plc));
}
}
}
use of javax.jcr.security.AccessControlPolicy in project jackrabbit-oak by apache.
the class CompositeAccessControlManagerTest method testGetApplicablePolicies.
@Test
public void testGetApplicablePolicies() throws Exception {
AccessControlPolicyIterator it = acMgr.getApplicablePolicies("/");
while (it.hasNext()) {
if (it.nextAccessControlPolicy() == TestPolicy.INSTANCE) {
fail("TestPolicy should only be applicable at /test.");
}
}
Set<AccessControlPolicy> applicable = ImmutableSet.copyOf(acMgr.getApplicablePolicies(TEST_PATH));
assertEquals(2, applicable.size());
assertTrue(applicable.contains(TestPolicy.INSTANCE));
}
use of javax.jcr.security.AccessControlPolicy in project jackrabbit-oak by apache.
the class CompositeAccessControlManagerTest method testSetPolicyAtRoot.
@Test
public void testSetPolicyAtRoot() throws Exception {
AccessControlPolicyIterator it = acMgr.getApplicablePolicies("/");
int cnt = 0;
while (it.hasNext()) {
AccessControlPolicy plc = it.nextAccessControlPolicy();
assertTrue(plc instanceof JackrabbitAccessControlList);
acMgr.setPolicy("/", plc);
cnt++;
}
assertEquals(1, cnt);
}
use of javax.jcr.security.AccessControlPolicy in project jackrabbit-oak by apache.
the class UserImportWithActionsTest method testAccessControlActionExecutionForUser.
@Test
public void testAccessControlActionExecutionForUser() throws Exception {
AccessControlAction a1 = new AccessControlAction();
a1.init(securityProvider, ConfigurationParameters.of(AccessControlAction.USER_PRIVILEGE_NAMES, new String[] { Privilege.JCR_ALL }));
setAuthorizableActions(a1);
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<sv:node sv:name=\"t\" xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\" xmlns:fn_old=\"http://www.w3.org/2004/10/xpath-functions\" xmlns:fn=\"http://www.w3.org/2005/xpath-functions\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\" xmlns:rep=\"internal\" xmlns:jcr=\"http://www.jcp.org/jcr/1.0\">" + " <sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:User</sv:value></sv:property>" + " <sv:property sv:name=\"jcr:uuid\" sv:type=\"String\"><sv:value>e358efa4-89f5-3062-b10d-d7316b65649e</sv:value></sv:property>" + " <sv:property sv:name=\"rep:password\" sv:type=\"String\"><sv:value>{sha1}8efd86fb78a56a5145ed7739dcb00c78581c5375</sv:value></sv:property>" + " <sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>tPrincipal</sv:value></sv:property>" + "</sv:node>";
doImport(USERPATH, xml);
Authorizable a = getUserManager().getAuthorizable("t");
assertNotNull(a);
assertFalse(a.isGroup());
AccessControlManager acMgr = getImportSession().getAccessControlManager();
AccessControlPolicy[] policies = acMgr.getPolicies(a.getPath());
assertNotNull(policies);
assertEquals(1, policies.length);
assertTrue(policies[0] instanceof AccessControlList);
AccessControlEntry[] aces = ((AccessControlList) policies[0]).getAccessControlEntries();
assertEquals(1, aces.length);
assertEquals("tPrincipal", aces[0].getPrincipal().getName());
}
Aggregations