@Test public void testSimplePrivilegesAcesAdditive() throws Exception { aceBeanInstallerIncremental.installAcl( asSet(bean1, bean2, bean3), testPath, asSet(testPrincipal1, testPrincipal2, testPrincipal3), session, installLog); verify(jackrabbitAccessControlList, never()).removeAccessControlEntry(any(JackrabbitAccessControlEntry.class)); verify(aceBeanInstallerIncremental).installPrivileges(eq(bean1), eq(new PrincipalImpl(testPrincipal1)), eq(jackrabbitAccessControlList), eq(session), eq(accessControlManager)); verify(aceBeanInstallerIncremental).installPrivileges(eq(bean2), eq(new PrincipalImpl(testPrincipal2)), eq(jackrabbitAccessControlList), eq(session), eq(accessControlManager)); verify(aceBeanInstallerIncremental).installPrivileges(eq(bean3), eq(new PrincipalImpl(testPrincipal3)), eq(jackrabbitAccessControlList), eq(session), eq(accessControlManager)); }
protected void installAcl(Set<AceBean> aceBeanSetFromConfig, String path, Set<String> principalsInConfiguration, Session session, InstallationLogger installLog) throws RepositoryException { boolean hadPendingChanges = session.hasPendingChanges(); int countDeleted = 0; int countAdded = 0; int countNoChange = 0; int countOutsideConfig = 0; StringBuilder diffLog = new StringBuilder(); aceBeanSetFromConfig = transformActionsIntoPrivileges(aceBeanSetFromConfig, session, installLog); aceBeanSetFromConfig = filterInitialContentOnlyNodes(aceBeanSetFromConfig); aceBeanSetFromConfig = filterDuplicates(aceBeanSetFromConfig, session); List<AceBean> configuredAceEntries = new ArrayList<AceBean>(aceBeanSetFromConfig); int currentPositionConfig = 0; boolean changeHasBeenFound = false; AccessControlManager acMgr = session.getAccessControlManager(); JackrabbitAccessControlList acl = getAccessControlList(acMgr, path); Iterator<AccessControlEntry> aceIt = Arrays.asList(acl.getAccessControlEntries()).iterator(); while (aceIt.hasNext()) { AccessControlEntry ace = aceIt.next(); AceBean actualAceBean = AcHelper.getAceBean(ace, acl); String acePrincipalName = actualAceBean.getPrincipalName(); String actualAceBeanCompareStr = toAceCompareString(actualAceBean, acMgr); if (!principalsInConfiguration.contains(acePrincipalName)) { countOutsideConfig++; diffLog.append(" OUTSIDE (not in Config) " + actualAceBeanCompareStr + "\n"); continue; } AceBean configuredAceAtThisLocation; if (currentPositionConfig < configuredAceEntries.size()) { configuredAceAtThisLocation = configuredAceEntries.get(currentPositionConfig); } else { changeHasBeenFound = true; configuredAceAtThisLocation = null; } String configuredAceAtThisLocationCompareStr = toAceCompareString(configuredAceAtThisLocation, acMgr); boolean dumpEqualToConfig = StringUtils.equals(actualAceBeanCompareStr, configuredAceAtThisLocationCompareStr); if (!changeHasBeenFound && !dumpEqualToConfig) { String configBeanStr = configuredAceAtThisLocationCompareStr; diffLog.append("<<< CHANGE (Repo Version) " + actualAceBeanCompareStr + "\n>>> CHANGE (Config Version) " + configBeanStr + "\n"); } if (changeHasBeenFound || !dumpEqualToConfig) { changeHasBeenFound = true; acl.removeAccessControlEntry(ace); countDeleted++; diffLog.append(" DELETED (from Repo) " + actualAceBeanCompareStr + "\n"); continue; } currentPositionConfig++; countNoChange++; diffLog.append(" UNCHANGED " + actualAceBeanCompareStr + "\n"); } for (int i = currentPositionConfig; i < configuredAceEntries.size(); i++) { AceBean aceBeanToAppend = configuredAceEntries.get(i); installPrivileges(aceBeanToAppend, new PrincipalImpl(aceBeanToAppend.getPrincipalName()), acl, session, acMgr); diffLog.append(" APPENDED (from Config) " + toAceCompareString(aceBeanToAppend, acMgr) + "\n"); countAdded++; } if (countAdded > 0 || countDeleted > 0) { acMgr.setPolicy(StringUtils.isNotBlank(path) ? path : null, acl); installLog.incCountAclsChanged(); installLog.addVerboseMessage(LOG, "Update result at path " + path + ": O=" + countOutsideConfig + " N=" + countNoChange + " D=" + countDeleted + " A=" + countAdded + (LOG.isDebugEnabled() ? "\nDIFF at " + path + "\n" + diffLog : "")); } else { installLog.incCountAclsNoChange(); } if (!hadPendingChanges) { if (session.hasPendingChanges()) { hadPendingChanges = true; installLog.addMessage(LOG, "Path " + path + " introduced pending changes to the session"); } } }
AceBeanInstallerIncremental extends BaseAceBeanInstaller implements AceBeanInstaller { protected void installAcl(Set<AceBean> aceBeanSetFromConfig, String path, Set<String> principalsInConfiguration, Session session, InstallationLogger installLog) throws RepositoryException { boolean hadPendingChanges = session.hasPendingChanges(); int countDeleted = 0; int countAdded = 0; int countNoChange = 0; int countOutsideConfig = 0; StringBuilder diffLog = new StringBuilder(); aceBeanSetFromConfig = transformActionsIntoPrivileges(aceBeanSetFromConfig, session, installLog); aceBeanSetFromConfig = filterInitialContentOnlyNodes(aceBeanSetFromConfig); aceBeanSetFromConfig = filterDuplicates(aceBeanSetFromConfig, session); List<AceBean> configuredAceEntries = new ArrayList<AceBean>(aceBeanSetFromConfig); int currentPositionConfig = 0; boolean changeHasBeenFound = false; AccessControlManager acMgr = session.getAccessControlManager(); JackrabbitAccessControlList acl = getAccessControlList(acMgr, path); Iterator<AccessControlEntry> aceIt = Arrays.asList(acl.getAccessControlEntries()).iterator(); while (aceIt.hasNext()) { AccessControlEntry ace = aceIt.next(); AceBean actualAceBean = AcHelper.getAceBean(ace, acl); String acePrincipalName = actualAceBean.getPrincipalName(); String actualAceBeanCompareStr = toAceCompareString(actualAceBean, acMgr); if (!principalsInConfiguration.contains(acePrincipalName)) { countOutsideConfig++; diffLog.append(" OUTSIDE (not in Config) " + actualAceBeanCompareStr + "\n"); continue; } AceBean configuredAceAtThisLocation; if (currentPositionConfig < configuredAceEntries.size()) { configuredAceAtThisLocation = configuredAceEntries.get(currentPositionConfig); } else { changeHasBeenFound = true; configuredAceAtThisLocation = null; } String configuredAceAtThisLocationCompareStr = toAceCompareString(configuredAceAtThisLocation, acMgr); boolean dumpEqualToConfig = StringUtils.equals(actualAceBeanCompareStr, configuredAceAtThisLocationCompareStr); if (!changeHasBeenFound && !dumpEqualToConfig) { String configBeanStr = configuredAceAtThisLocationCompareStr; diffLog.append("<<< CHANGE (Repo Version) " + actualAceBeanCompareStr + "\n>>> CHANGE (Config Version) " + configBeanStr + "\n"); } if (changeHasBeenFound || !dumpEqualToConfig) { changeHasBeenFound = true; acl.removeAccessControlEntry(ace); countDeleted++; diffLog.append(" DELETED (from Repo) " + actualAceBeanCompareStr + "\n"); continue; } currentPositionConfig++; countNoChange++; diffLog.append(" UNCHANGED " + actualAceBeanCompareStr + "\n"); } for (int i = currentPositionConfig; i < configuredAceEntries.size(); i++) { AceBean aceBeanToAppend = configuredAceEntries.get(i); installPrivileges(aceBeanToAppend, new PrincipalImpl(aceBeanToAppend.getPrincipalName()), acl, session, acMgr); diffLog.append(" APPENDED (from Config) " + toAceCompareString(aceBeanToAppend, acMgr) + "\n"); countAdded++; } if (countAdded > 0 || countDeleted > 0) { acMgr.setPolicy(StringUtils.isNotBlank(path) ? path : null, acl); installLog.incCountAclsChanged(); installLog.addVerboseMessage(LOG, "Update result at path " + path + ": O=" + countOutsideConfig + " N=" + countNoChange + " D=" + countDeleted + " A=" + countAdded + (LOG.isDebugEnabled() ? "\nDIFF at " + path + "\n" + diffLog : "")); } else { installLog.incCountAclsNoChange(); } if (!hadPendingChanges) { if (session.hasPendingChanges()) { hadPendingChanges = true; installLog.addMessage(LOG, "Path " + path + " introduced pending changes to the session"); } } } }
AceBeanInstallerIncremental extends BaseAceBeanInstaller implements AceBeanInstaller { protected void installAcl(Set<AceBean> aceBeanSetFromConfig, String path, Set<String> principalsInConfiguration, Session session, InstallationLogger installLog) throws RepositoryException { boolean hadPendingChanges = session.hasPendingChanges(); int countDeleted = 0; int countAdded = 0; int countNoChange = 0; int countOutsideConfig = 0; StringBuilder diffLog = new StringBuilder(); aceBeanSetFromConfig = transformActionsIntoPrivileges(aceBeanSetFromConfig, session, installLog); aceBeanSetFromConfig = filterInitialContentOnlyNodes(aceBeanSetFromConfig); aceBeanSetFromConfig = filterDuplicates(aceBeanSetFromConfig, session); List<AceBean> configuredAceEntries = new ArrayList<AceBean>(aceBeanSetFromConfig); int currentPositionConfig = 0; boolean changeHasBeenFound = false; AccessControlManager acMgr = session.getAccessControlManager(); JackrabbitAccessControlList acl = getAccessControlList(acMgr, path); Iterator<AccessControlEntry> aceIt = Arrays.asList(acl.getAccessControlEntries()).iterator(); while (aceIt.hasNext()) { AccessControlEntry ace = aceIt.next(); AceBean actualAceBean = AcHelper.getAceBean(ace, acl); String acePrincipalName = actualAceBean.getPrincipalName(); String actualAceBeanCompareStr = toAceCompareString(actualAceBean, acMgr); if (!principalsInConfiguration.contains(acePrincipalName)) { countOutsideConfig++; diffLog.append(" OUTSIDE (not in Config) " + actualAceBeanCompareStr + "\n"); continue; } AceBean configuredAceAtThisLocation; if (currentPositionConfig < configuredAceEntries.size()) { configuredAceAtThisLocation = configuredAceEntries.get(currentPositionConfig); } else { changeHasBeenFound = true; configuredAceAtThisLocation = null; } String configuredAceAtThisLocationCompareStr = toAceCompareString(configuredAceAtThisLocation, acMgr); boolean dumpEqualToConfig = StringUtils.equals(actualAceBeanCompareStr, configuredAceAtThisLocationCompareStr); if (!changeHasBeenFound && !dumpEqualToConfig) { String configBeanStr = configuredAceAtThisLocationCompareStr; diffLog.append("<<< CHANGE (Repo Version) " + actualAceBeanCompareStr + "\n>>> CHANGE (Config Version) " + configBeanStr + "\n"); } if (changeHasBeenFound || !dumpEqualToConfig) { changeHasBeenFound = true; acl.removeAccessControlEntry(ace); countDeleted++; diffLog.append(" DELETED (from Repo) " + actualAceBeanCompareStr + "\n"); continue; } currentPositionConfig++; countNoChange++; diffLog.append(" UNCHANGED " + actualAceBeanCompareStr + "\n"); } for (int i = currentPositionConfig; i < configuredAceEntries.size(); i++) { AceBean aceBeanToAppend = configuredAceEntries.get(i); installPrivileges(aceBeanToAppend, new PrincipalImpl(aceBeanToAppend.getPrincipalName()), acl, session, acMgr); diffLog.append(" APPENDED (from Config) " + toAceCompareString(aceBeanToAppend, acMgr) + "\n"); countAdded++; } if (countAdded > 0 || countDeleted > 0) { acMgr.setPolicy(StringUtils.isNotBlank(path) ? path : null, acl); installLog.incCountAclsChanged(); installLog.addVerboseMessage(LOG, "Update result at path " + path + ": O=" + countOutsideConfig + " N=" + countNoChange + " D=" + countDeleted + " A=" + countAdded + (LOG.isDebugEnabled() ? "\nDIFF at " + path + "\n" + diffLog : "")); } else { installLog.incCountAclsNoChange(); } if (!hadPendingChanges) { if (session.hasPendingChanges()) { hadPendingChanges = true; installLog.addMessage(LOG, "Path " + path + " introduced pending changes to the session"); } } }  }
AceBeanInstallerIncremental extends BaseAceBeanInstaller implements AceBeanInstaller { protected void installAcl(Set<AceBean> aceBeanSetFromConfig, String path, Set<String> principalsInConfiguration, Session session, InstallationLogger installLog) throws RepositoryException { boolean hadPendingChanges = session.hasPendingChanges(); int countDeleted = 0; int countAdded = 0; int countNoChange = 0; int countOutsideConfig = 0; StringBuilder diffLog = new StringBuilder(); aceBeanSetFromConfig = transformActionsIntoPrivileges(aceBeanSetFromConfig, session, installLog); aceBeanSetFromConfig = filterInitialContentOnlyNodes(aceBeanSetFromConfig); aceBeanSetFromConfig = filterDuplicates(aceBeanSetFromConfig, session); List<AceBean> configuredAceEntries = new ArrayList<AceBean>(aceBeanSetFromConfig); int currentPositionConfig = 0; boolean changeHasBeenFound = false; AccessControlManager acMgr = session.getAccessControlManager(); JackrabbitAccessControlList acl = getAccessControlList(acMgr, path); Iterator<AccessControlEntry> aceIt = Arrays.asList(acl.getAccessControlEntries()).iterator(); while (aceIt.hasNext()) { AccessControlEntry ace = aceIt.next(); AceBean actualAceBean = AcHelper.getAceBean(ace, acl); String acePrincipalName = actualAceBean.getPrincipalName(); String actualAceBeanCompareStr = toAceCompareString(actualAceBean, acMgr); if (!principalsInConfiguration.contains(acePrincipalName)) { countOutsideConfig++; diffLog.append(" OUTSIDE (not in Config) " + actualAceBeanCompareStr + "\n"); continue; } AceBean configuredAceAtThisLocation; if (currentPositionConfig < configuredAceEntries.size()) { configuredAceAtThisLocation = configuredAceEntries.get(currentPositionConfig); } else { changeHasBeenFound = true; configuredAceAtThisLocation = null; } String configuredAceAtThisLocationCompareStr = toAceCompareString(configuredAceAtThisLocation, acMgr); boolean dumpEqualToConfig = StringUtils.equals(actualAceBeanCompareStr, configuredAceAtThisLocationCompareStr); if (!changeHasBeenFound && !dumpEqualToConfig) { String configBeanStr = configuredAceAtThisLocationCompareStr; diffLog.append("<<< CHANGE (Repo Version) " + actualAceBeanCompareStr + "\n>>> CHANGE (Config Version) " + configBeanStr + "\n"); } if (changeHasBeenFound || !dumpEqualToConfig) { changeHasBeenFound = true; acl.removeAccessControlEntry(ace); countDeleted++; diffLog.append(" DELETED (from Repo) " + actualAceBeanCompareStr + "\n"); continue; } currentPositionConfig++; countNoChange++; diffLog.append(" UNCHANGED " + actualAceBeanCompareStr + "\n"); } for (int i = currentPositionConfig; i < configuredAceEntries.size(); i++) { AceBean aceBeanToAppend = configuredAceEntries.get(i); installPrivileges(aceBeanToAppend, new PrincipalImpl(aceBeanToAppend.getPrincipalName()), acl, session, acMgr); diffLog.append(" APPENDED (from Config) " + toAceCompareString(aceBeanToAppend, acMgr) + "\n"); countAdded++; } if (countAdded > 0 || countDeleted > 0) { acMgr.setPolicy(StringUtils.isNotBlank(path) ? path : null, acl); installLog.incCountAclsChanged(); installLog.addVerboseMessage(LOG, "Update result at path " + path + ": O=" + countOutsideConfig + " N=" + countNoChange + " D=" + countDeleted + " A=" + countAdded + (LOG.isDebugEnabled() ? "\nDIFF at " + path + "\n" + diffLog : "")); } else { installLog.incCountAclsNoChange(); } if (!hadPendingChanges) { if (session.hasPendingChanges()) { hadPendingChanges = true; installLog.addMessage(LOG, "Path " + path + " introduced pending changes to the session"); } } }   }
AceBeanInstallerIncremental extends BaseAceBeanInstaller implements AceBeanInstaller { protected void installAcl(Set<AceBean> aceBeanSetFromConfig, String path, Set<String> principalsInConfiguration, Session session, InstallationLogger installLog) throws RepositoryException { boolean hadPendingChanges = session.hasPendingChanges(); int countDeleted = 0; int countAdded = 0; int countNoChange = 0; int countOutsideConfig = 0; StringBuilder diffLog = new StringBuilder(); aceBeanSetFromConfig = transformActionsIntoPrivileges(aceBeanSetFromConfig, session, installLog); aceBeanSetFromConfig = filterInitialContentOnlyNodes(aceBeanSetFromConfig); aceBeanSetFromConfig = filterDuplicates(aceBeanSetFromConfig, session); List<AceBean> configuredAceEntries = new ArrayList<AceBean>(aceBeanSetFromConfig); int currentPositionConfig = 0; boolean changeHasBeenFound = false; AccessControlManager acMgr = session.getAccessControlManager(); JackrabbitAccessControlList acl = getAccessControlList(acMgr, path); Iterator<AccessControlEntry> aceIt = Arrays.asList(acl.getAccessControlEntries()).iterator(); while (aceIt.hasNext()) { AccessControlEntry ace = aceIt.next(); AceBean actualAceBean = AcHelper.getAceBean(ace, acl); String acePrincipalName = actualAceBean.getPrincipalName(); String actualAceBeanCompareStr = toAceCompareString(actualAceBean, acMgr); if (!principalsInConfiguration.contains(acePrincipalName)) { countOutsideConfig++; diffLog.append(" OUTSIDE (not in Config) " + actualAceBeanCompareStr + "\n"); continue; } AceBean configuredAceAtThisLocation; if (currentPositionConfig < configuredAceEntries.size()) { configuredAceAtThisLocation = configuredAceEntries.get(currentPositionConfig); } else { changeHasBeenFound = true; configuredAceAtThisLocation = null; } String configuredAceAtThisLocationCompareStr = toAceCompareString(configuredAceAtThisLocation, acMgr); boolean dumpEqualToConfig = StringUtils.equals(actualAceBeanCompareStr, configuredAceAtThisLocationCompareStr); if (!changeHasBeenFound && !dumpEqualToConfig) { String configBeanStr = configuredAceAtThisLocationCompareStr; diffLog.append("<<< CHANGE (Repo Version) " + actualAceBeanCompareStr + "\n>>> CHANGE (Config Version) " + configBeanStr + "\n"); } if (changeHasBeenFound || !dumpEqualToConfig) { changeHasBeenFound = true; acl.removeAccessControlEntry(ace); countDeleted++; diffLog.append(" DELETED (from Repo) " + actualAceBeanCompareStr + "\n"); continue; } currentPositionConfig++; countNoChange++; diffLog.append(" UNCHANGED " + actualAceBeanCompareStr + "\n"); } for (int i = currentPositionConfig; i < configuredAceEntries.size(); i++) { AceBean aceBeanToAppend = configuredAceEntries.get(i); installPrivileges(aceBeanToAppend, new PrincipalImpl(aceBeanToAppend.getPrincipalName()), acl, session, acMgr); diffLog.append(" APPENDED (from Config) " + toAceCompareString(aceBeanToAppend, acMgr) + "\n"); countAdded++; } if (countAdded > 0 || countDeleted > 0) { acMgr.setPolicy(StringUtils.isNotBlank(path) ? path : null, acl); installLog.incCountAclsChanged(); installLog.addVerboseMessage(LOG, "Update result at path " + path + ": O=" + countOutsideConfig + " N=" + countNoChange + " D=" + countDeleted + " A=" + countAdded + (LOG.isDebugEnabled() ? "\nDIFF at " + path + "\n" + diffLog : "")); } else { installLog.incCountAclsNoChange(); } if (!hadPendingChanges) { if (session.hasPendingChanges()) { hadPendingChanges = true; installLog.addMessage(LOG, "Path " + path + " introduced pending changes to the session"); } } }    }