incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r896345 [1/3] - in /sling/trunk/bundles/commons/auth: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/sling/ src/main/java/org/apache/sling/commons/ src/main/java/org/apache/sling/commo...
Date Wed, 06 Jan 2010 07:55:12 GMT
Author: fmeschbe
Date: Wed Jan  6 07:55:01 2010
New Revision: 896345

URL: http://svn.apache.org/viewvc?rev=896345&view=rev
Log:
SLING-966 Commit first shot at Commons Auth bundle

Added:
    sling/trunk/bundles/commons/auth/   (with props)
    sling/trunk/bundles/commons/auth/pom.xml   (with props)
    sling/trunk/bundles/commons/auth/src/
    sling/trunk/bundles/commons/auth/src/main/
    sling/trunk/bundles/commons/auth/src/main/java/
    sling/trunk/bundles/commons/auth/src/main/java/org/
    sling/trunk/bundles/commons/auth/src/main/java/org/apache/
    sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/
    sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/
    sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/
    sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/AuthenticationSupport.java   (with props)
    sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/Authenticator.java   (with props)
    sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/NoAuthenticationHandlerException.java   (with props)
    sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/
    sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/AbstractAuthenticationHandlerHolder.java   (with props)
    sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/AuthenticationHandlerHolder.java   (with props)
    sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/AuthenticationRequirementHolder.java   (with props)
    sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/AuthenticatorWebConsolePlugin.java   (with props)
    sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/LoginServlet.java   (with props)
    sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/LogoutServlet.java   (with props)
    sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/PathBasedHolder.java   (with props)
    sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/PathBasedHolderCache.java   (with props)
    sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/SlingAuthenticator.java   (with props)
    sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/engine/
    sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/engine/EngineAuthenticationHandlerHolder.java   (with props)
    sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/engine/EngineSlingAuthenticator.java   (with props)
    sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/spi/
    sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/spi/AuthenticationHandler.java   (with props)
    sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/spi/AuthenticationInfo.java   (with props)
    sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/engine/
    sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/engine/auth/
    sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/engine/auth/AuthenticationHandler.java   (with props)
    sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/engine/auth/AuthenticationInfo.java   (with props)
    sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/engine/auth/Authenticator.java   (with props)
    sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/engine/auth/NoAuthenticationHandlerException.java   (with props)
    sling/trunk/bundles/commons/auth/src/main/resources/
    sling/trunk/bundles/commons/auth/src/main/resources/OSGI-INF/
    sling/trunk/bundles/commons/auth/src/main/resources/OSGI-INF/metatype/
    sling/trunk/bundles/commons/auth/src/main/resources/OSGI-INF/metatype/metatype.properties   (with props)

Propchange: sling/trunk/bundles/commons/auth/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Jan  6 07:55:01 2010
@@ -0,0 +1,4 @@
+.classpath
+.project
+target
+.settings

Added: sling/trunk/bundles/commons/auth/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/auth/pom.xml?rev=896345&view=auto
==============================================================================
--- sling/trunk/bundles/commons/auth/pom.xml (added)
+++ sling/trunk/bundles/commons/auth/pom.xml Wed Jan  6 07:55:01 2010
@@ -0,0 +1,136 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+  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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.sling</groupId>
+        <artifactId>sling</artifactId>
+        <version>8</version>
+        <relativePath>../../parent/pom.xml</relativePath>
+    </parent>
+
+    <artifactId>org.apache.sling.commons.auth</artifactId>
+    <packaging>bundle</packaging>
+    <version>0.9.0-SNAPSHOT</version>
+
+    <name>Apache Sling Authentication Service</name>
+    <description>
+        The Sling Authentication Service bundle provides the basic
+        mechanisms to authenticate HTTP requests with a JCR repository.
+        The algorithms for extracting authentication details from the
+        requests is extensible by implementing an AuthenticationHandler
+        interface.
+    </description>
+
+    <scm>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/commons/auth</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/commons/auth</developerConnection>
+        <url>http://svn.apache.org/viewvc/sling/trunk/bundles/commons/auth</url>
+    </scm>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-scr-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Export-Package>
+                            org.apache.sling.commons.auth;version=1.0.0,
+                            org.apache.sling.commons.auth.spi;version=1.0.0,
+                            org.apache.sling.engine.auth;version=2.0.6
+                        </Export-Package>
+                        <Private-Package>
+                            org.apache.sling.commons.auth.impl.*
+                        </Private-Package>
+                        <Embed-Dependency>
+                            org.apache.sling.commons.osgi;inline=org/apache/sling/commons/osgi/OsgiUtil.class
+                        </Embed-Dependency>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+    <reporting>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-javadoc-plugin</artifactId>
+                <configuration>
+                    <excludePackageNames>
+                        org.apache.sling.engine.impl
+                    </excludePackageNames>
+                </configuration>
+            </plugin>
+        </plugins>
+    </reporting>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.api</artifactId>
+            <version>2.0.4-incubator</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.jcr.api</artifactId>
+            <version>2.0.2-incubator</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.jcr.resource</artifactId>
+            <version>2.0.4-incubator</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.commons.osgi</artifactId>
+            <version>2.0.2-incubator</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+        </dependency>
+    </dependencies>
+</project>

