use of org.apache.jackrabbit.oak.spi.security.authorization.cug.CugPolicy in project jackrabbit-oak by apache.
the class CugPolicyImplTest method testAddInvalidPrincipalsIgnore.
@Test
public void testAddInvalidPrincipalsIgnore() throws Exception {
CugPolicy cug = new CugPolicyImpl(path, NamePathMapper.DEFAULT, principalManager, ImportBehavior.IGNORE, principals);
assertTrue(cug.addPrincipals(new PrincipalImpl("unknown"), EveryonePrincipal.getInstance()));
Set<Principal> principalSet = cug.getPrincipals();
assertEquals(2, principalSet.size());
assertFalse(principalSet.contains(new PrincipalImpl("unknown")));
assertFalse(principalSet.contains(new PrincipalImpl("")));
}
use of org.apache.jackrabbit.oak.spi.security.authorization.cug.CugPolicy in project jackrabbit-oak by apache.
the class AbstractCugTest method createCug.
void createCug(@Nonnull String absPath, @Nonnull Principal principal) throws RepositoryException {
AccessControlManager acMgr = getAccessControlManager(root);
AccessControlPolicyIterator it = acMgr.getApplicablePolicies(absPath);
while (it.hasNext()) {
AccessControlPolicy policy = it.nextAccessControlPolicy();
if (policy instanceof CugPolicy) {
((CugPolicy) policy).addPrincipals(principal);
acMgr.setPolicy(absPath, policy);
return;
}
}
throw new IllegalStateException("Unable to create CUG at " + absPath);
}
use of org.apache.jackrabbit.oak.spi.security.authorization.cug.CugPolicy in project jackrabbit-oak by apache.
the class CugAccessControlManagerTest method testGetPoliciesAfterManualCreation.
@Test
public void testGetPoliciesAfterManualCreation() throws Exception {
NodeUtil n = new NodeUtil(root.getTree(SUPPORTED_PATH));
NodeUtil cug = n.addChild(REP_CUG_POLICY, NT_REP_CUG_POLICY);
AccessControlPolicy[] policies = cugAccessControlManager.getPolicies(SUPPORTED_PATH);
assertEquals(1, policies.length);
assertTrue(policies[0] instanceof CugPolicy);
CugPolicy cugPolicy = (CugPolicy) policies[0];
assertTrue(cugPolicy.getPrincipals().isEmpty());
cug.setStrings(REP_PRINCIPAL_NAMES, "unknownPrincipalName", EveryonePrincipal.NAME);
policies = cugAccessControlManager.getPolicies(SUPPORTED_PATH);
cugPolicy = (CugPolicy) policies[0];
assertEquals(2, cugPolicy.getPrincipals().size());
}
use of org.apache.jackrabbit.oak.spi.security.authorization.cug.CugPolicy in project jackrabbit-oak by apache.
the class CugAccessControlManagerTest method testRemovePolicy.
@Test
public void testRemovePolicy() throws Exception {
CugPolicy cug = getApplicableCug(SUPPORTED_PATH);
cugAccessControlManager.setPolicy(SUPPORTED_PATH, cug);
cugAccessControlManager.removePolicy(SUPPORTED_PATH, cugAccessControlManager.getPolicies(SUPPORTED_PATH)[0]);
assertArrayEquals(new AccessControlPolicy[0], cugAccessControlManager.getPolicies(SUPPORTED_PATH));
}
use of org.apache.jackrabbit.oak.spi.security.authorization.cug.CugPolicy in project jackrabbit-oak by apache.
the class CugAccessControlManagerTest method testSetPolicyPersisted.
@Test
public void testSetPolicyPersisted() throws Exception {
CugPolicy cug = getApplicableCug(SUPPORTED_PATH);
cug.addPrincipals(EveryonePrincipal.getInstance());
cugAccessControlManager.setPolicy(SUPPORTED_PATH, cug);
root.commit();
Tree tree = root.getTree(SUPPORTED_PATH);
assertTrue(TreeUtil.isNodeType(tree, CugConstants.MIX_REP_CUG_MIXIN, root.getTree(NodeTypeConstants.NODE_TYPES_PATH)));
Tree cugTree = tree.getChild(CugConstants.REP_CUG_POLICY);
assertTrue(cugTree.exists());
assertEquals(CugConstants.NT_REP_CUG_POLICY, TreeUtil.getPrimaryTypeName(cugTree));
PropertyState prop = cugTree.getProperty(CugConstants.REP_PRINCIPAL_NAMES);
assertNotNull(prop);
assertTrue(prop.isArray());
assertEquals(Type.STRINGS, prop.getType());
assertEquals(1, prop.count());
assertEquals(EveryonePrincipal.NAME, prop.getValue(Type.STRING, 0));
}
Aggregations