Author: fmeschbe
Date: Sun Apr 26 20:59:53 2009
New Revision: 768788

URL: http://svn.apache.org/viewvc?rev=768788&view=rev
Log:
SLING-938 Provide path value of service registration properties, which
triggered the AuthenticationHandler call for the AuthenticationHandler
to include this in handling decisions

Modified:
    
incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/RequestUtil.java
    
incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/auth/SlingAuthenticator.java

Modified: 
incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/RequestUtil.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/RequestUtil.java?rev=768788&r1=768787&r2=768788&view=diff
==============================================================================
--- 
incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/RequestUtil.java
 (original)
+++ 
incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/RequestUtil.java
 Sun Apr 26 20:59:53 2009
@@ -23,6 +23,7 @@
 import java.util.Map;
 
 import javax.servlet.Servlet;
+import javax.servlet.http.HttpServletRequest;
 
 public class RequestUtil {
 
@@ -134,4 +135,26 @@
 
         return name;
     }
+
+    /**
+     * Sets the named request attribute to the new value and returns the
+     * previous value.
+     * 
+     * @param request The request object whose attribute is to be set.
+     * @param name The name of the attribute to be set.
+     * @param value The new value of the attribute. If this is 
<code>null</code>
+     *            the attribte is actually removed from the request.
+     * @return The previous value of the named request attribute or
+     *         <code>null</code> if it was not set.
+     */
+    public static Object setRequestAttribute(HttpServletRequest request,
+            String name, Object value) {
+        Object oldValue = request.getAttribute(name);
+        if (value == null) {
+            request.removeAttribute(name);
+        } else {
+            request.setAttribute(name, value);
+        }
+        return oldValue;
+    }
 }

Modified: 
incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/auth/SlingAuthenticator.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/auth/SlingAuthenticator.java?rev=768788&r1=768787&r2=768788&view=diff
==============================================================================
--- 
incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/auth/SlingAuthenticator.java
 (original)
+++ 
incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/auth/SlingAuthenticator.java
 Sun Apr 26 20:59:53 2009
@@ -40,6 +40,7 @@
 
 import org.apache.sling.commons.osgi.OsgiUtil;
 import org.apache.sling.engine.EngineConstants;
+import org.apache.sling.engine.RequestUtil;
 import org.apache.sling.engine.auth.AuthenticationHandler;
 import org.apache.sling.engine.auth.AuthenticationInfo;
 import org.apache.sling.engine.auth.Authenticator;
@@ -262,6 +263,7 @@
                     "requestAuthentication: requesting authentication using 
handler: {}",
                     handlerInfos[i]);
 
+                Object oldPathAttr = RequestUtil.setRequestAttribute(request, 
AuthenticationHandler.PATH_PROPERTY, handlerInfos[i].fullPath);
                 try {
                     done = 
handlerInfos[i].handler.requestAuthentication(request, response);
                 } catch (IOException ioe) {
@@ -269,6 +271,8 @@
                         "requestAuthentication: Failed sending authentication 
request through handler "
                             + handlerInfos[i] + ", access forbidden", ioe);
                     done = true;
+                } finally {
+                    RequestUtil.setRequestAttribute(request, 
AuthenticationHandler.PATH_PROPERTY, oldPathAttr);
                 }
             }
         }
@@ -377,7 +381,8 @@
 
                         for(int m = 0; m < paths.length; m++) {
                             if ( paths[m] != null && paths[m].length() > 0 ) {
-                                String path = paths[m];
+                                String fullPath = paths[m];
+                                String path = fullPath;
                                 String host = "";
                                 String protocol = "";
 
@@ -403,7 +408,7 @@
                                     }
                                 }
 
-                                AuthenticationHandlerInfo newInfo = new 
AuthenticationHandlerInfo(path, host, protocol, handler);
+                                AuthenticationHandlerInfo newInfo = new 
AuthenticationHandlerInfo(fullPath, path, host, protocol, handler);
 
                                 Map<String, List<AuthenticationHandlerInfo>> 
byHostMap = byProtocolMap.get(protocol);
                                 if(byHostMap == null) {
@@ -469,10 +474,18 @@
         AuthenticationHandlerInfo[] local = 
findApplicableAuthenticationHandlers(request);
         for (int i = 0; i < local.length; i++) {
             if ( pathInfo.startsWith(local[i].path) ) {
-                final AuthenticationInfo authInfo = 
local[i].handler.authenticate(request,
-                    response);
-                if (authInfo != null) {
-                    return authInfo;
+                Object oldPathAttr = RequestUtil.setRequestAttribute(request,
+                    AuthenticationHandler.PATH_PROPERTY, local[i].fullPath);
+                try {
+                    final AuthenticationInfo authInfo = 
local[i].handler.authenticate(
+                        request, response);
+                    if (authInfo != null) {
+                        return authInfo;
+                    }
+                } finally {
+                    RequestUtil.setRequestAttribute(request,
+                        AuthenticationHandler.PATH_PROPERTY, oldPathAttr);
+
                 }
             }
         }
@@ -682,12 +695,14 @@
     }
 
     protected static final class AuthenticationHandlerInfo {
+        public final String fullPath;
         public final String path;
         public final String host;
         public final String protocol;
         public final AuthenticationHandler handler;
 
-        public AuthenticationHandlerInfo(final String p, final String host, 
final String protocol, final AuthenticationHandler h) {
+        public AuthenticationHandlerInfo(final String fullPath, final String 
p, final String host, final String protocol, final AuthenticationHandler h) {
+            this.fullPath = fullPath;
             this.path = p;
             this.host = host;
             this.protocol = protocol;


Reply via email to