Propchange: sling/trunk/bundles/commons/auth/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/AuthenticationSupport.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/AuthenticationSupport.java?rev=896345&view=auto
==============================================================================
--- sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/AuthenticationSupport.java (added)
+++ sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/AuthenticationSupport.java Wed Jan  6 07:55:01 2010
@@ -0,0 +1,103 @@
+/*
+ * 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.commons.auth;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * The <code>AuthenticationSupport</code> provides the service API used to
+ * implement the <code>HttpContext.handleSecurity</code> method as defined in
+ * the OSGi Http Service specification.
+ * <p>
+ * Bundles registering servlets and/or resources with custom
+ * <code>HttpContext</code> implementations may implement the
+ * <code>handleSecurity</code> method using this service. The
+ * {@link #handleSecurity(HttpServletRequest, HttpServletResponse)} method
+ * implemented by this service exactly implements the specification of the
+ * <code>HttpContext.handleSecurity</code> method.
+ * <p>
+ * A simple implementation of the <code>HttpContext</code> interface based on
+ * this could be (using SCR JavaDoc tags of the Maven SCR Plugin) :
+ * <pre>
+ * &#47;** &#64;scr.component *&#47;
+ * public class MyHttpContext implements HttpContext {
+ *     &#47;** &#64;scr.reference *&#47;
+ *     private AuthenticationSupport authSupport;
+ *
+ *     &#47;** &#64;scr.reference *&#47;
+ *     private MimeTypeService mimeTypes;
+ *
+ *     public boolean handleSecurity(HttpServletRequest request,
+ *             HttpServletResponse response) {
+ *         return authSupport.handleSecurity(request, response);
+ *     }
+ *
+ *     public URL getResource(String name) {
+ *         return null;
+ *     }
+ *
+ *     public String getMimeType(String name) {
+ *         return mimeTypes.getMimeType(name);
+ *     }
+ * }
+ * </pre>
+ * <p>
+ * This interface is implemented by this bundle and is not intended to be
+ * implemented by client bundles.
+ */
+public interface AuthenticationSupport {
+
+    /**
+     * The name under which this service is registered.
+     */
+    static final String SERVICE_NAME = "org.apache.sling.commons.auth.AuthenticationSupport";
+
+    /**
+     * The name of the request attribute set by the
+     * {@link #handleSecurity(HttpServletRequest, HttpServletResponse)} method
+     * if authentication succeeds and <code>true</code> is returned.
+     * <p>
+     * The request attribute is set to a Sling <code>ResourceResolver</code>
+     * attached to the JCR repository using the credentials provided by the
+     * request.
+     */
+    static final String REQUEST_ATTRIBUTE_RESOLVER = "org.apache.sling.commons.auth.ResourceResolver";
+
+    /**
+     * Handles security on behalf of a custom OSGi Http Service
+     * <code>HttpContext</code> instance extracting credentials from the request
+     * using any registered
+     * {@link org.apache.sling.commons.auth.spi.AuthenticationHandler} services.
+     * If the credentials can be extracted and used to log into the JCR
+     * repository this method sets the request attributes required by the OSGi
+     * Http Service specification plus the {@link #REQUEST_ATTRIBUTE_RESOLVER}
+     * attribute.
+     *
+     * @param request The HTTP request to be authenticated
+     * @param response The HTTP response to send any response to in case of
+     *            problems.
+     * @return <code>true</code> if authentication succeeded and the request
+     *         attribtues are set. If <code>false</code> is returned the request
+     *         is immediately terminated and no request attributes are set.
+     */
+    boolean handleSecurity(HttpServletRequest request,
+            HttpServletResponse response);
+
+}

