/** * Utility to determine if a given group has any members. * * @param groupTree The tree of the target group. * @return {@code true} if the group has any members i.e. if it has a rep:members * property or a rep:membersList child node. */ private static boolean hasMembers(@NotNull Tree groupTree) { return groupTree.getPropertyStatus(REP_MEMBERS) != null || groupTree.hasChild(REP_MEMBERS_LIST); }
/** * Utility to determine if a given group has any members. * * @param groupTree The tree of the target group. * @return {@code true} if the group has any members i.e. if it has a rep:members * property or a rep:membersList child node. */ private static boolean hasMembers(@NotNull Tree groupTree) { return groupTree.getPropertyStatus(REP_MEMBERS) != null || groupTree.hasChild(REP_MEMBERS_LIST); }
@Override public Collection<PermissionEntry> getEntries(@NotNull Tree accessControlledTree) { return (accessControlledTree.hasChild(AccessControlConstants.REP_POLICY)) ? getEntries(accessControlledTree.getPath()) : Collections.<PermissionEntry>emptyList(); } }
@Override public boolean hasNodeType(String name) throws RepositoryException { Tree types = getTypes(); return types != null && types.hasChild(getOakName(name)); }
private static Tree getOrCreateChild(Tree tree, String name){ if (tree.hasChild(name)){ return tree.getChild(name); } Tree child = tree.addChild(name); child.setOrderableChildren(true); child.setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, NAME); return child; }
private static Tree getOrCreateChild(Tree tree, String name){ if (tree.hasChild(name)){ return tree.getChild(name); } Tree child = tree.addChild(name); child.setOrderableChildren(true); child.setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, NAME); return child; }
@Test public void testHasChild() throws Exception { Tree rootTree = testRoot.getTree("/"); assertTrue(rootTree.hasChild("a")); assertFalse(rootTree.hasChild(AccessControlConstants.REP_POLICY)); Tree a = rootTree.getChild("a"); assertTrue(a.hasChild("b")); assertFalse(a.hasChild("bb")); Tree b = a.getChild("b"); assertTrue(b.hasChild("c")); }
@Test public void testAllowChild() throws Exception { Tree rootTree1 = testRoot1.getTree("/"); Tree rootTree2 = testRoot2.getTree("/"); assertFalse(rootTree1.hasChild("a/bb")); assertFalse(rootTree2.hasChild("a/bb")); // now allow read with root session setupPermission("/a/bb", testPrincipal, true, PrivilegeConstants.JCR_READ); // the test sessions still need to see the old ACLs assertFalse(rootTree1.hasChild("a/bb")); assertFalse(rootTree2.hasChild("a/bb")); }
@Override public boolean matches(@NotNull Tree tree, @Nullable PropertyState property) { boolean match = false; // configured property name found on underlying jcr:content node has precedence if (tree.hasChild(JcrConstants.JCR_CONTENT)) { match = tree.getChild(JcrConstants.JCR_CONTENT).hasProperty(propertyName); } if (!match) { match = tree.hasProperty(propertyName); } return negate ? !match : match; }
@Test public void testGetBitsKnownPrivName() { when(privTree.exists()).thenReturn(true); when(privTree.hasChild(KNOWN_PRIV_NAME)).thenReturn(true); when(privTree.getChild(KNOWN_PRIV_NAME)).thenReturn(pTree); assertEquals(bits.unmodifiable(), bitsProvider.getBits(KNOWN_PRIV_NAME)); }
private Tree createPath(String path){ Tree base = root.getTree("/"); for (String e : PathUtils.elements(path)){ base = base.hasChild(e) ? base.getChild(e) : base.addChild(e); } return base; }
@Test public void testUnknownMember() throws Exception { importer.startChildInfo(createNodeInfo("memberRef", NT_REP_MEMBER_REFERENCES), ImmutableList.of(createPropInfo(REP_MEMBERS, unknownContentId))); importer.processReferences(); // default importbehavior == IGNORE assertFalse(memberRefList.hasChild("memberRef")); }
@Test public void testMixedMembers() throws Exception { importer.startChildInfo(createNodeInfo("memberRef", NT_REP_MEMBER_REFERENCES), ImmutableList.of(createPropInfo(REP_MEMBERS, unknownContentId, knownMemberContentId))); importer.processReferences(); assertFalse(memberRefList.hasChild("memberRef")); }
/** * Test asserting that {@link AuthorizableAction#onCreate(User, String, Root, NamePathMapper)} * is omitted upon calling {@link UserManager#createSystemUser(String, String)}. */ @Test public void testOnCreateOmitted() throws Exception { User user = createUser(null); Tree t = root.getTree(user.getPath()); assertFalse(t.hasChild(AccessControlConstants.REP_POLICY)); } }
@Test public void addExistingChild() throws CommitFailedException { Tree tree = root.getTree("/"); assertFalse(tree.hasChild("new")); tree.addChild("new"); root.commit(); assertTrue(tree.hasChild("new")); Tree added = tree.addChild("new"); assertTrue(added.exists()); assertEquals("new", added.getName()); }
@Test public void testWriteInvalidRestrictions() throws Exception { PropertyState ps = PropertyStates.createProperty(REP_GLOB, valueFactory.createValue(false)); Tree aceTree = getAceTree(); restrictionProvider.writeRestrictions(testPath, aceTree, ImmutableSet.<Restriction>of(new RestrictionImpl(ps, false))); assertTrue(aceTree.hasChild(REP_RESTRICTIONS)); Tree restr = aceTree.getChild(REP_RESTRICTIONS); assertEquals(ps, restr.getProperty(REP_GLOB)); }
@Test public void testPropertiesCompletedClearsCache() throws Exception { Tree userTree = createUserTree(); Tree cacheTree = userTree.addChild(CacheConstants.REP_CACHE); cacheTree.setProperty(JcrConstants.JCR_PRIMARYTYPE, CacheConstants.NT_REP_CACHE); importer.propertiesCompleted(cacheTree); assertFalse(cacheTree.exists()); assertFalse(userTree.hasChild(CacheConstants.REP_CACHE)); }
@Test public void testPolicyChild() throws Exception { assertTrue(root.getTree('/' + AccessControlConstants.REP_POLICY).exists()); // 'testUser' must not have access to the policy node Tree rootTree = testRoot.getTree("/"); assertFalse(rootTree.hasChild(AccessControlConstants.REP_POLICY)); assertFalse(rootTree.getChild(AccessControlConstants.REP_POLICY).exists()); }
@Test public void testOnlySystemCreatesCache() throws Exception { Set<? extends Principal> principals = principalProvider.getPrincipals(getTestUser().getID()); assertPrincipals(principals, EveryonePrincipal.getInstance(), testGroup.getPrincipal(), getTestUser().getPrincipal()); root.refresh(); Tree userTree = root.getTree(getTestUser().getPath()); assertFalse(userTree.hasChild(CacheConstants.REP_CACHE)); }