incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1060359 - in /sling/trunk/bundles/engine/src/main: java/org/apache/sling/engine/ java/org/apache/sling/engine/impl/ java/org/apache/sling/engine/impl/filter/ resources/OSGI-INF/metatype/
Date Tue, 18 Jan 2011 13:22:35 GMT
Author: cziegeler
Date: Tue Jan 18 13:22:35 2011
New Revision: 1060359

URL: http://svn.apache.org/viewvc?rev=1060359&view=rev
Log:
SLING-1734 : Change semantics of filter service scope support

Modified:
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/EngineConstants.java
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/filter/ServletFilterManager.java
    sling/trunk/bundles/engine/src/main/resources/OSGI-INF/metatype/metatype.properties

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/EngineConstants.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/EngineConstants.java?rev=1060359&r1=1060358&r2=1060359&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/EngineConstants.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/EngineConstants.java
Tue Jan 18 13:22:35 2011
@@ -128,10 +128,34 @@ public class EngineConstants {
      * @see #FILTER_SCOPE_INCLUDE
      * @see #FILTER_SCOPE_REQUEST
      * @since 2.1, Sling Engine 2.2
+     * @deprecated Use {@link #SLING_FILTER_SCOPE} instead
      */
+    @Deprecated
     public static final String FILTER_SCOPE = "filter.scope";
 
     /**
+     * The name of the service registration property of a
+     * <code>java.servlet.Filter</code> service to be used as a filter by the
+     * {@link SlingRequestProcessor}.
+     * <p>
+     * The specification of the <code>sling.filter.scope</code> service registration
+     * property is required for a <code>javax.servlet.Filter</code> service to
+     * be used as a filter by the Sling Engine.
+     * <p>
+     * The <code>sling.filter.scope</code> registration property is expected
to be a
+     * scalar String, an array of Strings or a Vector of Strings. Case of the
+     * value is ignored.
+     *
+     * @see #FILTER_SCOPE_COMPONENT
+     * @see #FILTER_SCOPE_ERROR
+     * @see #FILTER_SCOPE_FORWARD
+     * @see #FILTER_SCOPE_INCLUDE
+     * @see #FILTER_SCOPE_REQUEST
+     * @since 2.1, Sling Engine 2.2
+     */
+    public static final String SLING_FILTER_SCOPE = "sling.filter.scope";
+
+    /**
      * Filter scope value identifying a component level filter.
      * <p>
      * Component level filters are called once at the beginning of each request
@@ -140,7 +164,7 @@ public class EngineConstants {
      * by the <code>service.ranking</code> (or {@link #FILTER_ORDER}) property
      * and the service registration ID.
      *
-     * @see #FILTER_SCOPE
+     * @see #SLING_FILTER_SCOPE
      * @since 2.1, Sling Engine 2.2
      */
     public static final String FILTER_SCOPE_COMPONENT = "COMPONENT";

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java?rev=1060359&r1=1060358&r2=1060359&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
Tue Jan 18 13:22:35 2011
@@ -93,6 +93,11 @@ public class SlingMainServlet extends Ge
     @Property(boolValue=DEFAULT_ALLOW_TRACE)
     public static final String PROP_ALLOW_TRACE = "sling.trace.allow";
 
+    public static final boolean DEFAULT_FILTER_COMPAT_MODE = false;
+
+    @Property(boolValue=DEFAULT_FILTER_COMPAT_MODE)
+    public static final String PROP_FILTER_COMPAT_MODE = "sling.filter.compat.mode";
+
     @Property(intValue = RequestHistoryConsolePlugin.STORED_REQUESTS_COUNT)
     private static final String PROP_MAX_RECORD_REQUESTS = "sling.max.record.requests";
 
@@ -306,7 +311,8 @@ public class SlingMainServlet extends Ge
         // the HttpService as filter initialization may cause the servlet
         // context to be required (see SLING-42)
         filterManager = new ServletFilterManager(bundleContext,
-            slingServletContext);
+            slingServletContext,
+            OsgiUtil.toBoolean(componentConfig.get(PROP_FILTER_COMPAT_MODE), DEFAULT_FILTER_COMPAT_MODE));
         filterManager.open();
         requestProcessor.setFilterManager(filterManager);
 

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/filter/ServletFilterManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/filter/ServletFilterManager.java?rev=1060359&r1=1060358&r2=1060359&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/filter/ServletFilterManager.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/filter/ServletFilterManager.java
Tue Jan 18 13:22:35 2011
@@ -99,8 +99,11 @@ public class ServletFilterManager extend
 
     private final SlingFilterChainHelper[] filterChains;
 
-    public ServletFilterManager(BundleContext context,
-            final SlingServletContext servletContext) {
+    private final boolean compatMode;
+
+    public ServletFilterManager(final BundleContext context,
+            final SlingServletContext servletContext,
+            final boolean compatMode) {
         super(context, FILTER_SERVICE_NAME, null);
         this.servletContext = servletContext;
         this.filterChains = new SlingFilterChainHelper[FilterChainType.values().length];
@@ -109,6 +112,7 @@ public class ServletFilterManager extend
         this.filterChains[FilterChainType.INCLUDE.ordinal()] = new SlingFilterChainHelper();
         this.filterChains[FilterChainType.FORWARD.ordinal()] = new SlingFilterChainHelper();
         this.filterChains[FilterChainType.COMPONENT.ordinal()] = new SlingFilterChainHelper();
+        this.compatMode = compatMode;
     }
 
     public SlingFilterChainHelper getFilterChain(final FilterChainType chain) {
@@ -146,13 +150,31 @@ public class ServletFilterManager extend
         super.removedService(reference, service);
     }
 
+    /**
+     * Check if the filter should be excluded.
+     */
+    private boolean excludeFilter(final ServiceReference reference) {
+        // if the service has a filter scope property, we include it
+        if ( reference.getProperty(EngineConstants.SLING_FILTER_SCOPE) != null
+             || reference.getProperty(EngineConstants.FILTER_SCOPE) != null ) {
+            return false;
+        }
+        // in compat mode we allow all filters not having the felix pattern prop!
+        if ( this.compatMode ) {
+            // Check if filter will be registered by Felix HttpService Whiteboard
+            if (reference.getProperty(FELIX_WHITEBOARD_PATTERN_PROPERTY) != null) {
+                return true;
+            }
+            return false;
+        }
+        return true;
+    }
+
     private void initFilter(final ServiceReference reference,
             final Filter filter) {
-        // Check if filter will be registered by Felix HttpService Whiteboard
-        if (reference.getProperty(FELIX_WHITEBOARD_PATTERN_PROPERTY) != null) {
+        if ( this.excludeFilter(reference) ) {
             return;
         }
-
         final String filterName = SlingFilterConfig.getName(reference);
         if (filterName == null) {
             log.error("initFilter: Missing name for filter {}", reference);
@@ -188,7 +210,11 @@ public class ServletFilterManager extend
 
                 // register by scope
                 String[] scopes = OsgiUtil.toStringArray(
-                    reference.getProperty(EngineConstants.FILTER_SCOPE), null);
+                        reference.getProperty(EngineConstants.SLING_FILTER_SCOPE), null);
+                if ( scopes == null ) {
+                    scopes = OsgiUtil.toStringArray(
+                        reference.getProperty(EngineConstants.FILTER_SCOPE), null);
+                }
                 if (scopes != null && scopes.length > 0) {
                     for (String scope : scopes) {
                         scope = scope.toUpperCase();

Modified: sling/trunk/bundles/engine/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1060359&r1=1060358&r2=1060359&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/resources/OSGI-INF/metatype/metatype.properties (original)
+++ sling/trunk/bundles/engine/src/main/resources/OSGI-INF/metatype/metatype.properties Tue
Jan 18 13:22:35 2011
@@ -50,6 +50,10 @@ sling.max.record.requests.description = 
  internally recorded for display on the "Recent Requests" Web Console page. If \
  this value is less than or equal to zero, no requests are internally kept. The \
  default value is 20. 
+sling.filter.compat.mode.name = Filter Compat Mode
+sling.filter.compat.mode.description = This switch controls the handling of \
+ servlet filters. By default only filters with a scope property are registered. \
+ In compat mode, the scope property is not required.
 
 #
 # Request Loggger Filter



Mime
View raw message