Propchange: sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/AuthenticationSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/Authenticator.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/Authenticator.java?rev=896345&view=auto
==============================================================================
--- sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/Authenticator.java (added)
+++ sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/Authenticator.java Wed Jan  6 07:55:01 2010
@@ -0,0 +1,136 @@
+/*
+ * 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.commons.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 org.apache.sling.commons.auth.spi.AuthenticationHandler
+ * AuthenticationHandler} and call its
+ * {@link org.apache.sling.commons.auth.spi.AuthenticationHandler#requestAuthentication(HttpServletRequest, HttpServletResponse)
+ * requestAuthentication} or
+ * {@link org.apache.sling.commons.auth.spi.AuthenticationHandler#dropAuthentication(HttpServletRequest, HttpServletResponse)
+ * dropAuthentication} methods.
+ * <p>
+ * This service is used by applications which want to provide functionality to
+ * their users to log into the application and log out from it.
+ * <p>
+ * A very simple login script (using ESP here) could be implemented like this:
+ *
+ * <pre>
+ * var auth = sling.getService(org.apache.sling.commons.auth.Authenticator);
+ * if (auth != null) {
+ *     try {
+ *         auth.login(request, response);
+ *         return; // we are done here
+ *     } catch (e) {
+ *         // probably no AuthenticationHandler available
+ *     }
+ * }
+ * // Authenticator service is missing or no AuthenticationHandler
+ * ... do whatever you want to for error handling ...
+ * </pre>
+ * <p>
+ * Likewise implementing a logout script (ESP, too) is equally simple:
+ *
+ * <pre>
+ * if (request.authType) {
+ *     // not logged in at all, no need to logout
+ * } else {
+ *     var auth = sling.getService(org.apache.sling.commons.auth.Authenticator);
+ *     if (auth != null) {
+ *         auth.logout(request, response);
+ *     } else {
+ *         // handle the case of no Authenticator to logout with
+ *     }
+ * }
+ * </pre>
+ * <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.
+ */
+public interface Authenticator {
+
+    /**
+     * The name under which this service is registered.
+     */
+    static final String SERVICE_NAME = "org.apache.sling.commons.auth.Authenticator";
+
+    /**
+     * Name of the request attribute used by the
+     * {@link #login(HttpServletRequest, HttpServletResponse)} method to select
+     * an {@link org.apache.sling.commons.auth.spi.AuthenticationHandler} to
+     * call. If this request attribute is not set or is the empty string, the
+     * request path info ( <code>HttpServletRequest.getPathInfo()</code>) method
+     * is used to get the path.
+     * <p>
+     * This request attribute can be used by frontend servlets/scripts which
+     * call into {@link #login(HttpServletRequest, HttpServletResponse)} on
+     * behalf of users.
+     */
+    static final String LOGIN_RESOURCE = "resource";
+
+    /**
+     * Finds an {@link org.apache.sling.commons.auth.spi.AuthenticationHandler}
+     * for the given request and call its
+     * {@link org.apache.sling.commons.auth.spi.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 NoAuthenticationHandlerException If no authentication handler
+     *             claims responsibility to authenticate the request.
+     * @throws IllegalStateException If the response has already been committed.
+     */
+    void login(HttpServletRequest request, HttpServletResponse response);
+
+    /**
+     * Finds an {@link org.apache.sling.commons.auth.spi.AuthenticationHandler}
+     * for the given request and call its
+     * {@link org.apache.sling.commons.auth.spi.AuthenticationHandler#dropAuthentication(HttpServletRequest, HttpServletResponse)}
+     * method to drop authentication credentials for the client to logout from
+     * Sling.
+     * <p>
+     * This method must be called on an uncommitted response since the
+     * implementation may want to reset the response to restart 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.
+     */
+    void logout(HttpServletRequest request, HttpServletResponse response);
+}

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

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

Added: sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/NoAuthenticationHandlerException.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/NoAuthenticationHandlerException.java?rev=896345&view=auto
==============================================================================
--- sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/NoAuthenticationHandlerException.java (added)
+++ sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/NoAuthenticationHandlerException.java Wed Jan  6 07:55:01 2010
@@ -0,0 +1,44 @@
+/*
+ * 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.commons.auth;
+
+import org.apache.sling.api.SlingException;
+
+/**
+ * The <code>NoAuthenticationHandlerException</code> is thrown to indicate that
+ * there is no {@link org.apache.sling.commons.auth.spi.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 org.apache.sling.commons.auth.spi.AuthenticationHandler} is available
+ * to login.
+ */
+@SuppressWarnings("serial")
+public class NoAuthenticationHandlerException extends SlingException {
+
+    public NoAuthenticationHandlerException() {
+        super();
+    }
+
+}

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

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

