sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1582271 - in /sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl: ./ mapping/
Date Thu, 27 Mar 2014 12:07:39 GMT
Author: cziegeler
Date: Thu Mar 27 12:07:38 2014
New Revision: 1582271

URL: http://svn.apache.org/r1582271
Log:
SLING-3043 : Allow regexp filtering of vanity paths

Modified:
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapConfigurationProvider.java
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java?rev=1582271&r1=1582270&r2=1582271&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
Thu Mar 27 12:07:38 2014
@@ -192,8 +192,12 @@ public class CommonResourceResolverFacto
     public boolean isVanityPathEnabled() {
         return this.activator.isVanityPathEnabled();
     }
-    
+
     public boolean isOptimizeAliasResolutionEnabled() {
         return this.activator.isOptimizeAliasResolutionEnabled();
     }
+
+    public String[] getVanityPathWhiteList() {
+        return this.activator.getVanityPathWhiteList();
+    }
 }
\ No newline at end of file

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java?rev=1582271&r1=1582270&r2=1582271&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java
Thu Mar 27 12:07:38 2014
@@ -193,6 +193,13 @@ public class ResourceResolverFactoryActi
                       " and on the alias update time if the number of aliases is huge (over
10000).")
     private static final String PROP_ENABLE_OPTIMIZE_ALIAS_RESOLUTION = "resource.resolver.optimize.alias.resolution";
 
+    @Property(unbounded=PropertyUnbounded.ARRAY,
+            label = "Vanity Path Prefix",
+            description ="This setting can contain a list of path prefixes, e.g. /libs/,
/content/. If " +
+                    "such a list is configured, only vanity paths from resources starting
with this prefix " +
+                    " are considered. if the list is empty, all vanity paths are used.")
+    private static final String PROP_VANITY_PATH_PREFIX = "resource.resolver.vanitypath.whitelist";
+
     /** Tracker for the resource decorators. */
     private final ResourceDecoratorTracker resourceDecoratorTracker = new ResourceDecoratorTracker();
 
@@ -239,6 +246,9 @@ public class ResourceResolverFactoryActi
     /** alias resource resolution optimization enabled? */
     private boolean enableOptimizeAliasResolution = DEFAULT_ENABLE_OPTIMIZE_ALIAS_RESOLUTION;
 
+    /** Vanity path whitelist */
+    private String[] vanityPathWhiteList;
+
     private final FactoryPreconditions preconds = new FactoryPreconditions();
 
     /** Factory registration. */
@@ -305,6 +315,10 @@ public class ResourceResolverFactoryActi
         return this.enableOptimizeAliasResolution;
     }
 
+    public String[] getVanityPathWhiteList() {
+        return this.vanityPathWhiteList;
+    }
+
     // ---------- SCR Integration ---------------------------------------------
 
     /** Activates this component, called by SCR before registering as a service */
@@ -368,6 +382,24 @@ public class ResourceResolverFactoryActi
         defaultVanityPathRedirectStatus = PropertiesUtil.toInteger(properties.get(PROP_DEFAULT_VANITY_PATH_REDIRECT_STATUS),
                                                                    MapEntries.DEFAULT_DEFAULT_VANITY_PATH_REDIRECT_STATUS);
         this.enableVanityPath = PropertiesUtil.toBoolean(properties.get(PROP_ENABLE_VANITY_PATH),
DEFAULT_ENABLE_VANITY_PATH);
+        // vanity path white list
+        this.vanityPathWhiteList = null;
+        final String[] vanityPathPrefixes = PropertiesUtil.toStringArray(properties.get(PROP_VANITY_PATH_PREFIX));
+        if ( vanityPathPrefixes != null ) {
+            final List<String> prefixList = new ArrayList<String>();
+            for(final String value : vanityPathPrefixes) {
+                if ( value.trim().length() > 0 ) {
+                    if ( value.trim().endsWith("/") ) {
+                        prefixList.add(value.trim());
+                    } else {
+                        prefixList.add(value.trim() + "/");
+                    }
+                }
+            }
+            if ( prefixList.size() > 0 ) {
+                this.vanityPathWhiteList = prefixList.toArray(new String[prefixList.size()]);
+            }
+        }
 
         this.enableOptimizeAliasResolution = PropertiesUtil.toBoolean(properties.get(PROP_ENABLE_OPTIMIZE_ALIAS_RESOLUTION),
DEFAULT_ENABLE_OPTIMIZE_ALIAS_RESOLUTION);
 

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapConfigurationProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapConfigurationProvider.java?rev=1582271&r1=1582270&r2=1582271&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapConfigurationProvider.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapConfigurationProvider.java
Thu Mar 27 12:07:38 2014
@@ -38,6 +38,12 @@ public interface MapConfigurationProvide
     int getDefaultVanityPathRedirectStatus();
 
     boolean isVanityPathEnabled();
