Author: cziegeler
Date: Mon Mar 10 14:31:48 2014
New Revision: 1575951

URL: http://svn.apache.org/r1575951
Log:
FELIX-3444 : Provide a switch to enable feature flags for the resource resolver

Added:
    
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/FeatureConstants.java
   (with props)
    
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/FeatureAuthenticationInfoPostProcessor.java
   (with props)
Modified:
    
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/FeaturesHolder.java
    
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceResolverContext.java

Added: 
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/FeatureConstants.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/FeatureConstants.java?rev=1575951&view=auto
==============================================================================
--- 
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/FeatureConstants.java
 (added)
+++ 
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/FeatureConstants.java
 Mon Mar 10 14:31:48 2014
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.featureflags;
+
+
+public abstract class FeatureConstants {
+
+    /**
+     * The name of the resource resolver attribute which is set if the
+     * feature flag support should be enabled in the resource resolver.
+     * The value of this property should be of type Boolean. The default
+     * is <code>false</code>
+     */
+    public static final String RESOLVER_ATTR_FEATURES_ENABLED = 
"sling.resourceresolver.feature";
+}

Propchange: 
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/FeatureConstants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/FeatureConstants.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: 
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/FeatureConstants.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/FeatureAuthenticationInfoPostProcessor.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/FeatureAuthenticationInfoPostProcessor.java?rev=1575951&view=auto
==============================================================================
--- 
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/FeatureAuthenticationInfoPostProcessor.java
 (added)
+++ 
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/FeatureAuthenticationInfoPostProcessor.java
 Mon Mar 10 14:31:48 2014
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.featureflags.impl;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.api.resource.LoginException;
+import org.apache.sling.auth.core.spi.AuthenticationInfo;
+import org.apache.sling.auth.core.spi.AuthenticationInfoPostProcessor;
+import org.apache.sling.featureflags.FeatureConstants;
+
+/**
+ * This authentication info post processor enables the feature flag support
+ * in the resource resolver for GET and HEAD requests.
+ */
+@Component
+@Service(value=AuthenticationInfoPostProcessor.class)
+public class FeatureAuthenticationInfoPostProcessor implements 
AuthenticationInfoPostProcessor {
+
+    /**
+     * @see 
org.apache.sling.auth.core.spi.AuthenticationInfoPostProcessor#postProcess(org.apache.sling.auth.core.spi.AuthenticationInfo,
 javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+     */
+    @Override
+    public void postProcess(final AuthenticationInfo info,
+            final HttpServletRequest request,
+            final HttpServletResponse response)
+    throws LoginException {
+        if ( "GET".equals(request.getMethod()) || 
"HEAD".equals(request.getMethod()) ) {
+            info.put(FeatureConstants.RESOLVER_ATTR_FEATURES_ENABLED, 
Boolean.TRUE);
+        }
+    }
+
+}

Propchange: 
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/FeatureAuthenticationInfoPostProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/FeatureAuthenticationInfoPostProcessor.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: 
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/FeatureAuthenticationInfoPostProcessor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/FeaturesHolder.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/FeaturesHolder.java?rev=1575951&r1=1575950&r2=1575951&view=diff
==============================================================================
--- 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/FeaturesHolder.java
 (original)
+++ 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/FeaturesHolder.java
 Mon Mar 10 14:31:48 2014
@@ -25,6 +25,14 @@ package org.apache.sling.resourceresolve
  */
 public interface FeaturesHolder {
 
+    /** This holder always returns null */
+    FeaturesHolder EMPTY_HOLDER = new FeaturesHolder() {
+
+        public Object getFeatures() {
+            return null;
+        }
+    };
+
     /**
      * @return The {@code Features} service if available, {@code null} 
otherwise
      */

Modified: 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceResolverContext.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceResolverContext.java?rev=1575951&r1=1575950&r2=1575951&view=diff
==============================================================================
--- 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceResolverContext.java
 (original)
+++ 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceResolverContext.java
 Mon Mar 10 14:31:48 2014
@@ -33,6 +33,7 @@ import org.apache.sling.api.resource.Res
 import org.apache.sling.api.resource.ResourceResolverFactory;
 import org.apache.sling.api.resource.ResourceUtil;
 import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.featureflags.FeatureConstants;
 import org.apache.sling.featureflags.Features;
 import org.apache.sling.resourceresolver.impl.ResourceAccessSecurityTracker;
 
@@ -88,7 +89,19 @@ public class ResourceResolverContext {
         this.isAdmin = isAdmin;
         this.originalAuthInfo = originalAuthInfo;
         this.resourceAccessSecurityTracker = resourceAccessSecurityTracker;
-        this.featuresHolder = featuresHolder;
+        // check if features are enabled
+        boolean featuresEnabled = false;
+        if ( originalAuthInfo != null ) {
+            final Object featuresEnabledAttr = 
originalAuthInfo.get(FeatureConstants.RESOLVER_ATTR_FEATURES_ENABLED);
+            if ( featuresEnabledAttr != null && featuresEnabledAttr instanceof 
Boolean ) {
+                featuresEnabled = (Boolean)featuresEnabledAttr;
+            }
+        }
+        if ( featuresEnabled ) {
+            this.featuresHolder = featuresHolder;
+        } else {
+            this.featuresHolder = FeaturesHolder.EMPTY_HOLDER;
+        }
     }
 
     /**


Reply via email to