diff --git a/accesscontroltool-bundle/pom.xml b/accesscontroltool-bundle/pom.xml
index ffed059f..5fd81a84 100644
--- a/accesscontroltool-bundle/pom.xml
+++ b/accesscontroltool-bundle/pom.xml
@@ -11,7 +11,7 @@
biz.netcentric.cq.tools.accesscontroltool
accesscontroltool
- 1.8.4
+ 1.8.5
diff --git a/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/aceservice/AceService.java b/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/aceservice/AceService.java
index e9b1a4af..777db89e 100644
--- a/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/aceservice/AceService.java
+++ b/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/aceservice/AceService.java
@@ -64,12 +64,11 @@ public interface AceService {
*
* @param session
* @param history
- * @param newestConfigurations
+ * @param configurationFileContentsByFilename
* @param authorizableInstallationHistorySet
* @throws Exception */
- public void installNewConfigurations(Session session,
- AcInstallationHistoryPojo history,
- Map newestConfigurations, Set authorizableInstallationHistorySet)
- throws Exception;
+ public void installConfigurationFiles(Session session, AcInstallationHistoryPojo history,
+ Map configurationFileContentsByFilename,
+ Set authorizableInstallationHistorySet) throws Exception;
}
diff --git a/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/aceservice/impl/AceServiceImpl.java b/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/aceservice/impl/AceServiceImpl.java
index b35ab0bb..e968c54d 100644
--- a/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/aceservice/impl/AceServiceImpl.java
+++ b/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/aceservice/impl/AceServiceImpl.java
@@ -15,7 +15,6 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashSet;
-import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -48,6 +47,7 @@
import biz.netcentric.cq.tools.actool.authorizableutils.AuthorizableCreatorException;
import biz.netcentric.cq.tools.actool.authorizableutils.AuthorizableCreatorService;
import biz.netcentric.cq.tools.actool.authorizableutils.AuthorizableInstallationHistory;
+import biz.netcentric.cq.tools.actool.configmodel.AcConfiguration;
import biz.netcentric.cq.tools.actool.configreader.ConfigFilesRetriever;
import biz.netcentric.cq.tools.actool.configreader.ConfigReader;
import biz.netcentric.cq.tools.actool.configreader.ConfigurationMerger;
@@ -97,30 +97,26 @@ public class AceServiceImpl implements AceService {
private String configurationPath;
@Activate
- public void activate(@SuppressWarnings("rawtypes") final Map properties)
+ public void activate(final Map,?> properties)
throws Exception {
LOG.debug("Activated AceService!");
modified(properties);
}
@Modified
- public void modified(@SuppressWarnings("rawtypes") final Map properties) {
+ public void modified(final Map,?> properties) {
LOG.debug("Modified AceService!");
configurationPath = PropertiesUtil.toString(properties.get(PROPERTY_CONFIGURATION_PATH), "");
}
- // FIXME: Why is this called installConfigurationFromYamlList if it doesn't use YAML?
- private void installConfigurationFromYamlList(
- final List mergedConfigurations, AcInstallationHistoryPojo history,
+ private void installAcConfiguration(
+ AcConfiguration acConfiguration, AcInstallationHistoryPojo history,
final Session session,
Set authorizableHistorySet,
Map> repositoryDumpAceMap) throws Exception {
- // FIXME: putting different types of configuration objects in a heterogeneous list is pretty bad
- Map> authorizablesMapfromConfig = (Map>) mergedConfigurations
- .get(0);
- Map> aceMapFromConfig = (Map>) mergedConfigurations
- .get(1);
+ Map> authorizablesMapfromConfig = acConfiguration.getAuthorizablesConfig();
+ Map> aceMapFromConfig = acConfiguration.getAceConfig();
if (aceMapFromConfig == null) {
String message = "ace config not found in YAML file! installation aborted!";
@@ -135,7 +131,7 @@ private void installConfigurationFromYamlList(
installAces(history, session, aceMapFromConfig);
}
- private Set getAuthorizablesToRemoveAcesFor(Map> authorizablesMapfromConfig) {
+ private Set getAuthorizablesToRemoveAcesFor(Map> authorizablesMapfromConfig) {
Set authorizablesToRemoveAcesFor = new HashSet(authorizablesMapfromConfig.keySet());
Set authorizablesToBeMigrated = collectAuthorizablesToBeMigrated(authorizablesMapfromConfig);
Collection> invalidAuthorizablesInConfig = CollectionUtils.intersection(authorizablesToRemoveAcesFor, authorizablesToBeMigrated);
@@ -149,10 +145,10 @@ private Set getAuthorizablesToRemoveAcesFor(Map collectAuthorizablesToBeMigrated(Map> authorizablesMapfromConfig) {
+ private Set collectAuthorizablesToBeMigrated(Map> authorizablesMapfromConfig) {
Set authorizablesToBeMigrated = new HashSet();
for (String principalStr : authorizablesMapfromConfig.keySet()) {
- LinkedHashSet authorizableConfigBeans = authorizablesMapfromConfig.get(principalStr);
+ Set authorizableConfigBeans = authorizablesMapfromConfig.get(principalStr);
for (AuthorizableConfigBean authorizableConfigBean : authorizableConfigBeans) {
String migrateFrom = authorizableConfigBean.getMigrateFrom();
if (StringUtils.isNotBlank(migrateFrom)) {
@@ -203,7 +199,7 @@ private void installAces(
private void installAuthorizables(
AcInstallationHistoryPojo history,
Set authorizableHistorySet,
- Map> authorizablesMapfromConfig)
+ Map> authorizablesMapfromConfig)
throws RepositoryException, Exception {
// --- installation of Authorizables from configuration ---
@@ -265,7 +261,7 @@ public AcInstallationHistoryPojo execute() {
String rootPath = getConfigurationRootPath();
Node rootNode = session.getNode(rootPath);
Map newestConfigurations = configFilesRetriever.getConfigFileContentFromNode(rootNode);
- installNewConfigurations(session, history, newestConfigurations, authorizableInstallationHistorySet);
+ installConfigurationFiles(session, history, newestConfigurations, authorizableInstallationHistorySet);
} catch (AuthorizableCreatorException e) {
history.addError(e.toString());
// here no rollback of authorizables necessary since session wasn't
@@ -299,7 +295,7 @@ public AcInstallationHistoryPojo execute() {
/** Common entry point for JMX and install hook. */
@Override
- public void installNewConfigurations(Session session, AcInstallationHistoryPojo history, Map currentConfiguration,
+ public void installConfigurationFiles(Session session, AcInstallationHistoryPojo history, Map configurationFileContentsByFilename,
Set authorizableInstallationHistorySet)
throws Exception {
@@ -313,13 +309,14 @@ public void installNewConfigurations(Session session, AcInstallationHistoryPojo
LOG.info(message);
history.addMessage(message);
- if (currentConfiguration != null) {
+ if (configurationFileContentsByFilename != null) {
- history.setConfigFileContentsByName(currentConfiguration);
+ AcConfiguration acConfiguration = configurationMerger.getMergedConfigurations(configurationFileContentsByFilename, history,
+ configReader);
+ history.setAcConfiguration(acConfiguration);
+ history.setConfigFileContentsByName(configurationFileContentsByFilename);
- List mergedConfigurations = configurationMerger.getMergedConfigurations(currentConfiguration, history, configReader);
-
- installMergedConfigurations(history, session, authorizableInstallationHistorySet, mergedConfigurations);
+ installMergedConfigurations(history, session, authorizableInstallationHistorySet, acConfiguration);
// if everything went fine (no exceptions), save the session
// thus persisting the changed ACLs
@@ -352,7 +349,7 @@ private void installMergedConfigurations(
AcInstallationHistoryPojo history,
Session session,
Set authorizableInstallationHistorySet,
- List mergedConfigurations) throws ValueFormatException,
+ AcConfiguration acConfiguration) throws ValueFormatException,
RepositoryException, Exception {
String message = "Starting installation of merged configurations...";
@@ -366,9 +363,7 @@ private void installMergedConfigurations(
AcHelper.ACE_ORDER_NONE,
dumpservice.getQueryExcludePaths()).getAceDump();
- installConfigurationFromYamlList(mergedConfigurations, history,
- session, authorizableInstallationHistorySet,
- repositoryDumpAceMap);
+ installAcConfiguration(acConfiguration, history, session, authorizableInstallationHistorySet, repositoryDumpAceMap);
}
@@ -603,9 +598,9 @@ public Set getAllAuthorizablesFromConfig(Session session)
AcInstallationHistoryPojo history = new AcInstallationHistoryPojo();
Node rootNode = session.getNode(configurationPath);
Map newestConfigurations = configFilesRetriever.getConfigFileContentFromNode(rootNode);
- List mergedConfigurations = configurationMerger.getMergedConfigurations(
- newestConfigurations, history, configReader);
- return ((Map>) mergedConfigurations.get(0)).keySet();
+ AcConfiguration acConfiguration = configurationMerger.getMergedConfigurations(newestConfigurations, history, configReader);
+ Set allAuthorizablesFromConfig = acConfiguration.getAceConfig().keySet();
+ return allAuthorizablesFromConfig;
}
}
diff --git a/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/authorizableutils/AuthorizableCreatorService.java b/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/authorizableutils/AuthorizableCreatorService.java
index 90126134..fe7f0fa8 100644
--- a/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/authorizableutils/AuthorizableCreatorService.java
+++ b/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/authorizableutils/AuthorizableCreatorService.java
@@ -8,8 +8,8 @@
*/
package biz.netcentric.cq.tools.actool.authorizableutils;
-import java.util.LinkedHashSet;
import java.util.Map;
+import java.util.Set;
import javax.jcr.AccessDeniedException;
import javax.jcr.RepositoryException;
@@ -23,7 +23,7 @@
public interface AuthorizableCreatorService {
public void createNewAuthorizables(
- Map> principalMapFromConfig,
+ Map> principalMapFromConfig,
final Session session, AcInstallationHistoryPojo status,
AuthorizableInstallationHistory authorizableInstallationHistory)
throws AccessDeniedException,
diff --git a/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/authorizableutils/impl/AuthorizableCreatorServiceImpl.java b/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/authorizableutils/impl/AuthorizableCreatorServiceImpl.java
index 0213ae68..d4901029 100644
--- a/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/authorizableutils/impl/AuthorizableCreatorServiceImpl.java
+++ b/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/authorizableutils/impl/AuthorizableCreatorServiceImpl.java
@@ -10,11 +10,13 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
+import java.util.regex.Pattern;
import javax.jcr.AccessDeniedException;
import javax.jcr.Node;
@@ -28,6 +30,7 @@
import javax.jcr.nodetype.ConstraintViolationException;
import javax.jcr.version.VersionException;
+import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
@@ -51,22 +54,24 @@
import biz.netcentric.cq.tools.actool.installationhistory.AcInstallationHistoryPojo;
@Service
-@Component(metatype = true, label = "AuthorizableCreatorService Service", description = "Service that installs groups according to textual configuration files")
+@Component(metatype = true, label = "AC AuthorizableCreatorService", description = "Service that installs groups according to textual configuration files")
public class AuthorizableCreatorServiceImpl implements
AuthorizableCreatorService {
+ private static final Logger LOG = LoggerFactory.getLogger(AuthorizableCreatorServiceImpl.class);
+
private static final String PATH_HOME_GROUPS = "/home/groups";
private static final String PATH_HOME_USERS = "/home/users";
- private static final Logger LOG = LoggerFactory.getLogger(AuthorizableCreatorServiceImpl.class);
+ private static final String PRINCIPAL_EVERYONE = "everyone";
AcInstallationHistoryPojo status;
- Map> principalMapFromConfig;
+ Map> principalMapFromConfig;
AuthorizableInstallationHistory authorizableInstallationHistory;
@Override
public void createNewAuthorizables(
- Map> principalMapFromConfig,
+ Map> principalMapFromConfig,
final Session session, AcInstallationHistoryPojo status,
AuthorizableInstallationHistory authorizableInstallationHistory)
throws AccessDeniedException,
@@ -81,7 +86,7 @@ public void createNewAuthorizables(
for (String principalId : groupsFromConfigurations) {
- LinkedHashSet currentPrincipalData = principalMapFromConfig
+ Set currentPrincipalData = principalMapFromConfig
.get(principalId);
Iterator it = currentPrincipalData
.iterator();
@@ -345,9 +350,7 @@ private void mergeGroup(AcInstallationHistoryPojo status,
currentGroupFromRepository.getPath(),
membershipGroupsFromRepository);
- mergeMemberOfGroups(principalId, status, userManager,
- currentGroupFromRepository, membershipGroupsFromConfig,
- membershipGroupsFromRepository);
+ mergeMemberOfGroups(principalId, status, userManager, membershipGroupsFromConfig, membershipGroupsFromRepository);
}
private String getAuthorizableName(Authorizable currentGroupFromRepository) throws RepositoryException, ValueFormatException {
@@ -389,19 +392,15 @@ private Authorizable createNewAuthorizable(
return newAuthorizable;
}
- private Set getMembershipGroupsFromRepository(
- Authorizable currentGroupFromRepository) throws RepositoryException {
+ private Set getMembershipGroupsFromRepository(Authorizable currentGroupFromRepository) throws RepositoryException {
Set membershipGroupsFromRepository = new HashSet();
- Iterator memberOfGroupsIterator = currentGroupFromRepository
- .declaredMemberOf();
+ Iterator memberOfGroupsIterator = currentGroupFromRepository.declaredMemberOf();
// build Set which contains the all Groups of which the existingGroup is
// a member of
-
while (memberOfGroupsIterator.hasNext()) {
Authorizable memberOfGroup = memberOfGroupsIterator.next();
membershipGroupsFromRepository.add(memberOfGroup.getID());
-
}
return membershipGroupsFromRepository;
}
@@ -418,178 +417,80 @@ private Set getMembershipGroupsFromConfig(String[] memberOf) {
return membershipGroupsFromConfig;
}
- private void mergeMemberOfGroups(String principalId,
+ @SuppressWarnings("unchecked")
+ void mergeMemberOfGroups(String principalId,
AcInstallationHistoryPojo status, UserManager userManager,
- Authorizable currentGroupFromRepository,
Set membershipGroupsFromConfig,
Set membershipGroupsFromRepository)
throws RepositoryException, AuthorizableExistsException,
AuthorizableCreatorException {
- LOG.debug("...checking differences");
+ LOG.debug("mergeMemberOfGroups() for {}", principalId);
- // group in repo doesn't have any members and group in config doesn't
- // have any members
- // do nothing
- if (!isMemberOfOtherGroup(currentGroupFromRepository)
- && membershipGroupsFromConfig.isEmpty()) {
- LOG.debug(
- "{}: authorizable in repo is not member of any other group and group in config is not member of any other group. No change necessary here!",
- principalId);
- }
+ // membership to everyone cannot be removed or added => take it out from both lists
+ membershipGroupsFromConfig.remove(PRINCIPAL_EVERYONE);
+ membershipGroupsFromRepository.remove(PRINCIPAL_EVERYONE);
- // group in repo is not member of any other group but group in config is
- // member of at least one other group
- // transfer members to group in repo
+ logAndVerboseHistoryMessage(status, "Principal " + principalId + " isMemberOf(repo)=" + membershipGroupsFromRepository);
+ logAndVerboseHistoryMessage(status, "Principal " + principalId + " isMemberOf(conifg)=" + membershipGroupsFromConfig);
- else if (!isMemberOfOtherGroup(currentGroupFromRepository)
- && !membershipGroupsFromConfig.isEmpty()) {
- mergeMemberOfGroupsFromConfig(principalId, status, userManager,
- membershipGroupsFromConfig);
+ Set validatedMembershipGroupsFromConfig = validateAssignedGroups(userManager, principalId, membershipGroupsFromConfig);
- // group in repo is member of at least one other group and group in
- // config is not member of any other group
+ Collection unChangedMembers = CollectionUtils.intersection(membershipGroupsFromRepository,
+ validatedMembershipGroupsFromConfig);
+ logAndVerboseHistoryMessage(status, "Principal " + principalId + " remains member of groups " + unChangedMembers);
- } else if (isMemberOfOtherGroup(currentGroupFromRepository)
- && membershipGroupsFromConfig.isEmpty()) {
+ Collection toBeAddedMembers = CollectionUtils.subtract(validatedMembershipGroupsFromConfig, membershipGroupsFromRepository);
+ logAndVerboseHistoryMessage(status, "Principal " + principalId + " will be added as member of " + toBeAddedMembers);
- mergeMemberOfGroupsFromRepo(principalId, userManager,
- membershipGroupsFromRepository);
- }
-
- // group in repo does have members and group in config does have members
-
- else if (isMemberOfOtherGroup(currentGroupFromRepository)
- && !membershipGroupsFromConfig.isEmpty()) {
- mergeMultipleMembersOfBothGroups(principalId, status, userManager,
- membershipGroupsFromConfig, membershipGroupsFromRepository);
- }
- }
+ Collection toBeRemovedMembers = CollectionUtils.subtract(membershipGroupsFromRepository,
+ validatedMembershipGroupsFromConfig);
+ Set toBeSkippedFromRemovalMembers = new HashSet();
- private void mergeMemberOfGroupsFromRepo(String principalId,
- UserManager userManager, Set membershipGroupsFromRepository)
- throws RepositoryException {
- LOG.debug(
- "{}: authorizable in repo is member of at least one other group and authorizable in config is not member of any other group",
- principalId);
- // delete memberOf groups of that group in repo
- for (String group : membershipGroupsFromRepository) {
- LOG.debug(
- "{}: delete authorizable from members of group {} in repository",
- principalId, group);
- ((Group) userManager.getAuthorizable(group))
- .removeMember(userManager.getAuthorizable(principalId));
- }
- }
+ Pattern ignoredMembershipsPattern = status.getAcConfiguration().getGlobalConfiguration().getAllowExternalGroupNamesRegEx();
- private void mergeMemberOfGroupsFromConfig(String principalId,
- AcInstallationHistoryPojo status, UserManager userManager,
- Set membershipGroupsFromConfig) throws RepositoryException,
- AuthorizableExistsException, AuthorizableCreatorException {
- LOG.debug(
- "{}: authorizable in repo is not member of any other group but authorizable in config is member of at least one other group",
- principalId);
-
- Set validatedGroups = validateAssignedGroups(userManager,
- principalId, membershipGroupsFromConfig.toArray(new String[membershipGroupsFromConfig.size()]));
-
- for (Group membershipGroup : validatedGroups) {
- LOG.debug(
- "{}: add authorizable to members of group {} in repository",
- principalId, membershipGroup.getID());
-
- if (StringUtils.equals(membershipGroup.getID(), principalId)) {
- String warning = "Attempt to add a group as member of itself ("
- + membershipGroup.getID() + ").";
- LOG.warn(warning);
- status.addWarning(warning);
- } else {
- ((Group) membershipGroup).addMember(userManager
- .getAuthorizable(principalId));
+ Iterator toBeRemovedMembersIt = toBeRemovedMembers.iterator();
+ while (toBeRemovedMembersIt.hasNext()) {
+ String groupId = toBeRemovedMembersIt.next();
+ if (ignoredMembershipsPattern != null && ignoredMembershipsPattern.matcher(groupId).find()) {
+ toBeSkippedFromRemovalMembers.add(groupId);
+ toBeRemovedMembersIt.remove();
}
}
- }
-
- private void mergeMultipleMembersOfBothGroups(String principalId,
- AcInstallationHistoryPojo status, UserManager userManager,
- Set membershipGroupsFromConfig,
- Set membershipGroupsFromRepository)
- throws RepositoryException, AuthorizableExistsException,
- AuthorizableCreatorException {
-
- // are both groups members of exactly the same groups?
- if (membershipGroupsFromRepository.equals(membershipGroupsFromConfig)) {
- // do nothing!
- LOG.debug(
- "{}: authorizable in repo and authorizable in config are members of the same group(s). No change necessary here!",
- principalId);
- } else {
- LOG.debug(
- "{}: authorizable in repo is member of at least one other group and authorizable in config is member of at least one other group",
- principalId);
-
- // loop through memberOf-groups of group from repo
-
- for (String authorizable : membershipGroupsFromRepository) {
- // is current a also contained in memberOf-groups property of
- // existing group?
- if (membershipGroupsFromConfig.contains(authorizable)) {
- continue;
-
- } else {
- // if not delete that group of membersOf-property of
- // existing group
-
- LOG.debug(
- "delete {} from members of group {} in repository",
- principalId, authorizable);
- ((Group) userManager.getAuthorizable(authorizable))
- .removeMember(userManager
- .getAuthorizable(principalId));
- }
- }
+ logAndVerboseHistoryMessage(status, "Principal " + principalId + " will be removed from members of " + toBeRemovedMembers);
- Set validatedGroups = validateAssignedGroups(
- userManager, principalId,
- membershipGroupsFromConfig.toArray(new String[0]));
- for (Group validatedGroup : validatedGroups) {
+ if (!toBeSkippedFromRemovalMembers.isEmpty()) {
+ logAndVerboseHistoryMessage(status, "Principal " + principalId + " remains member of groups "
+ + toBeSkippedFromRemovalMembers + " (due to configured ignoredMembershipsPattern=" + ignoredMembershipsPattern + ")");
- // is current group also contained in memberOf-groups property
- // of repo group?
+ }
- if (membershipGroupsFromRepository.contains(validatedGroup
- .getID())) {
- continue;
- } else {
+ // perform changes
- // if not add that group to membersOf-property of existing
- // group
+ Authorizable currentAuthorizable = userManager.getAuthorizable(principalId);
- LOG.debug("add {} to members of group {} in repository",
- principalId, validatedGroup);
- if (StringUtils.equals(validatedGroup.getID(), principalId)) {
- String warning = "Attempt to add a group as member of itself ("
- + validatedGroup + ").";
- LOG.warn(warning);
- status.addWarning(warning);
- } else {
- ((Group) validatedGroup).addMember(userManager
- .getAuthorizable(principalId));
+ for (String groupId : toBeAddedMembers) {
+ LOG.debug("Membership Change: Adding {} to members of group {} in repository", principalId, groupId);
+ Authorizable targetAuthorizable = userManager.getAuthorizable(groupId);
+ ((Group) targetAuthorizable).addMember(currentAuthorizable);
+ }
- }
- }
- }
+ for (String groupId : toBeRemovedMembers) {
+ LOG.debug("Membership Change: Removing {} from members of group {} in repository", principalId, groupId);
+ Authorizable targetAuthorizable = userManager.getAuthorizable(groupId);
+ ((Group) targetAuthorizable).removeMember(currentAuthorizable);
+ }
+ if (!toBeAddedMembers.isEmpty() && !toBeAddedMembers.isEmpty()) {
+ logAndVerboseHistoryMessage(status,
+ "Membership Change: Principal " + principalId + " was added to " + toBeAddedMembers.size()
+ + " and removed from " + toBeRemovedMembers.size() + " groups");
}
- }
- private boolean isMemberOfOtherGroup(Authorizable group)
- throws RepositoryException {
- Iterator it = group.declaredMemberOf();
+ }
- if (!it.hasNext()) {
- return false;
- }
- return true;
+ private void logAndVerboseHistoryMessage(AcInstallationHistoryPojo status, String msg) {
+ LOG.debug(msg);
+ status.addVerboseMessage(msg);
}
private Authorizable createNewGroup(
@@ -598,7 +499,7 @@ private Authorizable createNewGroup(
AcInstallationHistoryPojo status,
AuthorizableInstallationHistory authorizableInstallationHistory,
ValueFactory vf,
- Map> principalMapFromConfig, Session session)
+ Map> principalMapFromConfig, Session session)
throws AuthorizableExistsException, RepositoryException,
AuthorizableCreatorException {
@@ -653,9 +554,6 @@ private void setAuthorizableProperties(Authorizable authorizable, ValueFactory v
authorizable.setProperty("profile/aboutMe", vf.createValue(description));
}
}
-
-
-
private Authorizable createNewUser(
final UserManager userManager,
@@ -663,7 +561,7 @@ private Authorizable createNewUser(
AcInstallationHistoryPojo status,
AuthorizableInstallationHistory authorizableInstallationHistory,
ValueFactory vf,
- Map> principalMapFromConfig, Session session)
+ Map> principalMapFromConfig, Session session)
throws AuthorizableExistsException, RepositoryException,
AuthorizableCreatorException {
String principalId = principalConfigBean.getPrincipalID();
@@ -690,10 +588,12 @@ private void addMembersToReferencingAuthorizables(Authorizable authorizable, Aut
String[] memberOf = principalConfigBean.getMemberOf();
if ((authorizable != null) && (memberOf != null) && (memberOf.length > 0)) {
// add group to groups according to configuration
- Set referencingAuthorizablesToBeChanged = validateAssignedGroups(userManager, principalId, memberOf);
+ Set referencingAuthorizablesToBeChanged = validateAssignedGroups(userManager, principalId,
+ new HashSet(Arrays.asList(memberOf)));
if (!referencingAuthorizablesToBeChanged.isEmpty()) {
LOG.debug("start adding {} to assignedGroups", principalId);
- for (Group referencingAuthorizableToBeChanged : referencingAuthorizablesToBeChanged) {
+ for (String referencingAuthorizableToBeChangedId : referencingAuthorizablesToBeChanged) {
+ Group referencingAuthorizableToBeChanged = (Group) userManager.getAuthorizable(referencingAuthorizableToBeChangedId);
referencingAuthorizableToBeChanged.addMember(authorizable);
LOG.debug("added to {} ", referencingAuthorizableToBeChanged);
}
@@ -733,17 +633,21 @@ private User userManagerCreateSystemUserViaReflection(UserManager userManager, S
*
* @param userManager
* @param authorizablelID the ID of authorizable to validate
- * @param memberOf String array that contains the groups which the authorizable should be a member of
+ * @param isMemberOf String array that contains the groups which the authorizable should be a member of
* @return Set of authorizables which the current authorizable is a member of
* @throws RepositoryException
* @throws AuthorizableCreatorException if one of the authorizables contained in membersOf array is a user */
- private Set validateAssignedGroups(
+ Set validateAssignedGroups(
final UserManager userManager, final String authorizablelID,
- final String[] memberOf) throws RepositoryException,
+ final Set isMemberOf) throws RepositoryException,
AuthorizableCreatorException {
- Set authorizableSet = new HashSet();
- for (String memberOfPrincipal : memberOf) {
+ Set authorizableSet = new HashSet();
+ for (String memberOfPrincipal : isMemberOf) {
+
+ if (StringUtils.equals(authorizablelID, memberOfPrincipal)) {
+ throw new AuthorizableCreatorException("Cannot add authorizable " + authorizablelID + " as member of itself.");
+ }
Authorizable authorizable = userManager.getAuthorizable(memberOfPrincipal);
@@ -754,17 +658,12 @@ private Set validateAssignedGroups(
// check if authorizable is a group
if (authorizable.isGroup()) {
- authorizableSet.add((Group) authorizable);
+ authorizableSet.add(authorizable.getID());
} else {
String message = "Failed to add authorizable "
- + authorizablelID + "to autorizable " + memberOfPrincipal
+ + authorizablelID + " to autorizable " + memberOfPrincipal
+ "! Authorizable is not a group";
- LOG.warn(message);
-
- throw new AuthorizableCreatorException(
- "Failed to add authorizable " + authorizablelID
- + "to autorizable " + memberOfPrincipal
- + "! Authorizable is not a group");
+ throw new AuthorizableCreatorException(message);
}
// if authorizable doesn't exist yet, it gets created and the
// current authorizable gets added as a member
@@ -774,7 +673,7 @@ private Set validateAssignedGroups(
if (principalMapFromConfig.keySet().contains(memberOfPrincipal)) {
// get authorizable intermediatePath
- LinkedHashSet authorizableConfigSet = principalMapFromConfig.get(memberOfPrincipal);
+ Set authorizableConfigSet = principalMapFromConfig.get(memberOfPrincipal);
Iterator it = authorizableConfigSet.iterator();
AuthorizableConfigBean authorizableConfigBean = null;
while (it.hasNext()) {
@@ -788,10 +687,9 @@ private Set validateAssignedGroups(
Group newGroup = userManager.createGroup(
new PrincipalImpl(memberOfPrincipal),
authorizableConfigBean.getPath());
- authorizableSet.add(newGroup);
+ authorizableSet.add(newGroup.getID());
authorizableInstallationHistory.addNewCreatedAuthorizable(newGroup.getID());
- LOG.warn("Failed to add {} to group {} - Created group",
- authorizablelID, memberOfPrincipal);
+ LOG.info("Created group to be able to add {} to group {} ", authorizablelID, memberOfPrincipal);
} else {
String message = "Failed to add group: "
+ authorizablelID
diff --git a/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/configmodel/AcConfiguration.java b/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/configmodel/AcConfiguration.java
new file mode 100644
index 00000000..bc32d0bc
--- /dev/null
+++ b/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/configmodel/AcConfiguration.java
@@ -0,0 +1,53 @@
+/*
+ * (C) Copyright 2016 Netcentric AG.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package biz.netcentric.cq.tools.actool.configmodel;
+
+import java.util.Map;
+import java.util.Set;
+
+import biz.netcentric.cq.tools.actool.authorizableutils.AuthorizableConfigBean;
+import biz.netcentric.cq.tools.actool.helper.AceBean;
+
+/** Root class of the configuration model as it is constructed from the multiple yaml files, it is a fully merged configuration. All loops
+ * and variables have been processed. */
+public class AcConfiguration {
+
+ private GlobalConfiguration globalConfiguration;
+
+ // to be changed from map to PojoClass in future versions
+ private Map> authorizablesMap;
+
+ // to be changed from map to PojoClass in future versions
+ private Map> aceMap;
+
+ public GlobalConfiguration getGlobalConfiguration() {
+ return globalConfiguration;
+ }
+
+ public void setGlobalConfiguration(GlobalConfiguration globalConfiguration) {
+ this.globalConfiguration = globalConfiguration;
+ }
+
+ public Map> getAuthorizablesConfig() {
+ return authorizablesMap;
+ }
+
+ public void setAuthorizablesConfig(Map> authorizablesMap) {
+ this.authorizablesMap = authorizablesMap;
+ }
+
+ public Map> getAceConfig() {
+ return aceMap;
+ }
+
+ public void setAceConfig(Map> aceMap) {
+ this.aceMap = aceMap;
+ }
+
+}
diff --git a/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/configmodel/GlobalConfiguration.java b/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/configmodel/GlobalConfiguration.java
new file mode 100644
index 00000000..264c5924
--- /dev/null
+++ b/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/configmodel/GlobalConfiguration.java
@@ -0,0 +1,78 @@
+/*
+ * (C) Copyright 2016 Netcentric AG.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package biz.netcentric.cq.tools.actool.configmodel;
+
+import java.util.Map;
+import java.util.regex.Pattern;
+
+import org.apache.commons.lang.StringUtils;
+
+import biz.netcentric.cq.tools.actool.validators.GlobalConfigurationValidator;
+
+/** Global configuration that applies to the overall access control configuration system. */
+public class GlobalConfiguration {
+
+ public static final String KEY_MIN_REQUIRED_VERSION = "minRequiredVersion";
+ public static final String KEY_ALLOW_EXTERNAL_GROUP_NAMES_REGEX = "allowExternalGroupNamesRegEx";
+
+ private Pattern allowExternalGroupNamesRegEx;
+ private String minRequiredVersion;
+
+ public GlobalConfiguration() {
+ }
+
+ public GlobalConfiguration(Map globalConfigMap) {
+
+ if (globalConfigMap != null) {
+ setAllowExternalGroupNamesRegEx((String) globalConfigMap.get(KEY_ALLOW_EXTERNAL_GROUP_NAMES_REGEX));
+ setMinRequiredVersion((String) globalConfigMap.get(KEY_MIN_REQUIRED_VERSION));
+ }
+
+ }
+
+ public void merge(GlobalConfiguration otherGlobalConfig) {
+
+ if (otherGlobalConfig.getAllowExternalGroupNamesRegEx() != null) {
+ if (allowExternalGroupNamesRegEx == null) {
+ allowExternalGroupNamesRegEx = otherGlobalConfig.getAllowExternalGroupNamesRegEx();
+ } else {
+ throw new IllegalArgumentException("Duplicate config for " + KEY_ALLOW_EXTERNAL_GROUP_NAMES_REGEX);
+ }
+ }
+
+ if (otherGlobalConfig.getMinRequiredVersion() != null) {
+ if (minRequiredVersion == null) {
+ minRequiredVersion = otherGlobalConfig.getMinRequiredVersion();
+ } else {
+ minRequiredVersion = GlobalConfigurationValidator.versionCompare(otherGlobalConfig.getMinRequiredVersion(), minRequiredVersion) > 0
+ ? otherGlobalConfig.getMinRequiredVersion() : minRequiredVersion;
+ }
+ }
+
+ }
+
+ public Pattern getAllowExternalGroupNamesRegEx() {
+ return allowExternalGroupNamesRegEx;
+ }
+
+ public void setAllowExternalGroupNamesRegEx(String allowExternalGroupNamesRegEx) {
+ this.allowExternalGroupNamesRegEx = StringUtils.isNotBlank(allowExternalGroupNamesRegEx)
+ ? Pattern.compile(allowExternalGroupNamesRegEx) : null;
+ }
+
+ public String getMinRequiredVersion() {
+ return minRequiredVersion;
+ }
+
+ public void setMinRequiredVersion(String requiredMinVersion) {
+ this.minRequiredVersion = requiredMinVersion;
+ }
+
+
+}
diff --git a/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/configreader/ConfigReader.java b/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/configreader/ConfigReader.java
index 5e8235df..b43a099b 100644
--- a/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/configreader/ConfigReader.java
+++ b/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/configreader/ConfigReader.java
@@ -15,6 +15,7 @@
import javax.jcr.RepositoryException;
import biz.netcentric.cq.tools.actool.authorizableutils.AuthorizableConfigBean;
+import biz.netcentric.cq.tools.actool.configmodel.GlobalConfiguration;
import biz.netcentric.cq.tools.actool.helper.AceBean;
import biz.netcentric.cq.tools.actool.validators.AceBeanValidator;
import biz.netcentric.cq.tools.actool.validators.AuthorizableValidator;
@@ -36,4 +37,8 @@ public Map> getUserConfigurationBeans(
final Collection> userConfigData,
AuthorizableValidator authorizableValidator)
throws AcConfigBeanValidationException;
+
+ public GlobalConfiguration getGlobalConfiguration(final Collection yamlList);
+
+
}
\ No newline at end of file
diff --git a/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/configreader/ConfigurationMerger.java b/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/configreader/ConfigurationMerger.java
index 547c974b..ba6797d9 100644
--- a/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/configreader/ConfigurationMerger.java
+++ b/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/configreader/ConfigurationMerger.java
@@ -8,36 +8,27 @@
*/
package biz.netcentric.cq.tools.actool.configreader;
-import java.util.List;
import java.util.Map;
import javax.jcr.RepositoryException;
+import biz.netcentric.cq.tools.actool.configmodel.AcConfiguration;
import biz.netcentric.cq.tools.actool.installationhistory.AcInstallationHistoryPojo;
import biz.netcentric.cq.tools.actool.validators.exceptions.AcConfigBeanValidationException;
public interface ConfigurationMerger {
- /**
- * Method that merges several textual AccessControlConfigurations written in
- * YAML format, each comprising of a groups and ACE configuration.
- * Validation ensures that no doubled defined groups and only valid section
- * identifiers in configuration files are possible
+ /** Method that merges several textual AccessControlConfigurations written in YAML format, each comprising of a groups and ACE
+ * configuration. Validation ensures that no doubled defined groups and only valid section identifiers in configuration files are
+ * possible
*
- * @param newestConfigurations
- * map which contains all paths and configuration in YAML format.
- * key is the node path in CRX under which the respective
- * configuration is stored, entry is the textual configuration
- * @param history
- * history object
- * @return List which contains the combined groups configurations (as map
- * holding sets of AuthorizableConfigBeans) as first element and the
- * combined ACE configurations (as map holding sets of AceBeans) as
- * second element
+ * @param newestConfigurations map which contains all paths and configuration in YAML format. key is the node path in CRX under which
+ * the respective configuration is stored, entry is the textual configuration
+ * @param history history object
+ * @return The AcConfiguration
* @throws RepositoryException in case some repository error has occurred
- * @throws AcConfigBeanValidationException in case the given configuration is invalid
- */
- public abstract List getMergedConfigurations(
+ * @throws AcConfigBeanValidationException in case the given configuration is invalid */
+ public abstract AcConfiguration getMergedConfigurations(
final Map newestConfigurations,
final AcInstallationHistoryPojo history,
final ConfigReader configReader) throws RepositoryException,
diff --git a/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/configreader/YamlConfigReader.java b/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/configreader/YamlConfigReader.java
index 7b69a190..06c2425a 100644
--- a/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/configreader/YamlConfigReader.java
+++ b/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/configreader/YamlConfigReader.java
@@ -32,6 +32,7 @@
import org.slf4j.LoggerFactory;
import biz.netcentric.cq.tools.actool.authorizableutils.AuthorizableConfigBean;
+import biz.netcentric.cq.tools.actool.configmodel.GlobalConfiguration;
import biz.netcentric.cq.tools.actool.helper.AceBean;
import biz.netcentric.cq.tools.actool.helper.Constants;
import biz.netcentric.cq.tools.actool.helper.QueryHelper;
@@ -116,11 +117,21 @@ public Map> getUserConfigurationBeans(final
return principalsMap;
}
- private Collection getConfigSection(final String sectionName, final Collection yamlList) {
+ @Override
+ public GlobalConfiguration getGlobalConfiguration(final Collection yamlList) {
+
+ Map globalConfigMap = (Map) getConfigSection(Constants.GLOBAL_CONFIGURATION_KEY, yamlList);
+
+ GlobalConfiguration globalConfiguration = new GlobalConfiguration(globalConfigMap);
+
+ return globalConfiguration;
+ }
+
+ private Object getConfigSection(final String sectionName, final Collection yamlList) {
final List> yamList = new ArrayList>(yamlList);
for (final LinkedHashMap, ?> currMap : yamList) {
if (sectionName.equals(currMap.keySet().iterator().next())) {
- return (List) currMap.get(sectionName);
+ return currMap.get(sectionName);
}
}
return null;
diff --git a/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/configreader/YamlConfigurationMerger.java b/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/configreader/YamlConfigurationMerger.java
index fe96733a..6d503054 100644
--- a/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/configreader/YamlConfigurationMerger.java
+++ b/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/configreader/YamlConfigurationMerger.java
@@ -8,7 +8,6 @@
*/
package biz.netcentric.cq.tools.actool.configreader;
-import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
@@ -26,11 +25,14 @@
import org.yaml.snakeyaml.Yaml;
import biz.netcentric.cq.tools.actool.authorizableutils.AuthorizableConfigBean;
+import biz.netcentric.cq.tools.actool.configmodel.AcConfiguration;
+import biz.netcentric.cq.tools.actool.configmodel.GlobalConfiguration;
import biz.netcentric.cq.tools.actool.helper.AceBean;
import biz.netcentric.cq.tools.actool.installationhistory.AcInstallationHistoryPojo;
import biz.netcentric.cq.tools.actool.validators.AceBeanValidator;
import biz.netcentric.cq.tools.actool.validators.AuthorizableValidator;
import biz.netcentric.cq.tools.actool.validators.ConfigurationsValidator;
+import biz.netcentric.cq.tools.actool.validators.GlobalConfigurationValidator;
import biz.netcentric.cq.tools.actool.validators.YamlConfigurationsValidator;
import biz.netcentric.cq.tools.actool.validators.exceptions.AcConfigBeanValidationException;
import biz.netcentric.cq.tools.actool.validators.impl.AceBeanValidatorImpl;
@@ -47,30 +49,28 @@ public class YamlConfigurationMerger implements ConfigurationMerger {
YamlMacroProcessor yamlMacroProcessor;
@Override
- public List getMergedConfigurations(
- final Map newestConfigurations,
+ public AcConfiguration getMergedConfigurations(
+ final Map configFileContentByFilename,
final AcInstallationHistoryPojo history,
final ConfigReader configReader) throws RepositoryException,
AcConfigBeanValidationException {
- final List c = new ArrayList