Added: sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/AbstractAuthenticationHandlerHolder.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/AbstractAuthenticationHandlerHolder.java?rev=896345&view=auto
==============================================================================
--- sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/AbstractAuthenticationHandlerHolder.java (added)
+++ sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/AbstractAuthenticationHandlerHolder.java Wed Jan  6 07:55:01 2010
@@ -0,0 +1,110 @@
+/*
+ * 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.commons.auth.impl;
+
+import java.io.IOException;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.sling.commons.auth.spi.AuthenticationHandler;
+import org.apache.sling.commons.auth.spi.AuthenticationInfo;
+
+/**
+ * The <code>AuthenticationHandlerHolder</code> class represents an
+ * authentication handler service in the internal data structure of the
+ * {@link SlingAuthenticator}.
+ *
+ * @since 2.1
+ */
+public abstract class AbstractAuthenticationHandlerHolder extends PathBasedHolder implements AuthenticationHandler {
+
+    protected AbstractAuthenticationHandlerHolder(final String fullPath) {
+        super(fullPath);
+    }
+
+    protected abstract AuthenticationInfo doAuthenticate(HttpServletRequest request,
+            HttpServletResponse response);
+
+    public final AuthenticationInfo authenticate(HttpServletRequest request,
+            HttpServletResponse response) {
+
+        final Object oldPathAttr = setPath(request);
+        try {
+            return doAuthenticate(request, response);
+        } finally {
+            resetPath(request, oldPathAttr);
+        }
+
+    }
+
+    protected abstract boolean doRequestAuthentication(HttpServletRequest request,
+            HttpServletResponse response) throws IOException;
+
+    public final boolean requestAuthentication(HttpServletRequest request,
+            HttpServletResponse response) throws IOException {
+        final Object oldPathAttr = setPath(request);
+        try {
+            return doRequestAuthentication(request, response);
+        } finally {
+            resetPath(request, oldPathAttr);
+        }
+    }
+
+    protected abstract void doDropAuthentication(HttpServletRequest request,
+            HttpServletResponse response) throws IOException;
+
+    public final void dropAuthentication(HttpServletRequest request,
+            HttpServletResponse response) throws IOException {
+        doDropAuthentication(request, response);
+    }
+
+    private Object setPath(final HttpServletRequest request) {
+        return setRequestAttribute(request,
+            AuthenticationHandler.PATH_PROPERTY, fullPath);
+    }
+
+    private void resetPath(final HttpServletRequest request, Object oldValue) {
+        setRequestAttribute(request, AuthenticationHandler.PATH_PROPERTY,
+            oldValue);
+    }
+
+    /**
+     * 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.
+     */
+    private 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;
+    }
+
+}
\ No newline at end of file

Propchange: sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/AbstractAuthenticationHandlerHolder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/AbstractAuthenticationHandlerHolder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url

Added: sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/AuthenticationHandlerHolder.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/AuthenticationHandlerHolder.java?rev=896345&view=auto
==============================================================================
--- sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/AuthenticationHandlerHolder.java (added)
+++ sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/AuthenticationHandlerHolder.java Wed Jan  6 07:55:01 2010
@@ -0,0 +1,87 @@
+/*
+ * 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.commons.auth.impl;
+
+import java.io.IOException;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.sling.commons.auth.spi.AuthenticationHandler;
+import org.apache.sling.commons.auth.spi.AuthenticationInfo;
+
+/**
+ * The <code>AuthenticationHandlerHolder</code> class represents an
+ * authentication handler service in the internal data structure of the
+ * {@link SlingAuthenticator}.
+ *
+ * @since 2.1
+ */
+final class AuthenticationHandlerHolder extends
+        AbstractAuthenticationHandlerHolder {
+
+    // the actual authentication handler
+    private final AuthenticationHandler handler;
+
+    AuthenticationHandlerHolder(final String fullPath,
+            final AuthenticationHandler handler) {
+        super(fullPath);
+
+        // assign the fields
+        this.handler = handler;
+    }
+
+    public AuthenticationInfo doAuthenticate(HttpServletRequest request,
+            HttpServletResponse response) {
+
+        return handler.authenticate(request, response);
+
+    }
+
+    public boolean doRequestAuthentication(HttpServletRequest request,
+            HttpServletResponse response) throws IOException {
+        return handler.requestAuthentication(request, response);
+    }
+
+    public void doDropAuthentication(HttpServletRequest request,
+            HttpServletResponse response) throws IOException {
+        handler.dropAuthentication(request, response);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+
+        // equality is the base class equality (based on the fullpath)
+        // and the encapsulated holders being the same.
+        if (super.equals(obj)) {
+            if (obj.getClass() == getClass()) {
+                AuthenticationHandlerHolder other = (AuthenticationHandlerHolder) obj;
+                return other.handler == handler;
+            }
+        }
+
+        // handlers are not the same, so the holders are not the same
+        return false;
+    }
+
+    @Override
+    public String toString() {
+        return handler.toString();
+    }
+}
\ No newline at end of file

