This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-cpconverter.git
The following commit(s) were added to refs/heads/master by this push:
new 97219c0 SLING-9963 : AccessControlEntry: refactor 'operation' string
to boolean/enum (#36)
97219c0 is described below
commit 97219c03dfbcbcf4139910100cb708bced6acb6d
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Thu Dec 3 09:37:05 2020 +0100
SLING-9963 : AccessControlEntry: refactor 'operation' string to
boolean/enum (#36)
Co-authored-by: angela <[email protected]>
---
.../cpconverter/accesscontrol/AccessControlEntry.java | 12 ++++++------
.../cpconverter/handlers/RepPolicyEntryHandler.java | 10 +++++-----
.../feature/cpconverter/accesscontrol/AclManagerTest.java | 14 +++++++-------
3 files changed, 18 insertions(+), 18 deletions(-)
diff --git
a/src/main/java/org/apache/sling/feature/cpconverter/accesscontrol/AccessControlEntry.java
b/src/main/java/org/apache/sling/feature/cpconverter/accesscontrol/AccessControlEntry.java
index 150e8c7..b6b850b 100644
---
a/src/main/java/org/apache/sling/feature/cpconverter/accesscontrol/AccessControlEntry.java
+++
b/src/main/java/org/apache/sling/feature/cpconverter/accesscontrol/AccessControlEntry.java
@@ -26,7 +26,7 @@ import java.util.List;
*/
public final class AccessControlEntry {
- private final String operation;
+ private final boolean isAllow;
private final String privileges;
@@ -36,8 +36,8 @@ public final class AccessControlEntry {
private final List<String> restrictions = new LinkedList<>();
- public AccessControlEntry(String operation, String privileges, RepoPath
path, RepoPath repositoryPath) {
- this.operation = operation;
+ public AccessControlEntry(boolean isAllow, String privileges, RepoPath
path, RepoPath repositoryPath) {
+ this.isAllow = isAllow;
this.privileges = privileges;
this.path = path;
this.repositoryPath = repositoryPath;
@@ -50,7 +50,7 @@ public final class AccessControlEntry {
}
public String getOperation() {
- return operation;
+ return isAllow ? "allow" : "deny";
}
public String getPrivileges() {
@@ -71,8 +71,8 @@ public final class AccessControlEntry {
@Override
public String toString() {
- return "Acl [operation="
- + operation
+ return "Acl [isAllow="
+ + isAllow
+ ", privileges="
+ privileges
+ ", path="
diff --git
a/src/main/java/org/apache/sling/feature/cpconverter/handlers/RepPolicyEntryHandler.java
b/src/main/java/org/apache/sling/feature/cpconverter/handlers/RepPolicyEntryHandler.java
index f665beb..130ce41 100644
---
a/src/main/java/org/apache/sling/feature/cpconverter/handlers/RepPolicyEntryHandler.java
+++
b/src/main/java/org/apache/sling/feature/cpconverter/handlers/RepPolicyEntryHandler.java
@@ -111,11 +111,11 @@ public final class RepPolicyEntryHandler extends
AbstractRegexEntryHandler {
private static final String REP_PRIVILEGES = "rep:privileges";
- private static final Map<String, String> operations = new HashMap<>();
+ private static final Map<String, Boolean> operations = new HashMap<>();
static {
- operations.put(REP_GRANT_ACE, "allow");
- operations.put(REP_DENY_ACE, "deny");
+ operations.put(REP_GRANT_ACE, true);
+ operations.put(REP_DENY_ACE, false);
}
private static final String[] RESTRICTIONS = new String[] {
"rep:glob", "rep:ntNames", "rep:prefixes", "rep:itemNames" };
@@ -161,11 +161,11 @@ public final class RepPolicyEntryHandler extends
AbstractRegexEntryHandler {
if (REP_GRANT_ACE.equals(primaryType) ||
REP_DENY_ACE.equals(primaryType)) {
String principalName =
attributes.getValue(REP_PRINCIPAL_NAME);
- String operation = operations.get(primaryType);
+ Boolean isAllow = operations.get(primaryType);
String privileges =
extractValue(attributes.getValue(REP_PRIVILEGES));
- AccessControlEntry acl = new AccessControlEntry(operation,
privileges, path, repositoryPath);
+ AccessControlEntry acl = new AccessControlEntry(isAllow,
privileges, path, repositoryPath);
processCurrentAcl = aclManager.addAcl(principalName, acl);
if (processCurrentAcl) {
diff --git
a/src/test/java/org/apache/sling/feature/cpconverter/accesscontrol/AclManagerTest.java
b/src/test/java/org/apache/sling/feature/cpconverter/accesscontrol/AclManagerTest.java
index 6292e5e..dfa4806 100644
---
a/src/test/java/org/apache/sling/feature/cpconverter/accesscontrol/AclManagerTest.java
+++
b/src/test/java/org/apache/sling/feature/cpconverter/accesscontrol/AclManagerTest.java
@@ -78,11 +78,11 @@ public class AclManagerTest {
aclManager.addSystemUser(new
SystemUser("acs-commons-package-replication-status-event-service", new
RepoPath("/asd/public")));
- aclManager.addAcl("acs-commons-ensure-oak-index-service",
newAcl("allow", "jcr:read,rep:write,rep:indexDefinitionManagement",
"/asd/not/system/user/path"));
-
aclManager.addAcl("acs-commons-package-replication-status-event-service",
newAcl("allow", "jcr:read,crx:replicate,jcr:removeNode", "/asd/public"));
+ aclManager.addAcl("acs-commons-ensure-oak-index-service", newAcl(true,
"jcr:read,rep:write,rep:indexDefinitionManagement",
"/asd/not/system/user/path"));
+
aclManager.addAcl("acs-commons-package-replication-status-event-service",
newAcl(true, "jcr:read,crx:replicate,jcr:removeNode", "/asd/public"));
// add an ACL for unknown user
- aclManager.addAcl("acs-commons-on-deploy-scripts-service",
newAcl("allow", "jcr:read,crx:replicate,jcr:removeNode", "/asd/public"));
+ aclManager.addAcl("acs-commons-on-deploy-scripts-service",
newAcl(true, "jcr:read,crx:replicate,jcr:removeNode", "/asd/public"));
VaultPackageAssembler assembler = mock(VaultPackageAssembler.class);
when(assembler.getEntry(anyString())).thenReturn(new
File(System.getProperty("java.io.tmpdir")));
@@ -123,8 +123,8 @@ public class AclManagerTest {
@Test
public void pathWithSpecialCharactersTest() throws
RepoInitParsingException {
aclManager.addSystemUser(new SystemUser("sys-usr", new
RepoPath("/home/users/system")));
- aclManager.addAcl("sys-usr", newAcl("allow", "jcr:read",
"/content/_cq_tags"));
- aclManager.addAcl("sys-usr", newAcl("allow", "jcr:write",
"/content/cq:tags"));
+ aclManager.addAcl("sys-usr", newAcl(true, "jcr:read",
"/content/_cq_tags"));
+ aclManager.addAcl("sys-usr", newAcl(true, "jcr:write",
"/content/cq:tags"));
VaultPackageAssembler assembler = mock(VaultPackageAssembler.class);
when(assembler.getEntry(anyString())).thenReturn(new
File(System.getProperty("java.io.tmpdir")));
Feature feature = new Feature(new ArtifactId("org.apache.sling",
"org.apache.sling.cp2fm", "0.0.1", null, null));
@@ -154,8 +154,8 @@ public class AclManagerTest {
assertFalse(operations.isEmpty());
}
- private static AccessControlEntry newAcl(String operation, String
privileges, String path) {
- return new AccessControlEntry(operation, privileges, new
RepoPath(path), new RepoPath(PlatformNameFormat.getRepositoryPath(path)));
+ private static AccessControlEntry newAcl(boolean isAllow, String
privileges, String path) {
+ return new AccessControlEntry(isAllow, privileges, new RepoPath(path),
new RepoPath(PlatformNameFormat.getRepositoryPath(path)));
}
}