SLING-4291 : NPE if optional prefix is not configured
authorCarsten Ziegeler <cziegeler@apache.org>
Fri, 9 Jan 2015 12:30:20 +0000 (12:30 +0000)
committerCarsten Ziegeler <cziegeler@apache.org>
Fri, 9 Jan 2015 12:30:20 +0000 (12:30 +0000)
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1650513 13f79535-47bb-0310-9956-ffa450edef68

src/main/java/org/apache/sling/jcr/resourcesecurity/impl/ResourceAccessGateFactory.java

index 4cfe4eb..a2171f7 100644 (file)
@@ -73,11 +73,8 @@ public class ResourceAccessGateFactory
     protected void activate(final Map<String, Object> props) {
         this.jcrPath = PropertiesUtil.toString(props.get(PROP_JCR_PATH), null);
         this.prefix = PropertiesUtil.toString(props.get(PROP_PREFIX), null);
-        if ( this.prefix != null ) {
-            if ( !this.prefix.endsWith("/") ) {
-                this.prefix = this.prefix + "/";
-            }
-            this.jcrPath = this.jcrPath + "/";
+        if ( this.prefix != null && !this.prefix.endsWith("/") ) {
+             this.prefix = this.prefix + "/";
         }
     }
 
@@ -92,7 +89,7 @@ public class ResourceAccessGateFactory
         if ( session != null ) {
             String checkPath = this.jcrPath;
             if ( this.prefix != null && path.startsWith(this.prefix) ) {
-                checkPath = this.jcrPath + path.substring(this.prefix.length());
+                checkPath = this.jcrPath + path.substring(this.prefix.length() - 1);
             }
             try {
                 granted = session.hasPermission(checkPath, permission);