/** * 11. >/a:/b >/b:/c = >/a:/c * See http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/ChangeLog.java?view=markup * Line 236 */ @Test public void test11() { MoveTracker mt = new MoveTracker(); mt.addMove("/a", "/b"); mt.addMove("/b", "/c"); assertEquals("/a", mt.getSourcePath("/c")); assertEquals("/c", mt.getDestPath("/a")); }
@Test public void testNotEmpty() { MoveTracker mt = new MoveTracker(); mt.addMove("/a/b/c", "/d/e/f"); assertFalse(mt.isEmpty()); }
private boolean containsMove(@Nullable Tree parentBefore, @Nullable Tree parentAfter) { return moveTracker.containsMove(PermissionUtil.getPath(parentBefore, parentAfter)); }
void assertResult() { // map destination -> original path for (String dest : src2dest.values()) { String expectedOrgSource = dest2orig.get(dest); assertEquals(expectedOrgSource, mt.getSourcePath(dest)); } // map original path -> destination for (String original : orig2dest.keySet()) { assertEquals(orig2dest.get(original), mt.getDestPath(original)); } } }
@Test public void testGetValidators() { assertTrue(configuration.getValidators("workspaceName", ImmutableSet.of(), new MoveTracker()).isEmpty()); }
@Test public void testIsEmpty() { assertTrue(new MoveTracker().isEmpty()); }
MoveTest addMove(String src, String dst, String originalSrc) { src2dest.put(src, dst); dest2orig.put(dst, originalSrc); orig2dest.put(originalSrc, dst); mt.addMove(src, dst); return this; }
@Override @NotNull public Validator getRootValidator( NodeState before, NodeState after, CommitInfo info) { PermissionProvider pp = acConfig.getPermissionProvider(createReadOnlyRoot(before), workspaceName, principals); if (moveTracker.isEmpty()) { return new PermissionValidator(before, after, pp, this); } else { return new MoveAwarePermissionValidator(before, after, pp, this, moveTracker); } }
private boolean processDelete(@Nullable Tree parent, @NotNull String name, @NotNull MoveAwarePermissionValidator validator) throws CommitFailedException { if (parent == null) { return false; } Tree child = parent.getChild(name); String destPath = moveTracker.getDestPath(child.getPath()); if (destPath != null) { Tree dest = rootAfter.getTree(destPath); if (dest.exists()) { // check permissions for removing that node. validator.checkPermissions(child, true, Permissions.REMOVE_NODE); checkPermissions(dest, Permissions.ADD_NODE|Permissions.NODE_TYPE_MANAGEMENT); return diff(child, dest, validator); } } return false; }
private boolean processAdd(@Nullable Tree parent, @NotNull String name , @NotNull MoveAwarePermissionValidator validator) throws CommitFailedException { if (parent == null) { return false; } Tree child = parent.getChild(name); String sourcePath = moveTracker.getSourcePath(child.getPath()); if (sourcePath != null) { Tree source = rootBefore.getTree(sourcePath); if (source.exists()) { // check permissions for adding the moved node at the target location. validator.checkPermissions(child, false, Permissions.ADD_NODE | Permissions.NODE_TYPE_MANAGEMENT); checkPermissions(source, Permissions.REMOVE_NODE); return diff(source, child, validator); } } return false; }
@Override public void commit(@NotNull Map<String, Object> info) throws CommitFailedException { checkLive(); ContentSession session = getContentSession(); CommitInfo commitInfo = new CommitInfo( session.toString(), session.getAuthInfo().getUserID(), newInfoWithCommitContext(info)); store.merge(builder, getCommitHook(), commitInfo); secureBuilder.baseChanged(); modCount = 0; if (permissionProvider.hasValue()) { permissionProvider.get().refresh(); } moveTracker.clear(); }
@Test public void testGetValidators() { List<? extends ValidatorProvider> l = configuration.getValidators("wspName", ImmutableSet.<Principal>of(), new MoveTracker()); assertEquals(1, l.size()); assertTrue(l.get(0) instanceof PrivilegeValidatorProvider); }
@Override public boolean move(String sourcePath, String destPath) { if (isAncestor(checkNotNull(sourcePath), checkNotNull(destPath))) { return false; } else if (sourcePath.equals(destPath)) { return true; } checkLive(); MutableTree source = rootTree.getTree(sourcePath); if (!source.exists()) { return false; } String newName = getName(destPath); MutableTree newParent = rootTree.getTree(getParentPath(destPath)); if (!newParent.exists() || newParent.hasChild(newName)) { return false; } boolean success = source.moveTo(newParent, newName); if (success) { lastMove = lastMove.setMove(sourcePath, newParent, newName); updated(); // remember all move operations for further processing in the commit hooks. moveTracker.addMove(sourcePath, destPath); } return success; }
@Override @NotNull public Validator getRootValidator( NodeState before, NodeState after, CommitInfo info) { PermissionProvider pp = acConfig.getPermissionProvider(createReadOnlyRoot(before), workspaceName, principals); if (moveTracker.isEmpty()) { return new PermissionValidator(before, after, pp, this); } else { return new MoveAwarePermissionValidator(before, after, pp, this, moveTracker); } }
private boolean processDelete(@CheckForNull Tree parent, @Nonnull String name, @Nonnull MoveAwarePermissionValidator validator) throws CommitFailedException { if (parent == null) { return false; } ImmutableTree child = (ImmutableTree) parent.getChild(name); String destPath = moveTracker.getDestPath(child.getPath()); if (destPath != null) { ImmutableTree dest = (ImmutableTree) rootAfter.getTree(destPath); if (dest.exists()) { // check permissions for removing that node. validator.checkPermissions(child, true, Permissions.REMOVE_NODE); checkPermissions(dest, Permissions.ADD_NODE|Permissions.NODE_TYPE_MANAGEMENT); return diff(child, dest, validator); } } return false; }
private boolean processAdd(@Nullable Tree parent, @NotNull String name , @NotNull MoveAwarePermissionValidator validator) throws CommitFailedException { if (parent == null) { return false; } Tree child = parent.getChild(name); String sourcePath = moveTracker.getSourcePath(child.getPath()); if (sourcePath != null) { Tree source = rootBefore.getTree(sourcePath); if (source.exists()) { // check permissions for adding the moved node at the target location. validator.checkPermissions(child, false, Permissions.ADD_NODE | Permissions.NODE_TYPE_MANAGEMENT); checkPermissions(source, Permissions.REMOVE_NODE); return diff(source, child, validator); } } return false; }
@Override public void commit(@NotNull Map<String, Object> info) throws CommitFailedException { checkLive(); ContentSession session = getContentSession(); CommitInfo commitInfo = new CommitInfo( session.toString(), session.getAuthInfo().getUserID(), newInfoWithCommitContext(info)); store.merge(builder, getCommitHook(), commitInfo); secureBuilder.baseChanged(); modCount = 0; if (permissionProvider.hasValue()) { permissionProvider.get().refresh(); } moveTracker.clear(); }
/** * 7. >/a:/b >/c:/a does not commute * See http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/ChangeLog.java?view=markup * Line 231 */ @Test public void test7() { MoveTracker mt3 = new MoveTracker(); mt3.addMove("/a", "/b"); mt3.addMove("/c", "/a"); assertEquals("/a", mt3.getSourcePath("/b")); assertEquals("/c", mt3.getSourcePath("/a")); assertEquals("/b", mt3.getDestPath("/a")); assertEquals("/a", mt3.getDestPath("/c")); }
@Test public void testGetValidators() { List<? extends ValidatorProvider> l = new CugConfiguration().getValidators("wspName", ImmutableSet.of(), new MoveTracker()); assertEquals(1, l.size()); assertTrue(l.iterator().next() instanceof CugValidatorProvider); }
@Override public boolean move(String sourcePath, String destPath) { if (isAncestor(checkNotNull(sourcePath), checkNotNull(destPath))) { return false; } else if (sourcePath.equals(destPath)) { return true; } checkLive(); MutableTree source = rootTree.getTree(sourcePath); if (!source.exists()) { return false; } String newName = getName(destPath); MutableTree newParent = rootTree.getTree(getParentPath(destPath)); if (!newParent.exists() || newParent.hasChild(newName)) { return false; } boolean success = source.moveTo(newParent, newName); if (success) { lastMove = lastMove.setMove(sourcePath, newParent, newName); updated(); // remember all move operations for further processing in the commit hooks. moveTracker.addMove(sourcePath, destPath); } return success; }