PrincipalPolicyImpl extends AbstractAccessControlList implements PrincipalAccessControlList { boolean addEntry(@NotNull Tree entryTree) throws AccessControlException { String oakPath = Strings.emptyToNull(TreeUtil.getString(entryTree, REP_EFFECTIVE_PATH)); PrivilegeBits bits = privilegeBitsProvider.getBits(entryTree.getProperty(Constants.REP_PRIVILEGES).getValue(Type.NAMES)); Set<Restriction> restrictions = restrictionProvider.readRestrictions(oakPath, entryTree); return addEntry(new EntryImpl(oakPath, bits, restrictions)); } PrincipalPolicyImpl(@NotNull Principal principal, @NotNull String oakPath, @NotNull MgrProvider mgrProvider); @Override @NotNull List<EntryImpl> getEntries(); @Override @NotNull RestrictionProvider getRestrictionProvider(); @Override @NotNull Principal getPrincipal(); @Override boolean addEntry(@Nullable String effectivePath, @NotNull Privilege[] privileges); @Override boolean addEntry(@Nullable String effectivePath, @NotNull Privilege[] privileges, @NotNull Map<String, Value> restrictions, @NotNull Map<String, Value[]> mvRestrictions); @Override boolean addEntry(@NotNull Principal principal, @NotNull Privilege[] privileges, boolean isAllow, @Nullable Map<String, Value> restrictions, @Nullable Map<String, Value[]> mvRestrictions); @Override void orderBefore(@NotNull AccessControlEntry srcEntry, @Nullable AccessControlEntry destEntry); @Override void removeAccessControlEntry(AccessControlEntry ace);  }
@Test public void testAddEntry() throws Exception { assertTrue(emptyPolicy.addEntry(testJcrPath, privilegesFromNames(PrivilegeConstants.JCR_ADD_CHILD_NODES))); assertEquals(1, emptyPolicy.size()); }
@Test public void testAddEntryWithRestrictionsTwice() throws Exception { Map<String, Value> restrictions = createGlobRestriction("*/some*glob"); assertTrue(policy.addEntry(testJcrPath, privilegesFromNames(PrivilegeConstants.JCR_READ_ACCESS_CONTROL, PrivilegeConstants.JCR_MODIFY_ACCESS_CONTROL), restrictions, Collections.emptyMap())); assertFalse(policy.addEntry(testJcrPath, privilegesFromNames(PrivilegeConstants.JCR_READ_ACCESS_CONTROL, PrivilegeConstants.JCR_MODIFY_ACCESS_CONTROL), restrictions, Collections.emptyMap())); }
@Test(expected = AccessControlException.class) public void testAddEntryWithRelativePath() throws Exception { emptyPolicy.addEntry("relative/path", privilegesFromNames(PrivilegeConstants.JCR_ADD_CHILD_NODES)); }
@Test(expected = AccessControlException.class) public void testAddEntryWithEmptyPath() throws Exception { emptyPolicy.addEntry("", privilegesFromNames(PrivilegeConstants.JCR_REMOVE_NODE)); }
@Test(expected = AccessControlException.class) public void testAddEntryEmptyPrivileges() throws Exception { policy.addEntry(testJcrPath, new Privilege[0]); }
@Test(expected = AccessControlException.class) public void testAddEntryUnknownPrivilege() throws Exception { Privilege privilege = when(mock(Privilege.class).getName()).thenReturn("unknown").getMock(); policy.addEntry(testJcrPath, new Privilege[] {privilege}); }
@Test(expected = AccessControlException.class) public void testAddAccessControlEntryDifferentPrincipal() throws Exception { policy.addEntry(EveryonePrincipal.getInstance(), privilegesFromNames(JCR_ALL), true, null, Collections.emptyMap()); }
@Test(expected = AccessControlException.class) public void testAddDenyingAccessControlEntry() throws Exception { policy.addEntry(principal, privilegesFromNames(PrivilegeConstants.REP_READ_NODES), false, Collections.emptyMap(), null); }
@Test(expected = AccessControlException.class) public void testAddAccessControlEntryMissingNodePath() throws Exception { policy.addEntry(principal, privilegesFromNames(PrivilegeConstants.REP_USER_MANAGEMENT), true, Collections.emptyMap(), Collections.singletonMap(AccessControlConstants.REP_NT_NAMES, new Value[] {getValueFactory(root).createValue(NodeTypeConstants.NT_REP_SYSTEM)})); }
@Test(expected = AccessControlException.class) public void testAddAccessControlEntryMissingNodePath2() throws Exception { policy.addEntry(principal, privilegesFromNames(PrivilegeConstants.REP_WRITE), true, null, null); }