PermissionStoreEditor implements AccessControlConstants, PermissionConstants { void updatePermissionEntries() { for (Map.Entry<String, List<AcEntry>> entry: entries.entrySet()) { String principalName = entry.getKey(); NodeBuilder principalRoot = permissionRoot.child(principalName); if (!principalRoot.hasProperty(JCR_PRIMARYTYPE)) { principalRoot.setProperty(JCR_PRIMARYTYPE, NT_REP_PERMISSION_STORE, Type.NAME); } NodeBuilder parent = principalRoot.child(nodeName); if (!parent.hasProperty(JCR_PRIMARYTYPE)) { parent.setProperty(JCR_PRIMARYTYPE, NT_REP_PERMISSION_STORE, Type.NAME); } if (parent.hasProperty(REP_ACCESS_CONTROLLED_PATH)) { if (!PermissionUtil.checkACLPath(parent, accessControlledPath)) { NodeBuilder child = null; int idx = 0; for (String childName : parent.getChildNodeNames()) { if (childName.charAt(0) != 'c') { continue; } child = parent.getChildNode(childName); if (PermissionUtil.checkACLPath(child, accessControlledPath)) { break; } child = null; idx++; } while (child == null) { String name = 'c' + String.valueOf(idx++); child = parent.getChildNode(name); if (child.exists()) { child = null; } else { child = parent.child(name); child.setProperty(JCR_PRIMARYTYPE, NT_REP_PERMISSION_STORE, Type.NAME); } } parent = child; parent.setProperty(REP_ACCESS_CONTROLLED_PATH, accessControlledPath); } } else { parent.setProperty(REP_ACCESS_CONTROLLED_PATH, accessControlledPath); } updateEntries(parent, entry.getValue()); if (parent.isNew()) { updateNumEntries(principalName, principalRoot, +1); } } } PermissionStoreEditor(@NotNull String aclPath, @NotNull String name,
                          @NotNull NodeState node, @NotNull NodeBuilder permissionRoot,
                          @NotNull TypePredicate isACE, @NotNull TypePredicate isGrantACE,
                          @NotNull PrivilegeBitsProvider bitsProvider,
                          @NotNull RestrictionProvider restrictionProvider,
                          @NotNull TreeProvider treeProvider);   }
@Test public void testUpdatePermissionEntriesDoesNotRemoveCollisions() { NodeState ace = mockACE(PRINCIPAL_NAME); NodeState nodeState = mockNodeState(ace); NodeBuilder child = mock(NodeBuilder.class); when(child.setProperty(anyString(), any())).thenReturn(child); when(child.setProperty(anyString(), any(), any(Type.class))).thenReturn(child); NodeBuilder parent = mock(NodeBuilder.class); when(parent.getChildNodeNames()).thenReturn(ImmutableSet.of("collision", "entry")); when(parent.getChildNode(anyString())).thenReturn(child); when(parent.child(anyString())).thenReturn(child); NodeBuilder principalRoot = when(mock(NodeBuilder.class).child(anyString())).thenReturn(parent).getMock(); NodeBuilder permissionsRoot = mock(NodeBuilder.class); when(permissionsRoot.child(PRINCIPAL_NAME)).thenReturn(principalRoot); PermissionStoreEditor editor = createPermissionStoreEditor(nodeState, permissionsRoot); editor.updatePermissionEntries(); verify(child, times(1)).remove(); }