Propchange: sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/AuthenticationHandlerHolder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/AuthenticationHandlerHolder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url

Added: sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/AuthenticationRequirementHolder.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/AuthenticationRequirementHolder.java?rev=896345&view=auto
==============================================================================
--- sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/AuthenticationRequirementHolder.java (added)
+++ sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/AuthenticationRequirementHolder.java Wed Jan  6 07:55:01 2010
@@ -0,0 +1,56 @@
+/*
+ * 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.commons.auth.impl;
+
+public class AuthenticationRequirementHolder extends PathBasedHolder {
+
+    private final boolean requiresAuthentication;
+
+    static AuthenticationRequirementHolder fromConfig(final String config) {
+        if (config == null || config.length() == 0) {
+            throw new IllegalArgumentException(
+                "Configuration must not be null or empty");
+        }
+
+        final boolean required;
+        final String path;
+        if (config.startsWith("+")) {
+            required = true;
+            path = config.substring(1);
+        } else if (config.startsWith("-")) {
+            required = false;
+            path = config.substring(1);
+        } else {
+            required = true;
+            path = config;
+        }
+
+        return new AuthenticationRequirementHolder(path, required);
+    }
+
+    protected AuthenticationRequirementHolder(final String fullPath,
+            final boolean requiresAuthentication) {
+        super(fullPath);
+        this.requiresAuthentication = requiresAuthentication;
+    }
+
+    public boolean requiresAuthentication() {
+        return requiresAuthentication;
+    }
+}

Propchange: sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/AuthenticationRequirementHolder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/AuthenticationRequirementHolder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url

Added: sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/AuthenticatorWebConsolePlugin.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/AuthenticatorWebConsolePlugin.java?rev=896345&view=auto
==============================================================================
--- sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/AuthenticatorWebConsolePlugin.java (added)
+++ sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/AuthenticatorWebConsolePlugin.java Wed Jan  6 07:55:01 2010
@@ -0,0 +1,116 @@
+/*
+ * 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.commons.auth.impl;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+@SuppressWarnings("serial")
+public class AuthenticatorWebConsolePlugin extends HttpServlet {
+
+    private final SlingAuthenticator slingAuthenticator;
+
+    String getLabel() {
+        return "slingauth";
+    }
+
+    String getTitle() {
+        return "Authenticator";
+    }
+
+    public AuthenticatorWebConsolePlugin(
+            final SlingAuthenticator slingAuthenticator) {
+        this.slingAuthenticator = slingAuthenticator;
+    }
+
+    @Override
+    protected void service(HttpServletRequest req, HttpServletResponse resp)
+            throws ServletException, IOException {
+        // only handle GET requests, ensure no error message for other requests
+        if ("GET".equals(req.getMethod()) || "HEAD".equals(req.getMethod())) {
+            super.service(req, resp);
+        }
+    }
+
+    @Override
+    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+            throws IOException {
+
+        PrintWriter pw = resp.getWriter();
+
+        pw.println("<table class='content' width='100%' cellspacing='0' cellpadding='0'>");
+
+        printAuthenticationHandler(pw);
+
+        pw.println("<tr><td colspan='2'>&nbsp;</td></tr>");
+
+        printAuthenticationRequirements(pw);
+
+        pw.println("</table>");
+    }
+
+    private void printAuthenticationHandler(PrintWriter pw) {
+        pw.println("<tr>");
+        pw.println("<th class='content container' colspan='2'>Registered Authentication Handler</td>");
+        pw.println("</tr>");
+        pw.println("<tr>");
+        pw.println("<th class='content'>Path</td>");
+        pw.println("<th class='content'>Handler</td>");
+        pw.println("</tr>");
+
+        ArrayList<AbstractAuthenticationHandlerHolder> holderList = slingAuthenticator.getAuthenticationHandler();
+        for (AbstractAuthenticationHandlerHolder handler : holderList) {
+
+            pw.println("<tr class='content'>");
+            pw.println("<td class='content'>" + handler.fullPath + "</td>");
+            pw.println("<td class='content'>" + handler + "</td>");
+            pw.println("</tr>");
+
+        }
+    }
+
+    private void printAuthenticationRequirements(PrintWriter pw) {
+        pw.println("<tr>");
+        pw.println("<th class='content container' colspan='2'>Authentication Requirement Configuration</td>");
+        pw.println("</tr>");
+        pw.println("<tr>");
+        pw.println("<th class='content'>Path</td>");
+        pw.println("<th class='content'>Authentication Required</td>");
+        pw.println("</tr>");
+
+        ArrayList<AuthenticationRequirementHolder> holderList = slingAuthenticator.getAuthenticationRequirements();
+        for (AuthenticationRequirementHolder req : holderList) {
+
+            pw.println("<tr class='content'>");
+            pw.println("<td class='content'>" + req.fullPath + "</td>");
+            pw.println("<td class='content'>"
+                + (req.requiresAuthentication() ? "Yes" : "No") + "</td>");
+            pw.println("</tr>");
+
+        }
+
+    }
+
+}

Propchange: sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/AuthenticatorWebConsolePlugin.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/AuthenticatorWebConsolePlugin.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url

Added: sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/LoginServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/LoginServlet.java?rev=896345&view=auto
==============================================================================
--- sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/LoginServlet.java (added)
+++ sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/LoginServlet.java Wed Jan  6 07:55:01 2010
@@ -0,0 +1,130 @@
+/*
+ * 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.commons.auth.impl;
+
+import java.io.IOException;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.servlets.SlingAllMethodsServlet;
+import org.apache.sling.commons.auth.Authenticator;
+import org.apache.sling.commons.auth.NoAuthenticationHandlerException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The <code>LoginServlet</code> lets the Authenticator do the login.
+ *
+ * @scr.component metatype="no"
+ * @scr.service interface="javax.servlet.Servlet"
+ * @scr.property name="service.description" value="Authenticator Login Servlet"
+ * @scr.property name="service.vendor" value="The Apache Software Foundation"
+ * @scr.property name="sling.servlet.methods" values.0="GET" values.1="POST"
+ */
+public class LoginServlet extends SlingAllMethodsServlet {
+
+    /** serialization UID */
+    private static final long serialVersionUID = -8797082194403667968L;
+
+    /** default log */
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    /** @scr.reference cardinality="0..1" policy="dynamic" */
+    private Authenticator authenticator;
+
+    /**
+     * The servlet is registered on this path, and the authenticator allows any
+     * requests to that path, without authentication
+     *
+     * @scr.property name="sling.servlet.paths"
+     */
+    public static final String SERVLET_PATH = "/system/sling/login";
+
+    @Override
+    protected void service(SlingHttpServletRequest request,
+            SlingHttpServletResponse response) throws IOException {
+
+        final String resourcePath = request.getParameter(Authenticator.LOGIN_RESOURCE);
+
+        // if the request is logged in and the resource is not set (such
+        // as when requesting /system/sling/login from the browser with the
+        // browser sending credentials) or the resource is set to the login
+        // servlet as a result of authenticating after providing credentials
+        // through the login servlet), redirect to root now assuming we are
+        // authenticated.
+        if (request.getAuthType() != null) {
+            if (isSelf(resourcePath)) {
+                String redirectTarget = request.getContextPath() + "/";
+                log.warn(
+                    "doGet: Redirecting to {} to prevent login loop for resource {}",
+                    redirectTarget, resourcePath);
+                response.sendRedirect(redirectTarget);
+                return;
+            }
+        }
+
+        Authenticator authenticator = this.authenticator;
+        if (authenticator != null) {
+            try {
+
+                // set the login resource to select the authenticator
+                request.setAttribute(Authenticator.LOGIN_RESOURCE,
+                    (resourcePath != null) ? resourcePath : "/");
+
+                authenticator.login(request, response);
+                return;
+
+            } catch (IllegalStateException ise) {
+
+                log.error("doGet: Response already committed, cannot login");
+                return;
+
+            } catch (NoAuthenticationHandlerException nahe) {
+
+                log.error("doGet: No AuthenticationHandler to login registered");
+
+            }
+
+        } else {
+
+            log.error("doGet: Authenticator service missing, cannot login");
+
+        }
+
+        // fall back to forbid access
+        response.sendError(HttpServletResponse.SC_FORBIDDEN, "Cannot login");
+    }
+
+    private boolean isSelf(final String resourcePath) {
+        // no resource, assume self
+        if (resourcePath == null) {
+            return true;
+        }
+
+        // login servlet is addressed
+        if (resourcePath.startsWith(SERVLET_PATH)) {
+            return true;
+        }
+
+        // not a prefix
+        return false;
+    }
+}

