@Override public void before() throws Exception { super.before(); NodeUtil testNode = new NodeUtil(root.getTree("/")).addChild("test", NT_OAK_UNSTRUCTURED); testNode.addChild("a", NT_OAK_UNSTRUCTURED).addChild("b", NT_OAK_UNSTRUCTURED).addChild("c", NT_OAK_UNSTRUCTURED); TreeUtil.addMixin(testNode.getTree(), MIX_VERSIONABLE, root.getTree(NODE_TYPES_PATH), null); AccessControlManager acMgr = getAccessControlManager(root); AccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, "/test"); acl.addAccessControlEntry(EveryonePrincipal.getInstance(), AccessControlUtils.privilegesFromNames(acMgr, PrivilegeConstants.JCR_READ)); acMgr.setPolicy("/test", acl); root.commit(); // create a structure in the version storage testNode.setBoolean(JCR_ISCHECKEDOUT, false); root.commit(); testNode.setBoolean(JCR_ISCHECKEDOUT, true); root.commit(); testTree = testNode.getTree(); vMgr = ReadOnlyVersionManager.getInstance(root, NamePathMapper.DEFAULT); pp = getConfig(AuthorizationConfiguration.class).getPermissionProvider(root, root.getContentSession().getWorkspaceName(), ImmutableSet.<Principal>of(EveryonePrincipal.getInstance())); assertTrue(pp instanceof PermissionProviderImpl); vpField = VersionTreePermission.class.getDeclaredField("versionablePermission"); vpField.setAccessible(true); Class cls = Class.forName(CompiledPermissionImpl.class.getName() + "$TreePermissionImpl"); tpImplTree = cls.getDeclaredField("tree"); tpImplTree.setAccessible(true); }
@Test public void testValidateRestrictionsWrongType() throws Exception { Restriction mand = restrictionProvider.createRestriction(testPath, "mandatory", valueFactory.createValue(true)); try { Tree ace = getAceTree(mand); new NodeUtil(ace).getChild(REP_RESTRICTIONS).setBoolean(REP_GLOB, true); restrictionProvider.validateRestrictions(testPath, ace); fail("wrong type with restriction 'rep:glob"); } catch (AccessControlException e) { // success } }
@Test public void testReadRestrictions() throws Exception { NodeUtil aceNode = new NodeUtil(root.getTree("/")).addChild("test", NT_REP_GRANT_ACE); aceNode.setBoolean("boolean", true); aceNode.setValues("longs", new Value[] {vf.createValue(10), vf.createValue(290)}); aceNode.setString(REP_GLOB, "*"); aceNode.setNames(REP_NT_NAMES); // empty array aceNode.setString("invalid", "val"); aceNode.setStrings("invalid2", "val1", "val2", "val3"); Set<Restriction> restrictions = provider.readRestrictions("/test", aceNode.getTree()); assertEquals(4, restrictions.size()); for (Restriction r : restrictions) { String name = r.getDefinition().getName(); if (!supported.contains(name)) { fail("read unsupported restriction"); } } }
@Test public void testValidateRestrictionsAtEntryNode() throws Exception { NodeUtil aceNode = new NodeUtil(root.getTree("/")).addChild("test", NT_REP_GRANT_ACE); aceNode.setBoolean("boolean", true); aceNode.setValues("longs", new Value[] {vf.createValue(10), vf.createValue(290)}); aceNode.setString(REP_GLOB, "*"); aceNode.setNames(REP_NT_NAMES); // empty array provider.validateRestrictions("/test", aceNode.getTree()); }
/** * Creating a referenceable tree with an invalid jcr:uuid must fail. */ @Test public void testCreateBooleanJcrUuid() throws Exception { setupPermission("/a", testPrincipal, true, PrivilegeConstants.JCR_READ, PrivilegeConstants.JCR_ADD_CHILD_NODES); try { Root testRoot = getTestRoot(); testRoot.refresh(); NodeUtil a = new NodeUtil(testRoot.getTree("/a")); NodeUtil test = a.addChild("referenceable2", NT_NAME); test.setBoolean(JcrConstants.JCR_UUID, false); testRoot.commit(); fail("Creating a referenceable node with an boolean uuid must fail."); } catch (CommitFailedException e) { assertTrue(e.isConstraintViolation()); } }
@Test public void testGetRestrictionPattern() throws Exception { NodeUtil aceNode = new NodeUtil(root.getTree("/")).addChild("test", NT_REP_GRANT_ACE); NodeUtil rNode = aceNode.addChild(REP_RESTRICTIONS, NT_REP_RESTRICTIONS); rNode.setString(REP_GLOB, "*"); assertFalse(provider.getPattern("/test", aceNode.getTree()) instanceof CompositePattern); rNode.setBoolean("boolean", true); rNode.setValues("longs", new Value[]{vf.createValue(10), vf.createValue(290)}); assertTrue(provider.getPattern("/test", rNode.getTree()) instanceof CompositePattern); } }
@Before @Override public void before() throws Exception { super.before(); NodeUtil rootNode = new NodeUtil(root.getTree("/")); NodeUtil testRootNode = rootNode.addChild("testRoot", NT_UNSTRUCTURED); NodeUtil a = testRootNode.addChild("a", NT_UNSTRUCTURED); NodeUtil b = a.addChild("b", NT_UNSTRUCTURED); NodeUtil c = b.addChild("c", NT_UNSTRUCTURED); c.setBoolean(PROP_NAME_PROTECT_ME, true); NodeUtil d = c.addChild("d", NT_UNSTRUCTURED); d.addChild("e", NT_UNSTRUCTURED); root.commit(); testPrincipal = getTestUser().getPrincipal(); }
NodeUtil aceNode = new NodeUtil(root.getTree("/")).addChild("test", NT_REP_GRANT_ACE); NodeUtil rNode = aceNode.addChild(REP_RESTRICTIONS, NT_REP_RESTRICTIONS); rNode.setBoolean("boolean", true); rNode.setValues("longs", new Value[] {vf.createValue(10), vf.createValue(290)}); rNode.setString(REP_GLOB, "*"); rNode.setBoolean("boolean", true);