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:50:14 UTC

[sling-org-apache-sling-jcr-jackrabbit-usermanager] 10/14: SLING-6753 expose underlying repository path of authorizable as well

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

rombert pushed a commit to annotated tag org.apache.sling.jcr.jackrabbit.usermanager-2.2.6
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-jackrabbit-usermanager.git

commit ab6ca19216b4144d6cb0f714d7af421a816939cc
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Thu Mar 30 11:33:24 2017 +0000

    SLING-6753 expose underlying repository path of authorizable as well
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/jackrabbit-usermanager@1789498 13f79535-47bb-0310-9956-ffa450edef68
---
 .../impl/resource/AuthorizableValueMap.java        | 38 +++++++++++++++-------
 1 file changed, 27 insertions(+), 11 deletions(-)

diff --git a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/resource/AuthorizableValueMap.java b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/resource/AuthorizableValueMap.java
index 753dd8e..5640754 100644
--- a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/resource/AuthorizableValueMap.java
+++ b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/resource/AuthorizableValueMap.java
@@ -32,6 +32,7 @@ import java.util.Set;
 import javax.jcr.Property;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
+import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.Value;
 import javax.jcr.ValueFormatException;
 
@@ -54,9 +55,9 @@ public class AuthorizableValueMap implements ValueMap {
 
     private static final String MEMBER_OF_KEY = "memberOf";
 
-    private static final Logger LOG = LoggerFactory.getLogger(AuthorizableValueMap.class);
+    private static final String PATH_KEY = "path";
 
-    private Logger logger = LoggerFactory.getLogger(AuthorizableValueMap.class);
+    private static final Logger LOG = LoggerFactory.getLogger(AuthorizableValueMap.class);
 
     private boolean fullyRead;
 
@@ -154,12 +155,14 @@ public class AuthorizableValueMap implements ValueMap {
                 return getMembers((Group) authorizable, false);
             }
             if (key.equals(MEMBER_OF_KEY)) {
-                return getMemberships(authorizable, true);
+                return getMemberships(true);
             }
             if (key.equals(DECLARED_MEMBER_OF_KEY)) {
-                return getMemberships(authorizable, false);
+                return getMemberships(false);
+            }
+            if (key.equals(PATH_KEY)) {
+                return getPath();
             }
-
             if (authorizable.hasProperty(key)) {
                 final Value[] property = authorizable.getProperty(key);
                 final Object value = valuesToJavaObject(property);
@@ -226,10 +229,14 @@ public class AuthorizableValueMap implements ValueMap {
                     cache.put(MEMBERS_KEY, getMembers((Group) authorizable, true));
                     cache.put(DECLARED_MEMBERS_KEY, getMembers((Group) authorizable, false));
                 }
-                cache.put(MEMBER_OF_KEY, getMemberships(authorizable, true));
-                cache.put(DECLARED_MEMBER_OF_KEY, getMemberships(authorizable, false));
+                cache.put(MEMBER_OF_KEY, getMemberships(true));
+                cache.put(DECLARED_MEMBER_OF_KEY, getMemberships(false));
 
-                // only direct properties are supported here
+                String path = getPath();
+                if (path != null) {
+                    cache.put(PATH_KEY, path);
+                }
+                // only direct property
                 Iterator<String> pi = authorizable.getPropertyNames();
                 while (pi.hasNext()) {
                     String key = (String) pi.next();
@@ -311,10 +318,10 @@ public class AuthorizableValueMap implements ValueMap {
             }
 
         } catch (ValueFormatException vfe) {
-            logger.info("converToType: Cannot convert value of " + name
+            LOG.info("converToType: Cannot convert value of " + name
                 + " to " + type, vfe);
         } catch (RepositoryException re) {
-            logger.info("converToType: Cannot get value of " + name, re);
+            LOG.info("converToType: Cannot get value of " + name, re);
         }
 
         // fall back to nothing
@@ -396,7 +403,7 @@ public class AuthorizableValueMap implements ValueMap {
         return results.toArray(new String[results.size()]);
     }
 
-    private String[] getMemberships(Authorizable authorizable, boolean includeAll) throws RepositoryException {
+    private String[] getMemberships(boolean includeAll) throws RepositoryException {
         List<String> results = new ArrayList<String>();
         for (Iterator<Group> it = includeAll ? authorizable.memberOf() : authorizable.declaredMemberOf();
                 it.hasNext();) {
@@ -406,6 +413,15 @@ public class AuthorizableValueMap implements ValueMap {
         return results.toArray(new String[results.size()]);
     }
     
+    private String getPath() throws RepositoryException {
+        try {
+            return authorizable.getPath();
+        } catch (UnsupportedRepositoryOperationException e) {
+            LOG.debug("Could not retrieve path of authorizable {}", authorizable, e);
+            return null;
+        }
+    }
+
     public static class LazyInputStream extends InputStream {
 
         /** The JCR Value from which the input stream is requested on demand */

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.