diff --git a/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/impl/AcInstallationServiceImpl.java b/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/impl/AcInstallationServiceImpl.java index d63e3bb7..de03886d 100644 --- a/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/impl/AcInstallationServiceImpl.java +++ b/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/impl/AcInstallationServiceImpl.java @@ -655,6 +655,8 @@ private void installAces(InstallationLogger installLog, .getPathBasedAceMap(acConfiguration.getAceConfig(), AcHelper.ACE_ORDER_ACTOOL_BEST_PRACTICE); Set principalsToRemoveAcesFor = getPrincipalNamesToRemoveAcesFor(acConfiguration.getAuthorizablesConfig()); + skipEveryoneAcesFromRemovalWhenRegexIsNotConfigured(acConfiguration.getAuthorizablesConfig(), + principalsToRemoveAcesFor, installLog); removeAcesForPathsNotInConfig(installLog, session, principalsToRemoveAcesFor, repositoryDumpAceMap, acConfiguration); Map> filteredPathBasedAceMapFromConfig = filterForRestrictedPaths(pathBasedAceMapFromConfig, @@ -738,6 +740,19 @@ private void installAuthorizables(InstallationLogger installLog, AcConfiguration + msHumanReadable(stopWatch.getTime())); } + static void skipEveryoneAcesFromRemovalWhenRegexIsNotConfigured(AuthorizablesConfig authorizablesConfig, + Set principalsToRemoveAcesFor, InstallationLogger installLog) { + for (AuthorizableConfigBean authorizableConfigBean : authorizablesConfig) { + if (PRINCIPAL_EVERYONE.equals(authorizableConfigBean.getPrincipalName()) + && StringUtils.isEmpty(authorizableConfigBean.getUnmanagedAcePathsRegex()) + && principalsToRemoveAcesFor.remove(PRINCIPAL_EVERYONE)) { + installLog.addMessage(LOG, + "Not removing existing ACEs for shared principal \"everyone\". To enforce this configure \"unmanagedAcePathsRegex\" for this principal in the configuration."); + return; + } + } + } + private Set removeNonExistingAuthorizables(Set authorizablesToCheck, Session session) throws AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException { Set nonExistingAuthorizables = new HashSet(); diff --git a/accesscontroltool-bundle/src/test/java/biz/netcentric/cq/tools/actool/impl/AcInstallationServiceImplTest.java b/accesscontroltool-bundle/src/test/java/biz/netcentric/cq/tools/actool/impl/AcInstallationServiceImplTest.java index fdb474c4..e14ebce4 100644 --- a/accesscontroltool-bundle/src/test/java/biz/netcentric/cq/tools/actool/impl/AcInstallationServiceImplTest.java +++ b/accesscontroltool-bundle/src/test/java/biz/netcentric/cq/tools/actool/impl/AcInstallationServiceImplTest.java @@ -1,6 +1,7 @@ package biz.netcentric.cq.tools.actool.impl; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; /*- * #%L @@ -22,9 +23,11 @@ import java.text.MessageFormat; import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.function.UnaryOperator; import javax.jcr.RepositoryException; @@ -46,6 +49,9 @@ import org.mockito.stubbing.Answer; import biz.netcentric.cq.tools.actool.api.InstallationOptionsBuilder; +import biz.netcentric.cq.tools.actool.configmodel.AuthorizableConfigBean; +import biz.netcentric.cq.tools.actool.configmodel.AuthorizablesConfig; +import biz.netcentric.cq.tools.actool.history.InstallationLogger; @ExtendWith(MockitoExtension.class) class AcInstallationServiceImplTest { @@ -126,6 +132,34 @@ void testSortAuthorizablesForDeletion() throws RepositoryException { } + @Test + void testEveryoneAcesAreNotRemovedWithoutUnmanagedPathsRegex() { + AuthorizablesConfig authorizablesConfig = new AuthorizablesConfig(); + AuthorizableConfigBean everyone = new AuthorizableConfigBean(); + everyone.setPrincipalName("everyone"); + authorizablesConfig.add(everyone); + + Set principalsToRemoveAcesFor = new HashSet<>(Arrays.asList("everyone", "someGroup")); + InstallationLogger installLog = Mockito.mock(InstallationLogger.class); + AcInstallationServiceImpl.skipEveryoneAcesFromRemovalWhenRegexIsNotConfigured(authorizablesConfig, + principalsToRemoveAcesFor, installLog); + + assertEquals(new HashSet<>(Arrays.asList("someGroup")), principalsToRemoveAcesFor); + assertNull(everyone.getUnmanagedAcePathsRegex()); + assertTrue(authorizablesConfig.managesPathForPrincipal("/content", "everyone", null)); + Mockito.verify(installLog).addMessage(Mockito.any(org.slf4j.Logger.class), + Mockito.contains("Not removing existing ACEs for shared principal \"everyone\". To enforce this configure \"unmanagedAcePathsRegex\" for this principal in the configuration.")); + + everyone.setUnmanagedAcePathsRegex("^/content.*"); + principalsToRemoveAcesFor.add("everyone"); + InstallationLogger configuredRegexLog = Mockito.mock(InstallationLogger.class); + AcInstallationServiceImpl.skipEveryoneAcesFromRemovalWhenRegexIsNotConfigured(authorizablesConfig, + principalsToRemoveAcesFor, configuredRegexLog); + + assertTrue(principalsToRemoveAcesFor.contains("everyone")); + Mockito.verifyNoInteractions(configuredRegexLog); + } + private static class GroupIteratorAnswer implements Answer> { static GroupIteratorAnswer forGroups(Group... groups) { diff --git a/docs/AdvancedFeatures.md b/docs/AdvancedFeatures.md index 51f2a3ad..3c6f38b9 100644 --- a/docs/AdvancedFeatures.md +++ b/docs/AdvancedFeatures.md @@ -332,7 +332,7 @@ To configure permissions for already existing users/groups, it's best to create This is not an option for the [`everyone` group](https://jackrabbit.apache.org/oak/docs/security/user/default.html#Everyone_Group) as it is neither allowed to put groups/users as members to this group (because implicitly every principal is member of this group) nor to put this group as member to another group (to prevent cycles, compare with [OAK-7323](https://issues.apache.org/jira/browse/OAK-7323)). Also in case of using [Sling Service Authentication bound to principals](https://sling.apache.org/documentation/the-sling-engine/service-authentication.html#service-user-mappings)(available since AEM 6.4) you cannot use group memberships, as the principal mapping does not consider (transitive) group memberships. Those mappings can be identified by looking up the according `org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended` configuration instance with its `user.mapping` property. It that has the format `[:]="["{","}"]"` (look for square brackets) it is a principal mapping. -In those cases just list the built-in authorizable (user/group) in the YAML file (with the correct authorizable id) and leverage `unmanagedAcePathsRegex` as outlined below. No other properties need to be set on the authorizable as this is in fact not touched by the ACTool. Alternatively just extend the permissions with [Repository Initialization (repoinit)](https://sling.apache.org/documentation/bundles/repository-initialization.html). +In those cases just list the built-in authorizable (user/group) in the YAML file (with the correct authorizable id) and leverage `unmanagedAcePathsRegex` as outlined below. No other properties need to be set on the authorizable as this is in fact not touched by the ACTool. When `everyone` is listed without an `unmanagedAcePathsRegex`, existing ACEs for this principal are preserved during cleanup, while configured ACEs can still be installed. If an `unmanagedAcePathsRegex` is set, it applies to both removing existing ACEs and installing configured ACEs. Alternatively just extend the permissions with [Repository Initialization (repoinit)](https://sling.apache.org/documentation/bundles/repository-initialization.html). ### Configure memberships of/towards externally managed groups