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

cziegeler pushed a commit to branch issues/SLING-11742
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourceresolver.git


The following commit(s) were added to refs/heads/issues/SLING-11742 by this 
push:
     new c83fac5  Remove metatype info for old properties, move vanity path 
confiuguration to separate configurer
c83fac5 is described below

commit c83fac5f3859f392730cd3e2f92208f2f1970d60
Author: Carsten Ziegeler <cziege...@apache.org>
AuthorDate: Sat Jun 3 09:47:42 2023 +0200

    Remove metatype info for old properties, move vanity path confiuguration to 
separate configurer
---
 .../impl/CommonResourceResolverFactoryImpl.java    | 18 ++---
 .../impl/ResourceResolverFactoryActivator.java     | 80 +++++-----------------
 .../impl/ResourceResolverFactoryConfig.java        | 10 +--
 .../impl/VanityPathConfigurer.java                 | 63 +++++++++++++++++
 4 files changed, 92 insertions(+), 79 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
 
b/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
index 43d2683..db9185b 100644
--- 
a/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
+++ 
b/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
@@ -388,12 +388,12 @@ public class CommonResourceResolverFactoryImpl implements 
MapConfigurationProvid
 
     @Override
     public int getDefaultVanityPathRedirectStatus() {
-        return this.activator.getDefaultVanityPathRedirectStatus();
+        return 
this.activator.getVanityPathConfigurer().getDefaultVanityPathRedirectStatus();
     }
 
     @Override
     public boolean isVanityPathCacheInitInBackground() {
-        return this.activator.isVanityPathCacheInitInBackground();
+        return 
this.activator.getVanityPathConfigurer().isVanityPathCacheInitInBackground();
     }
 
    /**
@@ -415,22 +415,22 @@ public class CommonResourceResolverFactoryImpl implements 
MapConfigurationProvid
 
     @Override
     public boolean isVanityPathEnabled() {
-        return this.activator.isVanityPathEnabled();
+        return this.activator.getVanityPathConfigurer().isVanityPathEnabled();
     }
 
     @Override
     public long getMaxCachedVanityPathEntries() {
-        return this.activator.getMaxCachedVanityPathEntries();
+        return 
this.activator.getVanityPathConfigurer().getMaxCachedVanityPathEntries();
     }
 
     @Override
     public boolean isMaxCachedVanityPathEntriesStartup() {
-        return this.activator.isMaxCachedVanityPathEntriesStartup();
+        return 
this.activator.getVanityPathConfigurer().isMaxCachedVanityPathEntriesStartup();
     }
 
     @Override
     public int getVanityBloomFilterMaxBytes() {
-        return this.activator.getVanityBloomFilterMaxBytes();
+        return 
this.activator.getVanityPathConfigurer().getVanityBloomFilterMaxBytes();
     }
 
     @Override
@@ -440,7 +440,7 @@ public class CommonResourceResolverFactoryImpl implements 
MapConfigurationProvid
 
     @Override
     public boolean hasVanityPathPrecedence() {
-        return this.activator.hasVanityPathPrecedence();
+        return 
this.activator.getVanityPathConfigurer().hasVanityPathPrecedence();
     }
 
     @Override
@@ -450,8 +450,8 @@ public class CommonResourceResolverFactoryImpl implements 
MapConfigurationProvid
 
     @Override
     public List<VanityPathConfig> getVanityPathConfig() {
-        final String[] includes = this.activator.getVanityPathWhiteList();
-        final String[] excludes = this.activator.getVanityPathBlackList();
+        final String[] includes = 
this.activator.getVanityPathConfigurer().getVanityPathAllowList();
+        final String[] excludes = 
this.activator.getVanityPathConfigurer().getVanityPathDenyList();
         if ( includes == null && excludes == null ) {
             return null;
         }
diff --git 
a/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java
 
b/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java
index 43c07b8..f6de983 100644
--- 
a/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java
+++ 
b/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java
@@ -21,10 +21,17 @@ package org.apache.sling.resourceresolver.impl;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.TreeSet;
 
-
-import java.util.function.Consumer;
 import org.apache.commons.collections4.BidiMap;
 import org.apache.commons.collections4.bidimap.TreeBidiMap;
 import org.apache.commons.lang3.StringUtils;
@@ -40,7 +47,6 @@ import 
org.apache.sling.resourceresolver.impl.providers.ResourceProviderTracker;
 import 
org.apache.sling.resourceresolver.impl.providers.ResourceProviderTracker.ChangeListener;
 import org.apache.sling.resourceresolver.impl.providers.RuntimeServiceImpl;
 import org.apache.sling.serviceusermapping.ServiceUserMapper;
-import org.jetbrains.annotations.NotNull;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
@@ -70,7 +76,6 @@ import org.slf4j.LoggerFactory;
 @Component(name = 
"org.apache.sling.jcr.resource.internal.JcrResourceResolverFactoryImpl")
 public class ResourceResolverFactoryActivator {
 
-
     private static final class FactoryRegistration {
         /** Registration .*/
         public volatile ServiceRegistration<ResourceResolverFactory> 
