use of javax.jcr.security.AccessControlPolicy in project jackrabbit by apache.
the class AccessControlPolicyTest method testSetPolicyIsTransient.
public void testSetPolicyIsTransient() throws RepositoryException, AccessDeniedException, NotExecutableException {
checkCanModifyAc(path);
List<AccessControlPolicy> currentPolicies = Arrays.asList(acMgr.getPolicies(path));
AccessControlPolicyIterator it = acMgr.getApplicablePolicies(path);
if (it.hasNext()) {
AccessControlPolicy policy = it.nextAccessControlPolicy();
acMgr.setPolicy(path, policy);
superuser.refresh(false);
String mgs = "Reverting 'setPolicy' must change back the return value of getPolicies.";
if (currentPolicies.isEmpty()) {
assertTrue(mgs, acMgr.getPolicies(path).length == 0);
} else {
assertEquals(mgs, currentPolicies, Arrays.asList(acMgr.getPolicies(path)));
}
} else {
throw new NotExecutableException();
}
}
use of javax.jcr.security.AccessControlPolicy in project jackrabbit-oak by apache.
the class CugAccessControlManagerTest method testGetEffectivePoliciesNotEnabled.
@Test
public void testGetEffectivePoliciesNotEnabled() throws Exception {
cugAccessControlManager.setPolicy(SUPPORTED_PATH, createCug(SUPPORTED_PATH));
root.commit();
ConfigurationParameters config = ConfigurationParameters.of(AuthorizationConfiguration.NAME, ConfigurationParameters.of(CugConstants.PARAM_CUG_SUPPORTED_PATHS, SUPPORTED_PATHS, CugConstants.PARAM_CUG_ENABLED, false));
CugAccessControlManager acMgr = new CugAccessControlManager(root, NamePathMapper.DEFAULT, new CugSecurityProvider(config), ImmutableSet.copyOf(SUPPORTED_PATHS));
AccessControlPolicy[] policies = acMgr.getEffectivePolicies(SUPPORTED_PATH);
assertEquals(0, policies.length);
AccessControlPolicy[] effectiveOnChild = acMgr.getEffectivePolicies(SUPPORTED_PATH + "/subtree");
assertEquals(0, policies.length);
assertEquals(policies.length, effectiveOnChild.length);
}
use of javax.jcr.security.AccessControlPolicy in project jackrabbit-oak by apache.
the class CugAccessControlManagerTest method testSetPolicy.
@Test
public void testSetPolicy() throws Exception {
CugPolicy cug = getApplicableCug(SUPPORTED_PATH);
cug.addPrincipals(EveryonePrincipal.getInstance());
cugAccessControlManager.setPolicy(SUPPORTED_PATH, cug);
AccessControlPolicy[] policies = cugAccessControlManager.getPolicies(SUPPORTED_PATH);
assertEquals(1, policies.length);
AccessControlPolicy policy = policies[0];
assertTrue(policy instanceof CugPolicyImpl);
Set<Principal> principals = ((CugPolicy) policy).getPrincipals();
assertEquals(1, principals.size());
assertEquals(EveryonePrincipal.getInstance(), principals.iterator().next());
}
use of javax.jcr.security.AccessControlPolicy in project jackrabbit-oak by apache.
the class CugAccessControlManagerTest method testRemoveInvalidPolicy.
@Test
public void testRemoveInvalidPolicy() throws Exception {
List<AccessControlPolicy> invalidPolicies = ImmutableList.of(new AccessControlPolicy() {
}, new NamedAccessControlPolicy() {
public String getName() {
return "name";
}
}, InvalidCug.INSTANCE);
for (AccessControlPolicy policy : invalidPolicies) {
try {
cugAccessControlManager.removePolicy(SUPPORTED_PATH, policy);
fail("Invalid cug policy must be detected.");
} catch (AccessControlException e) {
// success
}
}
}
use of javax.jcr.security.AccessControlPolicy in project jackrabbit-oak by apache.
the class CompositeAccessControlManager method getEffectivePolicies.
@Override
public AccessControlPolicy[] getEffectivePolicies(String absPath) throws RepositoryException {
ImmutableList.Builder<AccessControlPolicy> privs = ImmutableList.builder();
for (AccessControlManager acMgr : acMgrs) {
privs.add(acMgr.getEffectivePolicies(absPath));
}
List<AccessControlPolicy> l = privs.build();
return l.toArray(new AccessControlPolicy[l.size()]);
}
Aggregations