Author: fmeschbe
Date: Fri Apr 24 18:56:25 2009
New Revision: 768396

URL: http://svn.apache.org/viewvc?rev=768396&view=rev
Log:
SLING-938 Add NoAuthenticationHandlerException to be thrown by login
if no AuthenticationHandler can handle the request to login

Added:
    
incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/auth/NoAuthenticationHandlerException.java
   (with props)
Modified:
    
incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/auth/Authenticator.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/auth/Authenticator.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/auth/Authenticator.java?rev=768396&r1=768395&r2=768396&view=diff
==============================================================================
--- 
incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/auth/Authenticator.java
 (original)
+++ 
incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/auth/Authenticator.java
 Fri Apr 24 18:56:25 2009
@@ -52,6 +52,8 @@
      * 
      * @param request The object representing the client request.
      * @param response The object representing the response to the client.
+     * @throws NoAuthenticationHandlerException If no authentication handler
+     *             claims responsibility to authenticate the request.
      * @throws IllegalStateException If the response has already been 
committed.
      */
     public void login(HttpServletRequest request, HttpServletResponse 
response);

Added: 
incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/auth/NoAuthenticationHandlerException.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/auth/NoAuthenticationHandlerException.java?rev=768396&view=auto
==============================================================================
--- 
incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/auth/NoAuthenticationHandlerException.java
 (added)
+++ 
incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/auth/NoAuthenticationHandlerException.java
 Fri Apr 24 18:56:25 2009
@@ -0,0 +1,41 @@
+/*
+ * 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.engine.auth;
+
+import org.apache.sling.api.SlingException;
+
+/**
+ * The <code>NoAuthenticationHandlerException</code> is thrown to indicate that
+ * there is no {...@link AuthenticationHandler} willing to handle the request.
+ * <p>
+ * This exception is thrown without a message. The caller of the
+ * {...@link Authenticator} method called is expected to immediately handle 
this
+ * exception and not to forward it up the call chain.
+ * <p>
+ * This exception is not intended to be thrown by client code but is used by 
the
+ * {...@link Authenticator} implementation to indicate, that no
+ * {...@link AuthenticationHandler} is available to login.
+ */
+public class NoAuthenticationHandlerException extends SlingException {
+
+    public NoAuthenticationHandlerException() {
+        super();
+    }
+
+}

Propchange: 
incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/auth/NoAuthenticationHandlerException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/auth/NoAuthenticationHandlerException.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url

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=768396&r1=768395&r2=768396&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
 Fri Apr 24 18:56:25 2009
@@ -43,6 +43,7 @@
 import org.apache.sling.engine.auth.AuthenticationHandler;
 import org.apache.sling.engine.auth.AuthenticationInfo;
 import org.apache.sling.engine.auth.Authenticator;
+import org.apache.sling.engine.auth.NoAuthenticationHandlerException;
 import org.apache.sling.jcr.api.TooManySessionsException;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
@@ -134,16 +135,6 @@
     /** Whether access without credentials is allowed */
     boolean anonymousAllowed;
 
-    /**
-     * The list of packages from the configuration file. This list is checked
-     * for each request. The handler of the first package match is used for the
-     * authentication.
-     */
-    // private AuthPackage[] packages;
-    /**
-     * The number of {...@link AuthPackage} elements in the {...@link 
#packages} list.
-     */
-    // private int numPackages;
     private ServiceRegistration registration;
 
     public SlingAuthenticator(BundleContext bundleContext) {
@@ -252,6 +243,9 @@
      *
      * @param request The request object
      * @param response The response object to which to send the request
+     * @throws IllegalStateException If response is already committed
+     * @throws NoAuthenticationHandlerException If no authentication handler
+     *             claims responsibility to authenticate the request.
      */
     public void login(HttpServletRequest request, HttpServletResponse 
response) {
 
@@ -279,13 +273,12 @@
             }
         }
 
-        if ( !done ) {
-            // no handler could send an authentication request, fail with 
FORBIDDEN
+        // no handler could send an authentication request, throw
+        if (!done) {
             log.info(
-                    "requestAuthentication: No handler for request, sending 
FORBIDDEN ({} handlers available)",
-                    handlerInfos.length
-            );
-            sendFailure(response);
+                "requestAuthentication: No handler for request ({} handlers 
available)",
+                handlerInfos.length);
+            throw new NoAuthenticationHandlerException();
         }
     }
 
@@ -553,16 +546,6 @@
 
     }
 
-    // TODO
-    private void sendFailure(HttpServletResponse res) {
-        try {
-            res.sendError(HttpServletResponse.SC_FORBIDDEN, "Access Denied");
-        } catch (IOException ioe) {
-            log.error("Cannot send error " + HttpServletResponse.SC_FORBIDDEN
-                + " code", ioe);
-        }
-    }
-
     /**
      * Sets the request attributes required by the OSGi HttpContext interface
      * specification for the <code>handleSecurity</code> method. In addition


Reply via email to