-    
-    public boolean isOptimizeAliasResolutionEnabled();
+
+    boolean isOptimizeAliasResolutionEnabled();
+
+    /**
+     * A list of white list prefixes all ending with a slash.
+     * If <code>null</code> is returned, all paths are allowed.
+     */
+    String[] getVanityPathWhiteList();
 }

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java?rev=1582271&r1=1582270&r2=1582271&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
Thu Mar 27 12:07:38 2014
@@ -109,9 +109,11 @@ public class MapEntries implements Event
     private final ReentrantLock initializing = new ReentrantLock();
 
     private final boolean enabledVanityPaths;
-    
+
     private final boolean enableOptimizeAliasResolution;
 
+    private final String[] vanityPathWhiteList;
+
     @SuppressWarnings("unchecked")
     private MapEntries() {
         this.factory = null;
@@ -126,6 +128,7 @@ public class MapEntries implements Event
         this.eventAdmin = null;
         this.enabledVanityPaths = true;
         this.enableOptimizeAliasResolution = true;
+        this.vanityPathWhiteList = null;
     }
 
     @SuppressWarnings("unchecked")
@@ -135,6 +138,7 @@ public class MapEntries implements Event
         this.factory = factory;
         this.mapRoot = factory.getMapRoot();
         this.enabledVanityPaths = factory.isVanityPathEnabled();
+        this.vanityPathWhiteList = factory.getVanityPathWhiteList();
         this.enableOptimizeAliasResolution = factory.isOptimizeAliasResolutionEnabled();
         this.eventAdmin = eventAdmin;
 
@@ -220,17 +224,17 @@ public class MapEntries implements Event
             // sort global list and add to map
             Collections.sort(globalResolveMap);
             newResolveMapsMap.put(GLOBAL_LIST_KEY, globalResolveMap);
-            
+
             //optimization made in SLING-2521
             if (enableOptimizeAliasResolution){
                 final Map<String, Map<String, String>> aliasMap = this.loadAliases(resolver);
                 this.aliasMap = makeUnmodifiableMap(aliasMap);
-            }            
+            }
 
             this.vanityTargets = Collections.unmodifiableCollection(vanityTargets);
             this.resolveMapsMap = Collections.unmodifiableMap(newResolveMapsMap);
             this.mapMaps = Collections.unmodifiableSet(new TreeSet<MapEntry>(newMapMaps.values()));
- 
+
             sendChangeEvent();
 
         } catch (final Exception e) {
@@ -243,11 +247,11 @@ public class MapEntries implements Event
 
         }
     }
-    
+
     public boolean isOptimizeAliasResolutionEnabled(){
         return this.enableOptimizeAliasResolution;
     }
-    
+
 
     private <K1, K2, V> Map<K1, Map<K2, V>> makeUnmodifiableMap(final Map<K1,
Map<K2, V>> map) {
         final Map<K1, Map<K2, V>> newMap = new HashMap<K1, Map<K2, V>>();
@@ -585,6 +589,20 @@ public class MapEntries implements Event
                 continue;
             }
 
+            // check whitelist
+            if ( this.vanityPathWhiteList != null ) {
+                boolean allowed = false;
+                for(final String prefix : this.vanityPathWhiteList) {
+                    if ( resource.getPath().startsWith(prefix) ) {
+                        allowed = true;
+                        break;
+                    }
+                }
+                if ( !allowed ) {
+                    log.debug("loadVanityPaths: Ignoring as not in white list {}", resource);
+                    continue;
+                }
+            }
             // require properties
             final ValueMap props = resource.adaptTo(ValueMap.class);
             if (props == null) {



Mime
View raw message