You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by an...@apache.org on 2021/08/12 10:07:55 UTC

[jackrabbit-oak] branch trunk updated: OAK-9530 : Minor improvements to ACE.java

This is an automated email from the ASF dual-hosted git repository.

angela pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git


The following commit(s) were added to refs/heads/trunk by this push:
     new eedf552  OAK-9530 : Minor improvements to ACE.java
eedf552 is described below

commit eedf552b00750857ec92eee0ca6cdf3b844550fa
Author: angela <an...@adobe.com>
AuthorDate: Thu Aug 12 12:07:31 2021 +0200

    OAK-9530 : Minor improvements to ACE.java
---
 .../security/authorization/accesscontrol/ACE.java  | 50 ++++++++++++----------
 1 file changed, 28 insertions(+), 22 deletions(-)

diff --git a/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/accesscontrol/ACE.java b/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/accesscontrol/ACE.java
index 8bf8aac..468731c 100644
--- a/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/accesscontrol/ACE.java
+++ b/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/accesscontrol/ACE.java
@@ -16,16 +16,6 @@
  */
 package org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol;
 
-import java.security.Principal;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
-import javax.jcr.RepositoryException;
-import javax.jcr.Value;
-import javax.jcr.ValueFormatException;
-import javax.jcr.security.AccessControlException;
-
-import com.google.common.base.Function;
 import com.google.common.base.Objects;
 import com.google.common.collect.Collections2;
 import com.google.common.collect.ImmutableSet;
@@ -37,6 +27,15 @@ import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeBits;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+import javax.jcr.security.AccessControlException;
+import java.security.Principal;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
 /**
  * Default implementation of the {@code JackrabbitAccessControlEntry} interface.
  * It asserts that the basic contract is fulfilled but does perform any additional
@@ -53,8 +52,19 @@ public abstract class ACE implements JackrabbitAccessControlEntry {
 
     private int hashCode;
 
-    public ACE(Principal principal, PrivilegeBits privilegeBits,
-               boolean isAllow, Set<Restriction> restrictions, NamePathMapper namePathMapper) throws AccessControlException {
+    /**
+     * Creates a new access control entry.
+     * 
+     * @param principal The principal associated with this entry.
+     * @param privilegeBits The privilege bits defined for this entry.
+     * @param isAllow {@code true} if the entry is granting privileges.
+     * @param restrictions A optional set of restrictions.
+     * @param namePathMapper The name-path mapper
+     * @throws AccessControlException If the given {@code principal} or {@code privilgeBits} are {@code null} or if {@code privilgeBits} are {@link PrivilegeBits#isEmpty() empty}.
+     */
+    public ACE(@Nullable Principal principal, @Nullable PrivilegeBits privilegeBits,
+               boolean isAllow, @Nullable Set<Restriction> restrictions, 
+               @NotNull NamePathMapper namePathMapper) throws AccessControlException {
         if (principal == null || privilegeBits == null || privilegeBits.isEmpty()) {
             throw new AccessControlException();
         }
@@ -62,7 +72,7 @@ public abstract class ACE implements JackrabbitAccessControlEntry {
         this.principal = principal;
         this.privilegeBits = privilegeBits;
         this.isAllow = isAllow;
-        this.restrictions = (restrictions == null) ? Collections.<Restriction>emptySet() : ImmutableSet.copyOf(restrictions);
+        this.restrictions = (restrictions == null) ? Collections.emptySet() : ImmutableSet.copyOf(restrictions);
         this.namePathMapper = namePathMapper;
         this.valueFactory = new PartialValueFactory(namePathMapper);
     }
@@ -94,12 +104,7 @@ public abstract class ACE implements JackrabbitAccessControlEntry {
     @NotNull
     @Override
     public String[] getRestrictionNames() {
-        return Collections2.transform(restrictions, new Function<Restriction, String>() {
-            @Override
-            public String apply(Restriction restriction) {
-                return getJcrName(restriction);
-            }
-        }).toArray(new String[restrictions.size()]);
+        return Collections2.transform(restrictions, this::getJcrName).toArray(new String[restrictions.size()]);
     }
 
     @Nullable
@@ -110,9 +115,10 @@ public abstract class ACE implements JackrabbitAccessControlEntry {
             if (jcrName.equals(restrictionName)) {
                 if (restriction.getDefinition().getRequiredType().isArray()) {
                     List<Value> values = valueFactory.createValues(restriction.getProperty());
-                    switch (values.size()) {
-                        case 1: return values.get(0);
-                        default : throw new ValueFormatException("Attempt to retrieve single value from multivalued property");
+                    if (values.size() == 1) {
+                        return values.get(0);
+                    } else {
+                        throw new ValueFormatException("Attempt to retrieve single value from multivalued property");
                     }
                 } else {
                     return valueFactory.createValue(restriction.getProperty());