You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2016/11/07 15:13:33 UTC
svn commit: r1768529 - in
/sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl:
JcrRepoInitOpsProcessorImpl.java ServiceAndAclVisitor.java UserVisitor.java
Author: cziegeler
Date: Mon Nov 7 15:13:32 2016
New Revision: 1768529
URL: http://svn.apache.org/viewvc?rev=1768529&view=rev
Log:
SLING-6219 : Move ACL handling into separate visitor
Added:
sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/UserVisitor.java
- copied, changed from r1768528, sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/ServiceAndAclVisitor.java
Removed:
sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/ServiceAndAclVisitor.java
Modified:
sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOpsProcessorImpl.java
Modified: sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOpsProcessorImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOpsProcessorImpl.java?rev=1768529&r1=1768528&r2=1768529&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOpsProcessorImpl.java (original)
+++ sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOpsProcessorImpl.java Mon Nov 7 15:13:32 2016
@@ -30,18 +30,20 @@ import org.apache.sling.repoinit.parser.
@Component
@Service(JcrRepoInitOpsProcessor.class)
public class JcrRepoInitOpsProcessorImpl implements JcrRepoInitOpsProcessor {
-
+
/** Apply the supplied operations: first the namespaces and nodetypes
* registrations, then the service users, paths and ACLs.
*/
+ @Override
public void apply(Session session, List<Operation> ops) {
-
+
final OperationVisitor [] visitors = {
new NamespacesVisitor(session),
new NodetypesVisitor(session),
- new ServiceAndAclVisitor(session)
+ new UserVisitor(session),
+ new AclVisitor(session)
};
-
+
for(OperationVisitor v : visitors) {
for(Operation op : ops) {
op.accept(v);
Copied: sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/UserVisitor.java (from r1768528, sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/ServiceAndAclVisitor.java)
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/UserVisitor.java?p2=sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/UserVisitor.java&p1=sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/ServiceAndAclVisitor.java&r1=1768528&r2=1768529&rev=1768529&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/ServiceAndAclVisitor.java (original)
+++ sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/UserVisitor.java Mon Nov 7 15:13:32 2016
@@ -16,34 +16,22 @@
*/
package org.apache.sling.jcr.repoinit.impl;
-import java.util.List;
-
-import javax.jcr.Node;
import javax.jcr.Session;
-import org.apache.sling.repoinit.parser.operations.AclLine;
-import org.apache.sling.repoinit.parser.operations.CreatePath;
import org.apache.sling.repoinit.parser.operations.CreateServiceUser;
import org.apache.sling.repoinit.parser.operations.DeleteServiceUser;
-import org.apache.sling.repoinit.parser.operations.PathSegmentDefinition;
-import org.apache.sling.repoinit.parser.operations.SetAclPaths;
-import org.apache.sling.repoinit.parser.operations.SetAclPrincipals;
-
-import static org.apache.sling.repoinit.parser.operations.AclLine.PROP_PATHS;
-import static org.apache.sling.repoinit.parser.operations.AclLine.PROP_PRINCIPALS;
-import static org.apache.sling.repoinit.parser.operations.AclLine.PROP_PRIVILEGES;
/** OperationVisitor which processes only operations related to
* service users and ACLs. Having several such specialized visitors
* makes it easy to control the execution order.
*/
-class ServiceAndAclVisitor extends DoNothingVisitor {
+class UserVisitor extends DoNothingVisitor {
/** Create a visitor using the supplied JCR Session.
* @param s must have sufficient rights to create users
* and set ACLs.
*/
- public ServiceAndAclVisitor(Session s) {
+ public UserVisitor(Session s) {
super(s);
}
@@ -72,64 +60,4 @@ class ServiceAndAclVisitor extends DoNot
report(e, "Unable to delete service user [" + id + "]:" + e);
}
}
-
- private List<String> require(AclLine line, String propertyName) {
- final List<String> result = line.getProperty(propertyName);
- if(result == null) {
- throw new IllegalStateException("Missing property " + propertyName + " on " + line);
- }
- return result;
- }
-
- private void setAcl(AclLine line, Session s, List<String> principals, List<String> paths, List<String> privileges, boolean isAllow) {
- try {
- log.info("Adding ACL '{}' entry '{}' for {} on {}", isAllow ? "allow" : "deny", privileges, principals, paths);
- AclUtil.setAcl(s, principals, paths, privileges, isAllow);
- } catch(Exception e) {
- throw new RuntimeException("Failed to set ACL (" + e.toString() + ") " + line, e);
- }
- }
-
- @Override
- public void visitSetAclPrincipal(SetAclPrincipals s) {
- final List<String> principals = s.getPrincipals();
- for(AclLine line : s.getLines()) {
- final boolean isAllow = line.getAction().equals(AclLine.Action.ALLOW);
- setAcl(line, session, principals, require(line, PROP_PATHS), require(line, PROP_PRIVILEGES), isAllow);
- }
- }
-
- @Override
- public void visitSetAclPaths(SetAclPaths s) {
- final List<String> paths = s.getPaths();
- for(AclLine line : s.getLines()) {
- final boolean isAllow = line.getAction().equals(AclLine.Action.ALLOW);
- setAcl(line, session, require(line, PROP_PRINCIPALS), paths, require(line, PROP_PRIVILEGES), isAllow);
- }
- }
-
- @Override
- public void visitCreatePath(CreatePath cp) {
- String parentPath = "";
- for(PathSegmentDefinition psd : cp.getDefinitions()) {
- final String fullPath = parentPath + "/" + psd.getSegment();
- try {
- if(session.itemExists(fullPath)) {
- log.info("Path already exists, nothing to do (and not checking its primary type for now): {}", fullPath);
- } else {
- final Node n = parentPath.equals("") ? session.getRootNode() : session.getNode(parentPath);
- log.info("Creating node {} with primary type {}", fullPath, psd.getPrimaryType());
- n.addNode(psd.getSegment(), psd.getPrimaryType());
- }
- } catch(Exception e) {
- throw new RuntimeException("CreatePath execution failed at " + psd + ": " + e, e);
- }
- parentPath += "/" + psd.getSegment();
- }
- try {
- session.save();
- } catch(Exception e) {
- throw new RuntimeException("Session.save failed: "+ e, e);
- }
- }
}