Propchange: sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/LoginServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/LoginServlet.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url

Added: sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/LogoutServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/LogoutServlet.java?rev=896345&view=auto
==============================================================================
--- sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/LogoutServlet.java (added)
+++ sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/LogoutServlet.java Wed Jan  6 07:55:01 2010
@@ -0,0 +1,81 @@
+/*
+ * 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.commons.auth.impl;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.servlets.SlingAllMethodsServlet;
+import org.apache.sling.commons.auth.Authenticator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The <code>LogoutServlet</code> lets the Authenticator
+ * do the logout.
+ *
+ * @scr.component metatype="no"
+ * @scr.service interface="javax.servlet.Servlet"
+ * @scr.property name="service.description" value="Authenticator Logout Servlet"
+ * @scr.property name="service.vendor" value="The Apache Software Foundation"
+ * @scr.property name="sling.servlet.methods" values.0="GET" values.1="POST"
+ *
+ * @since 2.1
+ */
+public class LogoutServlet extends SlingAllMethodsServlet {
+
+    /** serialization UID */
+    private static final long serialVersionUID = -1L;
+
+    /** default log */
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    /** @scr.reference cardinality="0..1" policy="dynamic" */
+    private Authenticator authenticator;
+
+    /** The servlet is registered on this path.
+     *  @scr.property name="sling.servlet.paths" */
+    public static final String SERVLET_PATH = "/system/sling/logout";
+
+    @Override
+    protected void service(SlingHttpServletRequest request,
+            SlingHttpServletResponse response) {
+
+        final Authenticator authenticator = this.authenticator;
+        if (authenticator != null) {
+            try {
+                final String resourcePath = request.getParameter("resource");
+                request.setAttribute(Authenticator.LOGIN_RESOURCE,
+                    (resourcePath != null) ? resourcePath : "/");
+
+                authenticator.logout(request, response);
+                return;
+            } catch (IllegalStateException ise) {
+                log.error("service: Response already committed, cannot logout");
+                return;
+            }
+        }
+
+        log.error("service: Authenticator service missing, cannot logout");
+
+        // well, we don't really have something to say here, do we ?
+        response.setStatus(HttpServletResponse.SC_NO_CONTENT);
+    }
+}

