incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r767847 - in /incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine: auth/Authenticator.java impl/auth/SlingAuthenticator.java
Date Thu, 23 Apr 2009 08:24:01 GMT
Author: fmeschbe
Date: Thu Apr 23 08:24:01 2009
New Revision: 767847

URL: http://svn.apache.org/viewvc?rev=767847&view=rev
Log:
SLING-938 Provide service method to initiate the authentication process

Added:
    incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/auth/Authenticator.java
  (with props)
Modified:
    incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/auth/SlingAuthenticator.java

Added: 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=767847&view=auto
==============================================================================
--- incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/auth/Authenticator.java
(added)
+++ incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/auth/Authenticator.java
Thu Apr 23 08:24:01 2009
@@ -0,0 +1,59 @@
+/*
+ * 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 javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * The <code>Authenticator</code> interface defines the service interface of
the
+ * authenticator used by the Sling engine. This service provides a method to
+ * find an {@link AuthenticationHandler} and call its
+ * {@link AuthenticationHandler#requestAuthentication(HttpServletRequest, HttpServletResponse)}
+ * method.
+ * <p>
+ * This interface is not intended to be implemented by applications but may be
+ * used to initiate the authentication process form a request processing servlet
+ * or script.
+ * 
+ * @since 2.0.4
+ */
+public interface Authenticator {
+
+    /**
+     * Finds an {@link AuthenticationHandler} for the given request and call its
+     * {@link AuthenticationHandler#requestAuthentication(HttpServletRequest, HttpServletResponse)}
+     * method to initiate an authentication process with the client to login to
+     * Sling.
+     * <p>
+     * This method must be called on an uncommitted response since the
+     * implementation may want to reset the response to start the authentication
+     * process with a clean response. If the response is already committed an
+     * <code>IllegalStateException</code> is thrown.
+     * <p>
+     * After this method has finished, request processing should be terminated
+     * and the response be considered committed and finished.
+     * 
+     * @param request The object representing the client request.
+     * @param response The object representing the response to the client.
+     * @throws IllegalStateException If the response has already been committed.
+     */
+    public void login(HttpServletRequest request, HttpServletResponse response);
+
+}

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

Propchange: incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/auth/Authenticator.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=767847&r1=767846&r2=767847&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
Thu Apr 23 08:24:01 2009
@@ -42,6 +42,7 @@
 import org.apache.sling.engine.EngineConstants;
 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.jcr.api.TooManySessionsException;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
@@ -76,7 +77,7 @@
  * @scr.property name="service.description" value="Sling Authenticator"
  * @scr.property name="service.vendor" value="The Apache Software Foundation"
  */
-public class SlingAuthenticator implements ManagedService {
+public class SlingAuthenticator implements ManagedService, Authenticator {
 
     /**
      * The name of the request attribute containing the AuthenticationHandler
@@ -161,8 +162,9 @@
         props.put(Constants.SERVICE_DESCRIPTION, "Sling Request Authenticator");
         props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
 
-        registration = bundleContext.registerService(
-            ManagedService.class.getName(), this, props);
+        registration = bundleContext.registerService(new String[] {
+            ManagedService.class.getName(), Authenticator.class.getName() },
+            this, props);
     }
 
     public void dispose() {
@@ -242,7 +244,7 @@
      * Requests authentication information from the client. Returns
      * <code>true</code> if the information has been requested and request
      * processing can be terminated. Otherwise the request information could not
-     * be requested and the request should be terminated with a 40x (Forbidden)
+     * be requested and the request should be terminated with a 403/FORBIDDEN
      * response.
      * <p>
      * Any response sent by the handler is also handled by the error handler
@@ -251,9 +253,13 @@
      * @param request The request object
      * @param response The response object to which to send the request
      */
-    public void requestAuthentication(HttpServletRequest request,
-            HttpServletResponse response) {
+    public void login(HttpServletRequest request, HttpServletResponse response) {
 
+        // ensure the response is not committed yet
+        if (response.isCommitted()) {
+            throw new IllegalStateException("Response already committed");
+        }
+        
         AuthenticationHandlerInfo[] handlerInfos = findApplicableAuthenticationHandlers(request);
         boolean done = false;
         for (int i = 0; !done && i < handlerInfos.length; i++) {
@@ -501,7 +507,7 @@
 
         // request authentication now, and fail if not possible
         log.debug("getAnonymousSession: Anonymous access not allowed by configuration");
-        requestAuthentication(req, res);
+        login(req, res);
 
         // fallback to no session
         return false;
@@ -529,7 +535,7 @@
             // if no handler can request authentication information.
             log.info("authenticate: Unable to authenticate: {}",
                 reason.getMessage());
-            requestAuthentication(request, response);
+            login(request, response);
 
         } else {
 



Mime
View raw message