AccessControlValidator extends DefaultValidator implements AccessControlConstants { @Override public Validator childNodeAdded(String name, NodeState after) throws CommitFailedException { Tree treeAfter = checkNotNull(parentAfter.getChild(name)); checkValidTree(parentAfter, treeAfter, after); return newValidator(this, treeAfter); } AccessControlValidator(@NotNull NodeState parentAfter,
                           @NotNull PrivilegeManager privilegeManager,
                           @NotNull PrivilegeBitsProvider privilegeBitsProvider,
                           @NotNull RestrictionProvider restrictionProvider,
                           @NotNull ProviderCtx providerCtx); private  AccessControlValidator(AccessControlValidator parent, Tree parentAfter); @Override void propertyAdded(PropertyState after); @Override void propertyChanged(PropertyState before, PropertyState after); @Override void propertyDeleted(PropertyState before); @Override Validator childNodeAdded(String name, NodeState after); @Override Validator childNodeChanged(String name, NodeState before, NodeState after); @Override Validator childNodeDeleted(String name, NodeState before);  }
@Test(expected = IllegalStateException.class) public void testValidatingPrivilegesCausesInternalError() throws Exception { PrivilegeManager privMgr = when(mock(PrivilegeManager.class).getPrivilege(anyString())).thenThrow(new RepositoryException()).getMock(); PrivilegeConfiguration pc = when( mock(PrivilegeConfiguration.class).getPrivilegeManager(any(Root.class), any(NamePathMapper.class))).thenReturn(privMgr).getMock(); Tree rootTree = root.getTree(PathUtils.ROOT_PATH); Tree policy = createPolicy(rootTree, false); TreeProvider tp = getTreeProvider(); AccessControlValidatorProvider provider = createValidatorProvider(getConfig(AuthorizationConfiguration.class).getRestrictionProvider(), pc); NodeState ns = tp.asNodeState(rootTree); Validator v = provider.getRootValidator(ns, ns, new CommitInfo("sid", null)); v.childNodeAdded(policy.getName(), tp.asNodeState(policy)).childNodeAdded(aceName, tp.asNodeState(policy.getChild(aceName))); }
@Test(expected = CommitFailedException.class) public void testValidatingRestrictionsCausesInternalError() throws Exception { RestrictionProvider rp = spy(getConfig(AuthorizationConfiguration.class).getRestrictionProvider()); doAnswer(invocationOnMock -> { throw new RepositoryException(); }).when(rp).validateRestrictions(anyString(), any(Tree.class)); Tree rootTree = root.getTree(PathUtils.ROOT_PATH); Tree policy = createPolicy(rootTree, false); Tree entry = policy.getChild(aceName); entry.setProperty(REP_GLOB, "any"); TreeProvider tp = getTreeProvider(); AccessControlValidatorProvider provider = createValidatorProvider(rp, getConfig(PrivilegeConfiguration.class)); NodeState ns = tp.asNodeState(rootTree); Validator v = provider.getRootValidator(ns, ns, new CommitInfo("sid", null)); try { v.childNodeAdded(policy.getName(), tp.asNodeState(policy)).childNodeAdded(entry.getName(), tp.asNodeState(entry)); } catch (CommitFailedException e) { throw assertCommitFailedException(e, CommitFailedException.OAK, 13); } }
@Test public void hiddenNodeAdded() throws CommitFailedException { AccessControlValidatorProvider provider = createValidatorProvider(); MemoryNodeStore store = new MemoryNodeStore(); NodeState root = store.getRoot(); NodeBuilder builder = root.builder(); NodeBuilder test = builder.child("test"); NodeBuilder hidden = test.child(":hidden"); Validator validator = provider.getRootValidator( root, builder.getNodeState(), CommitInfo.EMPTY); Validator childValidator = validator.childNodeAdded( "test", test.getNodeState()); assertNotNull(childValidator); Validator hiddenValidator = childValidator.childNodeAdded(":hidden", hidden.getNodeState()); assertNull(hiddenValidator); }
@Test(expected = CommitFailedException.class) public void testAddPolicyTreeWithInvalidName() throws Exception { Tree rootTree = root.getTree(PathUtils.ROOT_PATH); rootTree.setProperty(JCR_MIXINTYPES, ImmutableList.of(MIX_REP_ACCESS_CONTROLLABLE), Type.NAMES); TreeUtil.addChild(rootTree, "invalidName", NT_REP_ACL); Validator v = createRootValidator(rootTree); try { v.childNodeAdded("invalidName", mock(NodeState.class)); } catch (CommitFailedException e) { throw assertCommitFailedException(e, CommitFailedException.ACCESS_CONTROL, 3); } }
@Test(expected = CommitFailedException.class) public void testAddEntyWithEmptyPrivileges() throws Exception { Tree rootTree = root.getTree(PathUtils.ROOT_PATH); Tree policy = createPolicy(rootTree, false); Tree entry = policy.getChild(aceName); entry.setProperty(REP_PRIVILEGES, ImmutableList.of(), Type.NAMES); Validator v = createRootValidator(rootTree); try { v.childNodeAdded(policy.getName(), getTreeProvider().asNodeState(policy)).childNodeAdded(entry.getName(), getTreeProvider().asNodeState(entry)); } catch (CommitFailedException e) { throw assertCommitFailedException(e, CommitFailedException.ACCESS_CONTROL, 9); } }
@Test(expected = CommitFailedException.class) public void testAddEntyWithNullrivileges() throws Exception { Tree rootTree = root.getTree(PathUtils.ROOT_PATH); Tree policy = createPolicy(rootTree, false); Tree entry = policy.getChild(aceName); entry.removeProperty(REP_PRIVILEGES); Validator v = createRootValidator(rootTree); try { v.childNodeAdded(policy.getName(), getTreeProvider().asNodeState(policy)).childNodeAdded(entry.getName(), getTreeProvider().asNodeState(entry)); } catch (CommitFailedException e) { throw assertCommitFailedException(e, CommitFailedException.ACCESS_CONTROL, 9); } }
@Test(expected = CommitFailedException.class) public void testAddEntyWithEmptyPrincipalName() throws Exception { Tree rootTree = root.getTree(PathUtils.ROOT_PATH); Tree policy = createPolicy(rootTree, false); Tree entry = policy.getChild(aceName); entry.setProperty(REP_PRINCIPAL_NAME, ""); Validator v = createRootValidator(rootTree); try { v.childNodeAdded(policy.getName(), getTreeProvider().asNodeState(policy)).childNodeAdded(entry.getName(), getTreeProvider().asNodeState(entry)); } catch (CommitFailedException e) { throw assertCommitFailedException(e, CommitFailedException.ACCESS_CONTROL, 8); } }
@Test(expected = CommitFailedException.class) public void testAddEntyWithNullPrincipalName() throws Exception { Tree rootTree = root.getTree(PathUtils.ROOT_PATH); Tree policy = createPolicy(rootTree, false); Tree entry = policy.getChild(aceName); entry.removeProperty(REP_PRINCIPAL_NAME); Validator v = createRootValidator(rootTree); try { v.childNodeAdded(policy.getName(), getTreeProvider().asNodeState(policy)).childNodeAdded(entry.getName(), getTreeProvider().asNodeState(entry)); } catch (CommitFailedException e) { throw assertCommitFailedException(e, CommitFailedException.ACCESS_CONTROL, 8); } }