Propchange: sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/LogoutServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/LogoutServlet.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url

Added: sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/PathBasedHolder.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/PathBasedHolder.java?rev=896345&view=auto
==============================================================================
--- sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/PathBasedHolder.java (added)
+++ sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/PathBasedHolder.java Wed Jan  6 07:55:01 2010
@@ -0,0 +1,103 @@
+/*
+ * 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.commons.auth.impl;
+
+/**
+ * The <code>AuthenticationHandlerHolder</code> class represents an
+ * authentication handler service in the internal data structure of the
+ * {@link SlingAuthenticator}.
+ *
+ * @since 2.1
+ */
+public abstract class PathBasedHolder implements Comparable<PathBasedHolder> {
+
+    // full path of the service registration
+    protected final String fullPath;
+
+    // file path part of the service registration full path
+    final String path;
+
+    // host element of the service registration full path
+    final String host;
+
+    // protocol element of the service registration full path
+    final String protocol;
+
+    protected PathBasedHolder(final String fullPath) {
+
+        String path = fullPath;
+        String host = "";
+        String protocol = "";
+
+        // check for protocol prefix in the full path
+        if (path.startsWith("http://") || path.startsWith("https://")) {
+            int idxProtocolEnd = path.indexOf("://");
+            protocol = path.substring(0, idxProtocolEnd);
+            path = path.substring(idxProtocolEnd + 1);
+        }
+
+        // check for host prefix in the full path
+        if (path.startsWith("//")) {
+            int idxHostEnd = path.indexOf("/", 2);
+            idxHostEnd = idxHostEnd == -1 ? path.length() : idxHostEnd;
+
+            if (path.length() > 2) {
+                host = path.substring(2, idxHostEnd);
+                if (idxHostEnd < path.length()) {
+                    path = path.substring(idxHostEnd);
+                } else {
+                    path = "/";
+                }
+            } else {
+                path = "/";
+            }
+        }
+
+        // assign the fields
+        this.fullPath = fullPath;
+        this.path = path;
+        this.host = host;
+        this.protocol = protocol;
+    }
+
+    public int compareTo(PathBasedHolder other) {
+        return other.path.compareTo(path);
+    }
+
+    @Override
+    public int hashCode() {
+        return fullPath.hashCode();
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == this) {
+            return true;
+        } else if (obj == null) {
+            return false;
+        }
+
+        if (obj.getClass() == getClass()) {
+            PathBasedHolder other = (PathBasedHolder) obj;
+            return fullPath.equals(other.fullPath);
+        }
+
+        return false;
+    }
+}
\ No newline at end of file