factoryRegistration;
@@ -132,12 +137,6 @@ public class ResourceResolverFactoryActivator {
     @SuppressWarnings("java:S3077")
     private volatile Set<String> allowedAliasLocations = 
Collections.emptySet();
 
-    /** Vanity path whitelist */
-    private volatile String[] vanityPathWhiteList;
-
-    /** Vanity path blacklist */
-    private volatile String[] vanityPathBlackList;
-
     /** Observation paths */
     private volatile Path[] observationPaths;
 
@@ -147,6 +146,9 @@ public class ResourceResolverFactoryActivator {
     private volatile FactoryRegistration factoryRegistration;
 
     private final VanityPathConfigurer vanityPathConfigurer = new 
VanityPathConfigurer();
+    {
+        vanityPathConfigurer.setConfiguration(DEFAULT_CONFIG);
+    }
 
     /**
      * Get the resource decorator tracker.
@@ -203,18 +205,6 @@ public class ResourceResolverFactoryActivator {
                || path.startsWith(this.mapRootPrefix);
     }
 
-    public int getDefaultVanityPathRedirectStatus() {
-        return config.resource_resolver_default_vanity_redirect_status();
-    }
-
-    public boolean isVanityPathEnabled() {
-        return this.config.resource_resolver_enable_vanitypath();
-    }
-
-    public boolean isVanityPathCacheInitInBackground() {
-        return this.config.resource_resolver_vanitypath_cache_in_background();
-    }
-
     public boolean isOptimizeAliasResolutionEnabled() {
         return this.config.resource_resolver_optimize_alias_resolution();
     }
@@ -227,30 +217,6 @@ public class ResourceResolverFactoryActivator {
         return this.config.resource_resolver_log_unclosed();
     }
 
-    public String[] getVanityPathWhiteList() {
-        return this.vanityPathWhiteList;
-    }
-
-    public String[] getVanityPathBlackList() {
-        return this.vanityPathBlackList;
-    }
-
-    public boolean hasVanityPathPrecedence() {
-        return this.config.resource_resolver_vanity_precedence();
-    }
-
-    public long getMaxCachedVanityPathEntries() {
-        return this.config.resource_resolver_vanitypath_maxEntries();
-    }
-
-    public boolean isMaxCachedVanityPathEntriesStartup() {
-        return this.config.resource_resolver_vanitypath_maxEntries_startup();
-    }
-
-    public int getVanityBloomFilterMaxBytes() {
-        return this.config.resource_resolver_vanitypath_bloomfilter_maxBytes();
-    }
-
     public boolean shouldLogResourceResolverClosing() {
         return this.config.resource_resolver_log_closing();
     }
@@ -259,6 +225,10 @@ public class ResourceResolverFactoryActivator {
         return this.observationPaths;
     }
 
+    public VanityPathConfigurer getVanityPathConfigurer() {
+        return this.vanityPathConfigurer;
+    }
+
     // ---------- SCR Integration ---------------------------------------------
 
     /**
@@ -266,6 +236,7 @@ public class ResourceResolverFactoryActivator {
      */
     @Activate
     protected void activate(final BundleContext bundleContext, final 
ResourceResolverFactoryConfig config) {
+        this.vanityPathConfigurer.setConfiguration(config);
         this.bundleContext = bundleContext;
         this.config = config;
 
@@ -342,21 +313,6 @@ public class ResourceResolverFactoryActivator {
             }
         }
 
-        // vanity path white list
-        this.vanityPathWhiteList = null;
-        
vanityPathConfigurer.configureVanityPathPrefixes(config.resource_resolver_vanitypath_whitelist(),
-            config.resource_resolver_vanitypath_allowlist(),
-            "resource_resolver_vanitypath_whitelist",
-            "resource_resolver_vanitypath_allowlist",
-            filteredPrefixes -> this.vanityPathWhiteList = filteredPrefixes);
-        // vanity path black list
-        this.vanityPathBlackList = null;
-        
vanityPathConfigurer.configureVanityPathPrefixes(config.resource_resolver_vanitypath_blacklist(),
-            config.resource_resolver_vanitypath_denylist(),
-            "resource_resolver_vanitypath_blacklist",
-            "resource_resolver_vanitypath_denylist",
-            filteredPrefixes -> this.vanityPathBlackList = filteredPrefixes);
-
         // check for required property
         Set<String> requiredResourceProvidersLegacy = 
getStringSet(config.resource_resolver_required_providers());
         Set<String> requiredResourceProviderNames = 
getStringSet(config.resource_resolver_required_providernames());
diff --git 
a/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryConfig.java
 
b/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryConfig.java
index 89617c8..6146587 100644
--- 
a/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryConfig.java
+++ 
b/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryConfig.java
@@ -160,10 +160,7 @@ public @interface ResourceResolverFactoryConfig {
     String[] resource_resolver_allowed_alias_locations();
 
 
-    @AttributeDefinition(name = "Allowed Vanity Path Location",
-        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, we fallback to 
resource.resolver.vanitypath.allowlist.")
+    /** This is the deprecated fallback configuration for 
resource_resolver_vanitypath_allowlist() */
     String[] resource_resolver_vanitypath_whitelist();
 
     @AttributeDefinition(name = "Allowed Vanity Path Location",
@@ -172,10 +169,7 @@ public @interface ResourceResolverFactoryConfig {
             " are considered. If the list is empty, all vanity paths are 
used.")
     String[] resource_resolver_vanitypath_allowlist();
 
-    @AttributeDefinition(name = "Denied Vanity Path Location",
-        description ="This setting can contain a list of path prefixes, e.g. 
/misc/. If " +
-                    "such a list is configured,vanity paths from resources 
starting with this prefix " +
-                    " are not considered. If the list is empty, we fallback to 
resource.resolver.vanitypath.denylist.")
+    /** This is the deprecated fallback configuration for 
resource_resolver_vanitypath_denylist() */
     String[] resource_resolver_vanitypath_blacklist();
 
     @AttributeDefinition(name = "Denied Vanity Path Location",
diff --git 
a/src/main/java/org/apache/sling/resourceresolver/impl/VanityPathConfigurer.java
 
b/src/main/java/org/apache/sling/resourceresolver/impl/VanityPathConfigurer.java
index 8d3d4e6..1f28f92 100644
--- 
a/src/main/java/org/apache/sling/resourceresolver/impl/VanityPathConfigurer.java
+++ 
b/src/main/java/org/apache/sling/resourceresolver/impl/VanityPathConfigurer.java
@@ -28,6 +28,69 @@ import org.slf4j.LoggerFactory;
 class VanityPathConfigurer {
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
+    private volatile ResourceResolverFactoryConfig config;
+
+    /** Vanity path allow list */
+    private volatile String[] vanityPathAllowList;
+
+    /** Vanity path deny list */
+    private volatile String[] vanityPathDenyList;
+
+    public void setConfiguration(final ResourceResolverFactoryConfig c) {
+        this.config = c;
+        // vanity path white list
+        this.vanityPathAllowList = null;
+        
this.configureVanityPathPrefixes(config.resource_resolver_vanitypath_whitelist(),
+            config.resource_resolver_vanitypath_allowlist(),
+            "resource_resolver_vanitypath_whitelist",
+            "resource_resolver_vanitypath_allowlist",
+            filteredPrefixes -> this.vanityPathAllowList = filteredPrefixes);
+        // vanity path black list
+        this.vanityPathDenyList = null;
+        
this.configureVanityPathPrefixes(config.resource_resolver_vanitypath_blacklist(),
+            config.resource_resolver_vanitypath_denylist(),
+            "resource_resolver_vanitypath_blacklist",
+            "resource_resolver_vanitypath_denylist",
+            filteredPrefixes -> this.vanityPathDenyList = filteredPrefixes);
+
+    }
+
+    public int getDefaultVanityPathRedirectStatus() {
+        return config.resource_resolver_default_vanity_redirect_status();
+    }
+
+    public boolean isVanityPathEnabled() {
+        return this.config.resource_resolver_enable_vanitypath();
+    }
+
+    public boolean isVanityPathCacheInitInBackground() {
+        return this.config.resource_resolver_vanitypath_cache_in_background();
+    }
+
+    public String[] getVanityPathAllowList() {
+        return this.vanityPathAllowList;
+    }
+
+    public String[] getVanityPathDenyList() {
+        return this.vanityPathDenyList;
+    }
+
+    public boolean hasVanityPathPrecedence() {
+        return this.config.resource_resolver_vanity_precedence();
+    }
+
+    public long getMaxCachedVanityPathEntries() {
+        return this.config.resource_resolver_vanitypath_maxEntries();
+    }
+
+    public boolean isMaxCachedVanityPathEntriesStartup() {
+        return this.config.resource_resolver_vanitypath_maxEntries_startup();
+    }
+
+    public int getVanityBloomFilterMaxBytes() {
+        return this.config.resource_resolver_vanitypath_bloomfilter_maxBytes();
+    }
+
     void configureVanityPathPrefixes(String[] pathPrefixes, String[] 
pathPrefixesFallback,
                                      String pathPrefixesPropertyName, String 
pathPrefixesFallbackPropertyName,
                                      Consumer<String[]> 
filteredPathPrefixesConsumer) {

Reply via email to