You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:49:01 UTC
[sling-org-apache-sling-jcr-repoinit] 18/43: SLING-5449 - remove
AclSetup component and adapt integration tests
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.jcr.repoinit-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git
commit 22a05d6f8e408d0e85a3b7d28871a378a33811ff
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Fri Jan 22 18:18:22 2016 +0000
SLING-5449 - remove AclSetup component and adapt integration tests
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/repoinit/oak-jcr@1726268 13f79535-47bb-0310-9956-ffa450edef68
---
.../sling/repoinit/jcr/AclOperationVisitor.java | 2 +
.../apache/sling/repoinit/jcr/impl/AclSetup.java | 154 ---------------------
.../sling/repoinit/jcr/{ => impl}/AclUtil.java | 2 +-
.../repoinit/jcr/{ => impl}/ServiceUserUtil.java | 2 +-
.../apache/sling/repoinit/jcr/package-info.java | 21 +++
.../org/apache/sling/repoinit/jcr/TestUtil.java | 1 +
6 files changed, 26 insertions(+), 156 deletions(-)
diff --git a/src/main/java/org/apache/sling/repoinit/jcr/AclOperationVisitor.java b/src/main/java/org/apache/sling/repoinit/jcr/AclOperationVisitor.java
index 6403e65..f206351 100644
--- a/src/main/java/org/apache/sling/repoinit/jcr/AclOperationVisitor.java
+++ b/src/main/java/org/apache/sling/repoinit/jcr/AclOperationVisitor.java
@@ -24,6 +24,8 @@ import java.util.List;
import javax.jcr.Session;
+import org.apache.sling.repoinit.jcr.impl.AclUtil;
+import org.apache.sling.repoinit.jcr.impl.ServiceUserUtil;
import org.apache.sling.repoinit.parser.operations.AclLine;
import org.apache.sling.repoinit.parser.operations.CreateServiceUser;
import org.apache.sling.repoinit.parser.operations.DeleteServiceUser;
diff --git a/src/main/java/org/apache/sling/repoinit/jcr/impl/AclSetup.java b/src/main/java/org/apache/sling/repoinit/jcr/impl/AclSetup.java
deleted file mode 100644
index 9bb2606..0000000
--- a/src/main/java/org/apache/sling/repoinit/jcr/impl/AclSetup.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sling.repoinit.jcr.impl;
-
-import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import javax.jcr.Session;
-
-import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.ConfigurationPolicy;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.sling.repoinit.jcr.AclOperationVisitor;
-import org.apache.sling.repoinit.parser.AclDefinitionsParser;
-import org.apache.sling.repoinit.parser.operations.Operation;
-import org.apache.sling.commons.threads.ThreadPool;
-import org.apache.sling.commons.threads.ThreadPoolManager;
-import org.apache.sling.jcr.api.SlingRepository;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import aQute.bnd.annotation.component.Deactivate;
-
-/** OSGi component that sets up service users and ACLS
- * based on configurations created by the repoinit provisioning
- * model processor.
- *
- * As Oak requires a path to exist before setting an ACL on it,
- * this component needs to retry setting ACLs when that fails
- * due to a non-existing path.
- */
-@Component(
- configurationFactory=true,
- metatype=false,
- configurationPid=AclSetup.CONFIG_PID,
- policy=ConfigurationPolicy.REQUIRE)
-public class AclSetup implements Runnable {
- private final Logger log = LoggerFactory.getLogger(getClass());
- public static final String CONFIG_PID = "org.apache.sling.repoinit.jcr.AclSetup";
- public static final String ACLDEF_PROP_PREFIX = "repoinit.text.";
- public static final String THREAD_POOL_NAME = "ACL Definitions";
-
- private List<String> todo;
- private ThreadPool threadPool;
- private boolean running;
-
- @Reference
- AclDefinitionsParser parser;
-
- @Reference
- ThreadPoolManager threadPoolManager;
-
- @Reference
- SlingRepository repository;
-
- @Activate
- public void activate(Map<String, Object> config) {
- todo = new ArrayList<String>();
- threadPool = threadPoolManager.get(THREAD_POOL_NAME);
-
- for(String key : config.keySet()) {
- if(key.startsWith(ACLDEF_PROP_PREFIX)) {
- final String value = (String)config.get(key);
- todo.add(value);
- }
- }
- if(todo.isEmpty()) {
- log.error("No {} properties in configuration {}, nothing to do", ACLDEF_PROP_PREFIX, config);
- } else {
- log.info("Got {} ACL definitions to execute asynchronously", todo.size());
- running = true;
- threadPool.execute(this);
- }
- }
-
- @Deactivate
- public void deactivate(Map<String, Object> config) {
- synchronized (this) {
- running = false;
- threadPoolManager.release(threadPool);
- }
- }
-
- private void sleep(int msec) {
- try {
- Thread.sleep(msec);
- } catch(InterruptedException ignore) {
- }
- }
-
- @Override
- public void run() {
- log.info("Applying {} ACL definition snippets", todo.size());
-
- List<String> newTodo = new ArrayList<String>();
- Session s = null;
- try {
- s = repository.loginAdministrative(null);
- final AclOperationVisitor visitor = new AclOperationVisitor(s);
- for(String repoinit : todo) {
- try {
- for(Operation op : parser.parse(new StringReader(repoinit))) {
- op.accept(visitor);
- s.save();
- }
- } catch(Exception e) {
- log.warn("Exception while executing an ACL definition:" + e.toString(), e);
- newTodo.add(repoinit);
- }
- }
- } catch(Exception e) {
- log.warn("Exception while executing ACL definitions, will retry everything:" + e.toString(), e);
- newTodo = todo;
- } finally {
- if(s != null) {
- s.logout();
- }
- }
-
- // TODO schedule with exponential backoff?
- if(!newTodo.isEmpty() && running) {
- sleep(1000);
- }
-
- synchronized (this) {
- todo = newTodo;
- if(todo.isEmpty()) {
- log.info("All ACL definitions executed");
- } else if(running) {
- log.info("{} ACL definitions left to execute, will retry", todo.size());
- threadPool.execute(this);
- } else {
- log.info("Some operations failed but not running anymore");
- }
- }
- }
-}
diff --git a/src/main/java/org/apache/sling/repoinit/jcr/AclUtil.java b/src/main/java/org/apache/sling/repoinit/jcr/impl/AclUtil.java
similarity index 98%
rename from src/main/java/org/apache/sling/repoinit/jcr/AclUtil.java
rename to src/main/java/org/apache/sling/repoinit/jcr/impl/AclUtil.java
index 10a7967..efe3cf5 100644
--- a/src/main/java/org/apache/sling/repoinit/jcr/AclUtil.java
+++ b/src/main/java/org/apache/sling/repoinit/jcr/impl/AclUtil.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.sling.repoinit.jcr;
+package org.apache.sling.repoinit.jcr.impl;
import java.security.Principal;
import java.util.List;
diff --git a/src/main/java/org/apache/sling/repoinit/jcr/ServiceUserUtil.java b/src/main/java/org/apache/sling/repoinit/jcr/impl/ServiceUserUtil.java
similarity index 98%
rename from src/main/java/org/apache/sling/repoinit/jcr/ServiceUserUtil.java
rename to src/main/java/org/apache/sling/repoinit/jcr/impl/ServiceUserUtil.java
index 65fa155..5f33145 100644
--- a/src/main/java/org/apache/sling/repoinit/jcr/ServiceUserUtil.java
+++ b/src/main/java/org/apache/sling/repoinit/jcr/impl/ServiceUserUtil.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.sling.repoinit.jcr;
+package org.apache.sling.repoinit.jcr.impl;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
diff --git a/src/main/java/org/apache/sling/repoinit/jcr/package-info.java b/src/main/java/org/apache/sling/repoinit/jcr/package-info.java
new file mode 100644
index 0000000..a2fd18a
--- /dev/null
+++ b/src/main/java/org/apache/sling/repoinit/jcr/package-info.java
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+@Version("1.0.0")
+package org.apache.sling.repoinit.jcr;
+
+import aQute.bnd.annotation.Version;
diff --git a/src/test/java/org/apache/sling/repoinit/jcr/TestUtil.java b/src/test/java/org/apache/sling/repoinit/jcr/TestUtil.java
index 612e699..5c68f3f 100644
--- a/src/test/java/org/apache/sling/repoinit/jcr/TestUtil.java
+++ b/src/test/java/org/apache/sling/repoinit/jcr/TestUtil.java
@@ -31,6 +31,7 @@ import javax.jcr.SimpleCredentials;
import org.apache.commons.io.IOUtils;
import org.apache.jackrabbit.api.security.user.Authorizable;
import org.apache.jackrabbit.api.security.user.User;
+import org.apache.sling.repoinit.jcr.impl.ServiceUserUtil;
import org.apache.sling.repoinit.parser.AclParsingException;
import org.apache.sling.repoinit.parser.impl.ACLDefinitionsParserService;
import org.apache.sling.repoinit.parser.operations.Operation;
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.