Propchange: sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/PathBasedHolder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/PathBasedHolder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url

Added: sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/PathBasedHolderCache.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/PathBasedHolderCache.java?rev=896345&view=auto
==============================================================================
--- sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/PathBasedHolderCache.java (added)
+++ sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/PathBasedHolderCache.java Wed Jan  6 07:55:01 2010
@@ -0,0 +1,119 @@
+/*
+ * 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.commons.auth.impl;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+public class PathBasedHolderCache<Type extends PathBasedHolder> {
+
+    private final Map<String, Map<String, ArrayList<Type>>> cache = new HashMap<String, Map<String, ArrayList<Type>>>();
+
+    public synchronized void clear() {
+        cache.clear();
+    }
+
+    public synchronized void addHolder(final Type holder) {
+
+        Map<String, ArrayList<Type>> byHostMap = cache.get(holder.protocol);
+        if (byHostMap == null) {
+            byHostMap = new HashMap<String, ArrayList<Type>>();
+            cache.put(holder.protocol, byHostMap);
+        }
+
+        final ArrayList<Type> byPathList = new ArrayList<Type>();
+
+        // preset with current list
+        final ArrayList<Type> currentPathList = byHostMap.get(holder.host);
+        if (currentPathList != null) {
+            byPathList.addAll(currentPathList);
+        }
+
+        // add the new holder
+        byPathList.add(holder);
+
+        // sort the list according to the path length (longest path first)
+        Collections.sort(byPathList);
+
+        // replace old list with new list
+        byHostMap.put(holder.host, byPathList);
+    }
+
+    public synchronized void removeHolder(final Type holder) {
+        final Map<String, ArrayList<Type>> byHostMap = cache.get(holder.protocol);
+        if (byHostMap != null) {
+            final ArrayList<Type> byPathList = byHostMap.get(holder.host);
+            if (byPathList != null) {
+
+                // create a new list without the removed holder
+                final ArrayList<Type> list = new ArrayList<Type>();
+                list.addAll(byPathList);
+                list.remove(holder);
+
+                // replace the old list with the new one (or remove if empty)
+                if (list.isEmpty()) {
+                    byHostMap.remove(holder.host);
+                } else {
+                    byHostMap.put(holder.host, list);
+                }
+            }
+        }
+    }
+
+    public synchronized ArrayList<Type> findApplicableHolder(
+            HttpServletRequest request) {
+
+        Map<String, ArrayList<Type>> byHostMap = cache.get(request.getScheme());
+        if (byHostMap == null) {
+            byHostMap = cache.get("");
+        }
+
+        String hostname = request.getServerName()
+            + (request.getServerPort() != 80 && request.getServerPort() != 443
+                    ? ":" + request.getServerPort()
+                    : "");
+
+        ArrayList<Type> infos = null;
+        if (byHostMap != null) {
+            infos = byHostMap.get(hostname);
+            if (infos == null) {
+                infos = byHostMap.get("");
+            }
+            if (infos != null) {
+                return infos;
+            }
+        }
+
+        return null;
+    }
+
+    public synchronized ArrayList<Type> getHolders() {
+        final ArrayList<Type> result = new ArrayList<Type>();
+        for (Map<String, ArrayList<Type>> byHostEntry : cache.values()) {
+            for (ArrayList<Type> holderList : byHostEntry.values()) {
+                result.addAll(holderList);
+            }
+        }
+        return result;
+    }
+}

Propchange: sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/PathBasedHolderCache.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/commons/auth/src/main/java/org/apache/sling/commons/auth/impl/PathBasedHolderCache.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url



Mime
View raw message