|
10 | 10 |
|
11 | 11 | import java.util.ArrayList; |
12 | 12 | import java.util.Arrays; |
| 13 | +import java.util.Collection; |
13 | 14 | import java.util.HashSet; |
14 | 15 | import java.util.LinkedHashSet; |
15 | 16 | import java.util.List; |
|
22 | 23 | import javax.jcr.UnsupportedRepositoryOperationException; |
23 | 24 | import javax.jcr.ValueFormatException; |
24 | 25 |
|
| 26 | +import org.apache.commons.collections.CollectionUtils; |
| 27 | +import org.apache.commons.lang.StringUtils; |
25 | 28 | import org.apache.commons.lang.time.StopWatch; |
26 | 29 | import org.apache.felix.scr.annotations.Activate; |
27 | 30 | import org.apache.felix.scr.annotations.Component; |
@@ -120,17 +123,49 @@ private void installConfigurationFromYamlList( |
120 | 123 | LOG.error(message); |
121 | 124 | throw new IllegalArgumentException(message); |
122 | 125 | } |
123 | | - removeAcesForAuthorizable(history, session, authorizablesMapfromConfig.keySet(), repositoryDumpAceMap); |
| 126 | + |
| 127 | + Set<String> authorizablesToRemoveAcesFor = getAuthorizablesToRemoveAcesFor(authorizablesMapfromConfig); |
| 128 | + |
| 129 | + removeAcesForAuthorizables(history, session, authorizablesToRemoveAcesFor, repositoryDumpAceMap); |
124 | 130 | installAuthorizables(history, authorizableHistorySet, authorizablesMapfromConfig); |
125 | 131 | installAces(history, session, aceMapFromConfig); |
126 | 132 | } |
127 | | - |
128 | | - private void removeAcesForAuthorizable(AcInstallationHistoryPojo history, Session session, Set<String> authorizablesSet, Map<String, Set<AceBean>> repositoryDumpAceMap) throws UnsupportedRepositoryOperationException, RepositoryException { |
129 | | - // loop through all ACLs found in the repository |
| 133 | + |
| 134 | + private Set<String> getAuthorizablesToRemoveAcesFor(Map<String, LinkedHashSet<AuthorizableConfigBean>> authorizablesMapfromConfig) { |
| 135 | + Set<String> authorizablesToRemoveAcesFor = new HashSet<String>(authorizablesMapfromConfig.keySet()); |
| 136 | + Set<String> authorizablesToBeMigrated = collectAuthorizablesToBeMigrated(authorizablesMapfromConfig); |
| 137 | + Collection<?> invalidAuthorizablesInConfig = CollectionUtils.intersection(authorizablesToRemoveAcesFor, authorizablesToBeMigrated); |
| 138 | + if (!invalidAuthorizablesInConfig.isEmpty()) { |
| 139 | + String message = "If migrateFrom feature is used, groups that shall be migrated from must not be present in regular configuration (offending groups: " |
| 140 | + + invalidAuthorizablesInConfig + ")"; |
| 141 | + LOG.error(message); |
| 142 | + throw new IllegalArgumentException(message); |
| 143 | + } |
| 144 | + authorizablesToRemoveAcesFor.addAll(authorizablesToBeMigrated); |
| 145 | + return authorizablesToRemoveAcesFor; |
| 146 | + } |
| 147 | + |
| 148 | + private Set<String> collectAuthorizablesToBeMigrated(Map<String, LinkedHashSet<AuthorizableConfigBean>> authorizablesMapfromConfig) { |
| 149 | + Set<String> authorizablesToBeMigrated = new HashSet<String>(); |
| 150 | + for (String principalStr : authorizablesMapfromConfig.keySet()) { |
| 151 | + LinkedHashSet<AuthorizableConfigBean> authorizableConfigBeans = authorizablesMapfromConfig.get(principalStr); |
| 152 | + for (AuthorizableConfigBean authorizableConfigBean : authorizableConfigBeans) { |
| 153 | + String migrateFrom = authorizableConfigBean.getMigrateFrom(); |
| 154 | + if (StringUtils.isNotBlank(migrateFrom)) { |
| 155 | + authorizablesToBeMigrated.add(migrateFrom); |
| 156 | + } |
| 157 | + } |
| 158 | + } |
| 159 | + return authorizablesToBeMigrated; |
| 160 | + } |
| 161 | + |
| 162 | + private void removeAcesForAuthorizables(AcInstallationHistoryPojo history, Session session, Set<String> authorizablesSet, |
| 163 | + Map<String, Set<AceBean>> repositoryDumpAceMap) throws UnsupportedRepositoryOperationException, RepositoryException { |
| 164 | + // loop through all ACLs found in the repository |
130 | 165 | for (Map.Entry<String, Set<AceBean>> entry : repositoryDumpAceMap.entrySet()) { |
131 | 166 | Set<AceBean> acl = entry.getValue(); |
132 | 167 | for (AceBean aceBean : acl) { |
133 | | - // if the ACL form repo contains an ACE regarding an |
| 168 | + // if the ACL from repo contains an ACE regarding an |
134 | 169 | // authorizable from the groups config then delete all ACEs from |
135 | 170 | // this authorizable from current ACL |
136 | 171 | if (authorizablesSet.contains(aceBean.getPrincipalName())) { |
@@ -163,7 +198,7 @@ private void installAuthorizables( |
163 | 198 | AcInstallationHistoryPojo history, |
164 | 199 | Set<AuthorizableInstallationHistory> authorizableHistorySet, |
165 | 200 | Map<String, LinkedHashSet<AuthorizableConfigBean>> authorizablesMapfromConfig) |
166 | | - throws RepositoryException, Exception { |
| 201 | + throws RepositoryException, Exception { |
167 | 202 | // --- installation of Authorizables from configuration --- |
168 | 203 |
|
169 | 204 | LOG.info("--- start installation of Authorizable Configuration ---"); |
@@ -198,7 +233,7 @@ private void installAuthorizables( |
198 | 233 | } |
199 | 234 | } |
200 | 235 |
|
201 | | - String message = "finished installation of groups configuration without errors!"; |
| 236 | + String message = "Finished installation of groups configuration without errors"; |
202 | 237 | history.addMessage(message); |
203 | 238 | LOG.info(message); |
204 | 239 | } |
@@ -256,7 +291,7 @@ public AcInstallationHistoryPojo execute() { |
256 | 291 | public void installNewConfigurations(Session session, |
257 | 292 | AcInstallationHistoryPojo history, |
258 | 293 | Map<String, String> newestConfigurations, Set<AuthorizableInstallationHistory> authorizableInstallationHistorySet) |
259 | | - throws Exception { |
| 294 | + throws Exception { |
260 | 295 |
|
261 | 296 | StopWatch sw = new StopWatch(); |
262 | 297 | sw.start(); |
|
0 commit comments