[gatein-commits] gatein SVN: r5619 - in components/wci/trunk: exo and 26 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Dec 21 13:31:23 EST 2010


Author: mwringe
Date: 2010-12-21 13:31:20 -0500 (Tue, 21 Dec 2010)
New Revision: 5619

Added:
   components/wci/trunk/test/core/src/main/java/org/gatein/wci/spi/SPIAuthenticationTestCase.java
   components/wci/trunk/tomcat-tmp/
   components/wci/trunk/tomcat-tmp/tomcat6/
   components/wci/trunk/tomcat-tmp/tomcat7/
   components/wci/trunk/tomcat-tmp/tomcat7/pom.xml
   components/wci/trunk/tomcat-tmp/tomcat7/src/
   components/wci/trunk/tomcat-tmp/tomcat7/src/main/
   components/wci/trunk/tomcat-tmp/tomcat7/src/main/java/
   components/wci/trunk/tomcat-tmp/tomcat7/src/main/java/org/
   components/wci/trunk/tomcat-tmp/tomcat7/src/main/java/org/gatein/
   components/wci/trunk/tomcat-tmp/tomcat7/src/main/java/org/gatein/wci/
   components/wci/trunk/tomcat-tmp/tomcat7/src/main/java/org/gatein/wci/tomcat/
   components/wci/trunk/tomcat-tmp/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7ContainerServlet.java
   components/wci/trunk/tomcat-tmp/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7LifecycleListener.java
   components/wci/trunk/tomcat-tmp/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7ServletContainerContext.java
   components/wci/trunk/tomcat-tmp/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7WebAppContext.java
   components/wci/trunk/wci/src/main/doc/
   components/wci/trunk/wci/src/main/doc/wci-authentication.odp
   components/wci/trunk/wci/src/main/doc/wci-authentication.pdf
   components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/
   components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/AuthenticationEvent.java
   components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/AuthenticationException.java
   components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/AuthenticationListener.java
   components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/AuthenticationResult.java
   components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/GenericAuthentication.java
   components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/GenericAuthenticationResult.java
   components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/ProgrammaticAuthenticationResult.java
   components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/Ticket.java
   components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/TicketService.java
   components/wci/trunk/wci/src/main/java/org/gatein/wci/security/
   components/wci/trunk/wci/src/main/java/org/gatein/wci/security/Credentials.java
   components/wci/trunk/wci/src/main/java/org/gatein/wci/security/WCILoginController.java
   components/wci/trunk/wci/src/main/java/org/gatein/wci/security/WCILoginModule.java
Removed:
   components/wci/trunk/tomcat/
Modified:
   components/wci/trunk/exo/pom.xml
   components/wci/trunk/jetty/src/main/java/org/gatein/wci/jetty/Jetty6ServletContainerContext.java
   components/wci/trunk/pom.xml
   components/wci/trunk/test/core/src/main/java/org/gatein/wci/container/ServletContainerContextImpl.java
   components/wci/trunk/test/core/src/main/resources/org/gatein/portal/test/web/spi/native/server-beans.xml
   components/wci/trunk/test/src/test/build.xml
   components/wci/trunk/test/src/test/resources/config/servers.xml
   components/wci/trunk/tomcat-tmp/tomcat6/pom.xml
   components/wci/trunk/tomcat-tmp/tomcat6/src/main/java/org/gatein/wci/tomcat/TC6ServletContainerContext.java
   components/wci/trunk/wci/pom.xml
   components/wci/trunk/wci/src/main/java/org/gatein/wci/ServletContainer.java
   components/wci/trunk/wci/src/main/java/org/gatein/wci/impl/DefaultServletContainer.java
   components/wci/trunk/wci/src/main/java/org/gatein/wci/impl/generic/GenericServletContainerContext.java
   components/wci/trunk/wci/src/main/java/org/gatein/wci/spi/ServletContainerContext.java
Log:
Merge in changes from the adf branch.

Modified: components/wci/trunk/exo/pom.xml
===================================================================
--- components/wci/trunk/exo/pom.xml	2010-12-21 17:12:17 UTC (rev 5618)
+++ components/wci/trunk/exo/pom.xml	2010-12-21 18:31:20 UTC (rev 5619)
@@ -14,6 +14,11 @@
        <groupId>org.gatein.wci</groupId>
        <artifactId>wci-wci</artifactId>
      </dependency>
+     <dependency>
+      <groupId>javax.servlet</groupId>
+      <artifactId>servlet-api</artifactId>
+      <scope>provided</scope>
+    </dependency>
    </dependencies>
 
 </project>

Modified: components/wci/trunk/jetty/src/main/java/org/gatein/wci/jetty/Jetty6ServletContainerContext.java
===================================================================
--- components/wci/trunk/jetty/src/main/java/org/gatein/wci/jetty/Jetty6ServletContainerContext.java	2010-12-21 17:12:17 UTC (rev 5618)
+++ components/wci/trunk/jetty/src/main/java/org/gatein/wci/jetty/Jetty6ServletContainerContext.java	2010-12-21 18:31:20 UTC (rev 5619)
@@ -10,6 +10,8 @@
 import javax.servlet.http.HttpServletResponse;
 
 import org.gatein.wci.RequestDispatchCallback;
+import org.gatein.wci.authentication.AuthenticationResult;
+import org.gatein.wci.authentication.GenericAuthentication;
 import org.gatein.wci.command.CommandDispatcher;
 import org.gatein.wci.impl.DefaultServletContainerFactory;
 import org.gatein.wci.spi.ServletContainerContext;
@@ -60,7 +62,16 @@
 		this.registration = null;
 	}
 
+   public AuthenticationResult login(HttpServletRequest request, HttpServletResponse response, String userName, String password, long validityMillis)
+   {
+      return GenericAuthentication.getInstance().login(userName, password, request, response, validityMillis);
+   }
 
+   public void logout(HttpServletRequest request, HttpServletResponse response)
+   {
+      GenericAuthentication.getInstance().logout(request, response);
+   }
+
 	public void start()
 	{
 		DefaultServletContainerFactory.registerContext(this);
@@ -99,7 +110,6 @@
 		else if (bean instanceof WebAppContext)
 		{
 			WebAppContext wac = (WebAppContext)bean;
-			System.out.println("ADDING WEBAPP " + wac.getWar());
 			registerWebAppContext(wac);
 		}
 	}
@@ -125,7 +135,7 @@
 
 	public void remove(Relationship relationship) 
 	{
-		//ignore event for now
+      removeBean(relationship.getChild());
 	}
 
 	private void startWebAppContext(WebAppContext webappContext) 
@@ -180,7 +190,6 @@
 
 	private void unregisterWebAppContext(WebAppContext wac) 
 	{
-		System.out.println("UNREGISTERWEBAPPCONTEXT : " + wac);
 		if (monitoredContexts.contains(wac.getServletContext().getServletContextName()))
 	      {
 	         monitoredContexts.remove(wac.getServletContext().getServletContextName());

Modified: components/wci/trunk/pom.xml
===================================================================
--- components/wci/trunk/pom.xml	2010-12-21 17:12:17 UTC (rev 5618)
+++ components/wci/trunk/pom.xml	2010-12-21 18:31:20 UTC (rev 5619)
@@ -32,7 +32,8 @@
     <version.discovery>0.4</version.discovery>
     <!-- used in test module by maven-antrun-extended-plugin -->
     <version.jboss.unit>1.2.3</version.jboss.unit>
-    <version.cargo>1.0.1-alpha-2</version.cargo>
+    <version.cargo>1.0.3</version.cargo>
+    <version.cargo.jetty.deployer>1.0.1</version.cargo.jetty.deployer>
 
   </properties>
   
@@ -52,6 +53,16 @@
         <groupId>org.gatein.common</groupId>
         <artifactId>common-common</artifactId>
         <version>${version.gatein.common}</version>
+        <exclusions>
+          <exclusion>
+            <groupId>org.codehaus.cargo</groupId>
+            <artifactId>cargo-core-uberjar</artifactId>
+          </exclusion>
+          <exclusion>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+          </exclusion>
+        </exclusions>
       </dependency>
       <dependency>
         <groupId>org.gatein.common</groupId>
@@ -70,9 +81,14 @@
      </dependency>
      <dependency>
        <groupId>org.gatein.wci</groupId>
-       <artifactId>wci-tomcat</artifactId>
+       <artifactId>wci-tomcat6</artifactId>
        <version>${project.version}</version>
       </dependency>
+     <dependency>
+       <groupId>org.gatein.wci</groupId>
+       <artifactId>wci-tomcat7</artifactId>
+       <version>${project.version}</version>
+      </dependency>
       <dependency>
         <groupId>org.gatein.wci</groupId>
         <artifactId>wci-jetty</artifactId>
@@ -126,7 +142,8 @@
   <modules>
     <module>wci</module>
     <module>exo</module>
-    <module>tomcat</module>
+    <module>tomcat-tmp/tomcat6</module>
+    <module>tomcat-tmp/tomcat7</module>
     <module>jetty</module>
     <module>test</module>
   </modules>

Modified: components/wci/trunk/test/core/src/main/java/org/gatein/wci/container/ServletContainerContextImpl.java
===================================================================
--- components/wci/trunk/test/core/src/main/java/org/gatein/wci/container/ServletContainerContextImpl.java	2010-12-21 17:12:17 UTC (rev 5618)
+++ components/wci/trunk/test/core/src/main/java/org/gatein/wci/container/ServletContainerContextImpl.java	2010-12-21 18:31:20 UTC (rev 5619)
@@ -1,6 +1,6 @@
 /******************************************************************************
  * JBoss, a division of Red Hat                                               *
- * Copyright 2006, Red Hat Middleware, LLC, and individual                    *
+ * Copyright 2010, Red Hat Middleware, LLC, and individual                    *
  * contributors as indicated by the @authors tag. See the                     *
  * copyright.txt in the distribution for a full listing of                    *
  * individual contributors.                                                   *
@@ -22,6 +22,7 @@
  ******************************************************************************/
 package org.gatein.wci.container;
 
+import org.gatein.wci.authentication.AuthenticationResult;
 import org.gatein.wci.spi.ServletContainerContext;
 import org.gatein.wci.RequestDispatchCallback;
 
@@ -59,4 +60,14 @@
    {
       this.registration = null;
    }
+
+   public AuthenticationResult login(HttpServletRequest request, HttpServletResponse response, String userName, String password, long validityMillis)
+   {
+      throw new UnsupportedOperationException();
 }
+
+   public void logout(HttpServletRequest request, HttpServletResponse response)
+   {
+      throw new UnsupportedOperationException();
+   }
+}

Added: components/wci/trunk/test/core/src/main/java/org/gatein/wci/spi/SPIAuthenticationTestCase.java
===================================================================
--- components/wci/trunk/test/core/src/main/java/org/gatein/wci/spi/SPIAuthenticationTestCase.java	                        (rev 0)
+++ components/wci/trunk/test/core/src/main/java/org/gatein/wci/spi/SPIAuthenticationTestCase.java	2010-12-21 18:31:20 UTC (rev 5619)
@@ -0,0 +1,197 @@
+/*
+* Copyright (C) 2003-2009 eXo Platform SAS.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package org.gatein.wci.spi;
+
+import org.gatein.wci.ServletContainer;
+import org.gatein.wci.ServletTestCase;
+import org.gatein.wci.TestServlet;
+import org.gatein.wci.WebRequest;
+import org.gatein.wci.WebResponse;
+import org.gatein.wci.authentication.AuthenticationEvent;
+import org.gatein.wci.authentication.AuthenticationException;
+import org.gatein.wci.authentication.AuthenticationListener;
+import org.gatein.wci.authentication.AuthenticationResult;
+import org.gatein.wci.authentication.GenericAuthentication;
+import org.gatein.wci.authentication.GenericAuthenticationResult;
+import org.gatein.wci.authentication.ProgrammaticAuthenticationResult;
+import org.gatein.wci.authentication.TicketService;
+import org.gatein.wci.security.Credentials;
+import org.gatein.wci.impl.DefaultServletContainerFactory;
+import org.jboss.unit.Failure;
+import org.jboss.unit.driver.DriverCommand;
+import org.jboss.unit.driver.DriverResponse;
+import org.jboss.unit.driver.response.EndTestResponse;
+import org.jboss.unit.driver.response.FailureResponse;
+import org.jboss.unit.remote.driver.handler.http.response.InvokeGetResponse;
+
+import static org.jboss.unit.api.Assert.*;
+
+import javax.servlet.ServletException;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:alain.defrance at exoplatform.com">Alain Defrance</a>
+ * @version $Revision$
+ */
+public class SPIAuthenticationTestCase extends ServletTestCase
+{
+   private final String username = "foo";
+   private final String password = "bar";
+
+   /** . */
+   private ServletContainer container;
+
+   /** . */
+   private final Value v = new Value();
+
+   /** . */
+   private AuthenticationResult result;
+
+   @Override
+   public DriverResponse service(TestServlet testServlet, WebRequest req, WebResponse resp) throws ServletException, IOException
+   {
+      if (getRequestCount() == 0)
+      {
+         assertNull(req.getUserPrincipal());
+         container = DefaultServletContainerFactory.getInstance().getServletContainer();
+         container.addAuthenticationListener(new TestListener(v));
+         assertEquals("", v.value);
+         result = container.login(req, resp, username, password, TicketService.DEFAULT_VALIDITY);
+         assertNotNull(result);
+         if (result instanceof GenericAuthenticationResult)
+         {
+            GenericAuthenticationResult gAuthentication = (GenericAuthenticationResult) result;
+            // Test Ticket Expiration
+            GenericAuthentication.getInstance();
+            String expireTicket = GenericAuthentication.TICKET_SERVICE.createTicket(new Credentials("foo", "bar"), 5);
+            boolean expired = false;
+            try
+            {
+               Thread.sleep(5);
+               GenericAuthentication.TICKET_SERVICE.validateTicket(expireTicket, true);
+            }
+            catch (InterruptedException ignore)
+            {
+            }
+            catch (AuthenticationException ae)
+            {
+               expired = true;
+            }
+            if (!expired) return new FailureResponse(Failure.createAssertionFailure(""));
+
+
+            // Test Ticket Service
+            Credentials srcCredentials = new Credentials(username, password);
+            String ticket = GenericAuthentication.TICKET_SERVICE.createTicket(srcCredentials, TicketService.DEFAULT_VALIDITY);
+            Credentials resultCredentials = GenericAuthentication.TICKET_SERVICE.validateTicket(ticket, false);
+            assertEquals(srcCredentials.getUsername(), resultCredentials.getUsername());
+            assertEquals(srcCredentials.getPassword(), resultCredentials.getPassword());
+            assertNotNull(GenericAuthentication.TICKET_SERVICE.validateTicket(ticket, true));
+            assertNull(GenericAuthentication.TICKET_SERVICE.validateTicket(ticket, true));
+
+            // Test Generic login
+            GenericAuthenticationResult gResult = (GenericAuthenticationResult) result;
+            String t = gResult.getTicket();
+            Credentials credentials = GenericAuthentication.TICKET_SERVICE.validateTicket(t, true);
+            assertNotNull(credentials);
+            assertEquals("", v.value);
+            gAuthentication.perform(req, resp);
+
+            // Test login Event
+            assertEquals("login", v.value);
+            assertTrue(resp.isCommitted());
+            
+         }
+         else if (result instanceof ProgrammaticAuthenticationResult)
+         {
+            assertEquals("login", v.value);
+            assertNotNull(req.getUserPrincipal());
+            assertTrue(req.isUserInRole("test"));
+         }
+
+         //
+         String url = resp.renderURL("/", null, null);
+         return new InvokeGetResponse(url);
+      }
+      else if (getRequestCount() == 1)
+      {
+         if (result instanceof GenericAuthenticationResult)
+         {
+            // Test logout
+            assertNotNull(req.getSession(false));
+            assertEquals("login", v.value);
+            container.logout(req, resp);
+            assertNull(req.getSession(false));
+
+            // Test logout Event
+            assertEquals("logout", v.value);
+         }
+         else if (result instanceof ProgrammaticAuthenticationResult)
+         {
+            assertEquals("login", v.value);
+
+            container.logout(req, resp);
+
+            assertEquals("logout", v.value);
+            assertNull(req.getUserPrincipal());
+         }
+         return new EndTestResponse();
+      }
+
+      return new FailureResponse(Failure.createAssertionFailure(""));
+   }
+
+   @Override
+   public DriverResponse invoke(TestServlet testServlet, DriverCommand driverCommand)
+   {
+      if (getRequestCount() == -1)
+      {
+         return new InvokeGetResponse("/test-spi-server");
+      }
+      else
+      {
+         return new FailureResponse(Failure.createAssertionFailure(""));
+      }
+   }
+
+   class Value
+   {
+      public String value = "";
+   }
+
+   public static class TestListener implements AuthenticationListener
+   {
+      private Value value;
+
+      public TestListener(Value value) {
+         this.value = value;
+      }
+
+      public void onLogin(AuthenticationEvent ae)
+      {
+         value.value = "login";
+      }
+
+      public void onLogout(AuthenticationEvent ae)
+      {
+         value.value = "logout";
+      }
+   }
+}

Modified: components/wci/trunk/test/core/src/main/resources/org/gatein/portal/test/web/spi/native/server-beans.xml
===================================================================
--- components/wci/trunk/test/core/src/main/resources/org/gatein/portal/test/web/spi/native/server-beans.xml	2010-12-21 17:12:17 UTC (rev 5618)
+++ components/wci/trunk/test/core/src/main/resources/org/gatein/portal/test/web/spi/native/server-beans.xml	2010-12-21 18:31:20 UTC (rev 5619)
@@ -75,4 +75,13 @@
       </uninstall>
    </bean>
 
+   <bean name="SPIAuthenticationTestCase" class="org.gatein.wci.spi.SPIAuthenticationTestCase">
+      <install bean="TestSuite" method="mount">
+         <parameter><this/></parameter>
+      </install>
+      <uninstall bean="TestSuite" method="unmount">
+         <parameter><this/></parameter>
+      </uninstall>
+   </bean>
+
 </deployment>

Modified: components/wci/trunk/test/src/test/build.xml
===================================================================
--- components/wci/trunk/test/src/test/build.xml	2010-12-21 17:12:17 UTC (rev 5618)
+++ components/wci/trunk/test/src/test/build.xml	2010-12-21 18:31:20 UTC (rev 5619)
@@ -27,6 +27,7 @@
    <target name="tests.call.all" unless="tests">
       <antcall target="tests.jboss5"/>
       <antcall target="tests.jboss"/>
+      <antcall target="tests.tomcat7"/>
       <antcall target="tests.tomcat"/>
 <!--      <antcall target="tests.jetty"/> -->
    </target>
@@ -45,6 +46,9 @@
    <target name="tests.tomcat">
       <antcall target="tests.tomcat-6.0"/>
    </target>
+   <target name="tests.tomcat7">
+      <antcall target="tests.tomcat-7.0"/>
+   </target>
    <target name="tests.jetty">
       <antcall target="tests.jetty-6.1"/>
    </target>
@@ -116,6 +120,14 @@
             </not>
          </and>
       </condition>
+      <condition property="TOMCAT_7_0_HOME" value="${env.TOMCAT_7_0_HOME}">
+         <and>
+            <isset property="env.TOMCAT_7_0_HOME"/>
+            <not>
+               <isset property="TOMCAT_7_0_HOME"/>
+            </not>
+         </and>
+      </condition>
       <condition property="JETTY_6_1_HOME" value="${env.JETTY_6_1_HOME}">
          <and>
             <isset property="env.JETTY_6_1_HOME"/>
@@ -160,7 +172,7 @@
          </condition>
       </fail>
 
-      <fail message="Please set the environment variable TOMCAT_6_0_HOME or use -Dtest.specified.containers to only run tests for containers specified with a HOME variable">
+      <fail message="Please set the environment variable TOMCAT_6_0_HOME or TOMCAT_7_0_HOME or use -Dtest.specified.containers to only run tests for containers specified with a HOME variable">
          <condition>
             <and>
                <not>
@@ -169,6 +181,9 @@
                <not>
                   <isset property="TOMCAT_6_0_HOME"/>
                </not>
+               <not>
+                  <isset property="TOMCAT_7_0_HOME"/>
+               </not>
             </and>
          </condition>
       </fail>
@@ -276,6 +291,27 @@
          <path location="${dependency.jboss-serialization.jar}"/>
       </path>
 
+      <path id="tomcat-7.0">
+         <path refid="gatein-common"/>
+         <path refid="jboss-unit"/>
+         <path refid="jboss-microcontainer"/>
+         <pathelement path="${dependency.log4j.jar}"/>
+         <pathelement path="${dependency.xercesImpl.jar}"/>
+         <pathelement path="${dependency.xml-apis.jar}"/>
+         <pathelement path="${dependency.concurrent.jar}"/>
+      </path>
+
+      <path id="tomcat-7.0-shared">
+         <path refid="jboss-logging"/>
+         <path refid="gatein-common-shared"/>
+         <path location="${dependency.log4j.jar}"/>
+         <path location="${dependency.activation.jar}"/>
+         <path location="${dependency.junit.jar}"/>
+         <path path="${dependency.gatein-wci-core.jar}"/>
+         <path path="${dependency.gatein-wci-tomcat.jar}"/>
+         <path path="${dependency.gatein-wci-exo.jar}"/>
+         <path location="${dependency.jboss-serialization.jar}"/>
+      </path>
       <path id="jetty-6.1">
          <path refid="gatein-common"/>
          <path refid="jboss-unit"/>
@@ -381,8 +417,81 @@
          <fileset dir="${target}/test-classes/spi/exo/app-war"/>
       </jar>
 
+      <!-- **************************** -->
+      <!-- Tomcat 7.0 container servlet -->
+      <!-- **************************** -->
 
+      <copy todir="${test.support}/tomcat-7.0-container-servlet/server-war/WEB-INF/lib" flatten="true">
+        <path refid="tomcat-7.0"/>
+      </copy>
+      <mkdir dir="${test.temp.lib}/tomcat-7.0-container-servlet"/>
+      <war jarfile="${test.temp.lib}/tomcat-7.0-container-servlet/test-spi-server.war">
+        <fileset dir="${test.support}/tomcat-7.0-container-servlet/server-war"/>
+        <lib dir="${test.temp.lib}" includes="portal-test-spi-cs-lib.jar"/>
+      </war>
+      <jar jarfile="${test.temp.lib}/tomcat-7.0-container-servlet/test-spi-app.war">
+        <fileset dir="${target}/test-classes/spi/app-war"/>
+      </jar>
+      <jar jarfile="${test.temp.lib}/tomcat-7.0-container-servlet/test-generic-app.war">
+        <fileset dir="${target}/test-classes/spi/generic/app-war"/>
+      </jar>
+      <jar jarfile="${test.temp.lib}/tomcat-7.0-container-servlet/test-exo-app.war">
+        <fileset dir="${target}/test-classes/spi/exo/app-war"/>
+      </jar>
+
       <!-- **************************** -->
+      <!-- Tomcat 7.0 lifecyle listener -->
+      <!-- **************************** -->
+
+      <copy todir="${test.support}/tomcat-7.0-lifecycle-listener/server-war/WEB-INF/lib" flatten="true">
+        <path refid="tomcat-7.0"/>
+      </copy>
+      <mkdir dir="${test.temp.lib}/tomcat-7.0-lifecycle-listener"/>
+      <war jarfile="${test.temp.lib}/tomcat-7.0-lifecycle-listener/test-spi-server.war">
+        <fileset dir="${test.support}/tomcat-7.0-lifecycle-listener/server-war"/>
+        <lib dir="${test.temp.lib}" includes="portal-test-spi-lib.jar"/>
+      </war>
+      <jar jarfile="${test.temp.lib}/tomcat-7.0-lifecycle-listener/test-spi-app.war">
+        <fileset dir="${target}/test-classes/spi/app-war"/>
+      </jar>
+
+      <!-- ****************** -->
+      <!-- Tomcat 7.0 generic -->
+      <!-- ****************** -->
+
+      <!--  -->
+      <mkdir dir="${test.support}/tomcat-7.0-generic/server-war/WEB-INF/lib"/>
+      <copy todir="${test.support}/tomcat-7.0-generic/server-war/WEB-INF/lib"  flatten="true">
+        <path refid="tomcat-7.0"/>
+      </copy>
+      <mkdir dir="${test.temp.lib}/tomcat-7.0-generic"/>
+      <war jarfile="${test.temp.lib}/tomcat-7.0-generic/test-spi-server.war">
+        <fileset dir="${test.support}/tomcat-7.0-generic/server-war"/>
+        <lib dir="${test.temp.lib}" includes="portal-test-spi-lib.jar"/>
+      </war>
+      <jar jarfile="${test.temp.lib}/tomcat-7.0-generic/test-spi-app.war">
+        <fileset dir="${target}/test-classes/spi/generic/app-war"/>
+      </jar>
+
+      <!-- ****************** -->
+      <!-- Tomcat 7.0 eXo -->
+      <!-- ****************** -->
+
+      <!--  -->
+      <mkdir dir="${test.support}/tomcat-7.0-exo/server-war/WEB-INF/lib"/>
+      <copy todir="${test.support}/tomcat-7.0-exo/server-war/WEB-INF/lib"  flatten="true">
+        <path refid="tomcat-7.0"/>
+      </copy>
+      <mkdir dir="${test.temp.lib}/tomcat-7.0-exo"/>
+      <war jarfile="${test.temp.lib}/tomcat-7.0-exo/test-spi-server.war">
+        <fileset dir="${test.support}/tomcat-7.0-exo/server-war"/>
+        <lib dir="${test.temp.lib}" includes="portal-test-spi-lib.jar"/>
+      </war>
+      <jar jarfile="${test.temp.lib}/tomcat-7.0-exo/test-spi-app.war">
+        <fileset dir="${target}/test-classes/spi/exo/app-war"/>
+      </jar>
+
+      <!-- **************************** -->
       <!-- Jetty 6.1 handler -->
       <!-- **************************** -->
 
@@ -596,6 +705,36 @@
          <lib dir="${test.temp.lib}" includes="portal-test-endpoint-lib.jar"/>
       </war>
 
+      <!-- ********** -->
+      <!-- Tomcat 7.0 -->
+      <!-- ********** -->
+
+      <mkdir dir="${test.temp.lib}/tomcat-7.0"/>
+
+      <copy todir="${test.support}/tomcat-7.0-endpoint/default-servlet-mapping-war/WEB-INF/lib" flatten="true">
+         <path refid="tomcat-7.0"/>
+      </copy>
+      <war jarfile="${test.temp.lib}/tomcat-7.0/default-servlet-mapping.war">
+         <fileset dir="${test.support}/tomcat-7.0-endpoint/default-servlet-mapping-war"/>
+         <lib dir="${test.temp.lib}" includes="portal-test-endpoint-lib.jar"/>
+      </war>
+
+      <copy todir="${test.support}/tomcat-7.0-endpoint/path-mapping-war/WEB-INF/lib" flatten="true">
+         <path refid="tomcat-7.0"/>
+      </copy>
+      <war jarfile="${test.temp.lib}/tomcat-7.0/path-mapping.war">
+         <fileset dir="${test.support}/tomcat-7.0-endpoint/path-mapping-war"/>
+         <lib dir="${test.temp.lib}" includes="portal-test-endpoint-lib.jar"/>
+      </war>
+
+      <copy todir="${test.support}/tomcat-7.0-endpoint/root-path-mapping-war/WEB-INF/lib" flatten="true">
+         <path refid="tomcat-7.0"/>
+      </copy>
+      <war jarfile="${test.temp.lib}/tomcat-7.0/root-path-mapping.war">
+         <fileset dir="${test.support}/tomcat-7.0-endpoint/root-path-mapping-war"/>
+         <lib dir="${test.temp.lib}" includes="portal-test-endpoint-lib.jar"/>
+      </war>
+
       <!-- ********* -->
       <!-- JETTY 6.1 -->
       <!-- ********* -->
@@ -1084,6 +1223,119 @@
 
    </target>
 
+   <target name="cargo.tomcat-7.0.start" depends="cargo.setup">
+
+     <cargo
+        containerId="tomcat7x"
+        home="${test.tomcat-7.0.home}"
+        output="${cargo.log.dir}/cargo.${test.id}.server.log"
+        log="${cargo.log.dir}/cargo.${test.id}.start.log"
+        action="start"
+        wait="${cargo.wait}">
+        <sharedClasspath>
+
+           <path refid="tomcat-7.0-shared"/>
+
+        </sharedClasspath>
+        <configuration home="${target}/cargo">
+           <property name="cargo.servlet.port" value="8080"/>
+           <property name="cargo.logging" value="high"/>
+           <property name="cargo.jvmargs" value="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000"/>
+
+           <deployable type="war" file="${test.temp.lib}/manager.war"/>
+           <file file="${test.temp.lib}/manager" todir="webapps/manager"/>
+           <deployable type="war" file="${cargo.war}"/>
+       </configuration>
+     </cargo>
+   </target>
+
+   <target name="cargo.tomcat-7.0.stop" depends="cargo.setup">
+     <cargo
+        containerId="tomcat7x"
+        home="${test.tomcat-7.0.home}"
+        log="${cargo.log.dir}/cargo.${test.id}.shutdown.log"
+        action="stop">
+        <configuration home="${target}/cargo">
+        </configuration>
+     </cargo>
+   </target>
+
+   <target name="tests.tomcat-7.0.execute" unless="tests.tomcat-7.0.execute.skip">
+     <echo message="Starting Tomcat 7.0 ${test.tomcat-7.0.name} with ${test.tomcat-7.0.home} to execute ${test.id} tests"/>
+     <antcall target="cargo.tomcat-7.0.start">
+        <param name="cargo.wait" value="false"/>
+        <param name="cargo.war" value="${test.war}"/>
+     </antcall>
+     <antcall target="tests.remote">
+        <param name="test.remote.server.name" value="${test.tomcat-7.0.name}"/>
+        <param name="test.remote.archive.path" value="${test.archive.path}"/>
+     </antcall>
+     <antcall target="cargo.tomcat-7.0.stop">
+     </antcall>
+   </target>
+
+   <target name="tests.tomcat-7.0.spi">
+     <condition property="tests.tomcat-7.0.execute.skip">
+        <not>
+           <available file="${test.tomcat-7.0.home}" type="dir"/>
+        </not>
+     </condition>
+     <antcall target="tests.tomcat-7.0.execute">
+        <param name="test.id" value="${test.tomcat-7.0.name}-spi-container-servlet"/>
+        <param name="test.war" value="${test.temp.lib}/tomcat-7.0-container-servlet/test-spi-server.war"/>
+        <param name="test.archive.path" value="tomcat-7.0-container-servlet"/>
+     </antcall>
+     <antcall target="tests.tomcat-7.0.execute">
+        <param name="test.id" value="${test.tomcat-7.0.name}-spi-generic"/>
+        <param name="test.war" value="${test.temp.lib}/tomcat-7.0-generic/test-spi-server.war"/>
+        <param name="test.archive.path" value="tomcat-7.0-generic"/>
+     </antcall>
+     <antcall target="tests.tomcat-7.0.execute">
+        <param name="test.id" value="${test.tomcat-7.0.name}-spi-exo"/>
+        <param name="test.war" value="${test.temp.lib}/tomcat-7.0-exo/test-spi-server.war"/>
+        <param name="test.archive.path" value="tomcat-7.0-exo"/>
+     </antcall>
+   </target>
+
+   <target name="tests.tomcat-7.0.endpoint">
+     <condition property="tests.tomcat-7.0.execute.skip">
+        <not>
+           <available file="${test.tomcat-7.0.home}" type="dir"/>
+        </not>
+     </condition>
+     <antcall target="tests.tomcat-7.0.execute">
+        <param name="test.id" value="${test.tomcat-7.0.name}-endpoint-default-servlet-mapping"/>
+        <param name="test.war" value="${test.temp.lib}/tomcat-7.0/default-servlet-mapping.war"/>
+        <param name="test.archive.path" value=""/>
+     </antcall>
+     <antcall target="tests.tomcat-7.0.execute">
+        <param name="test.id" value="${test.tomcat-7.0.name}-endpoint-root-path-mapping"/>
+        <param name="test.war" value="${test.temp.lib}/tomcat-7.0/root-path-mapping.war"/>
+        <param name="test.archive.path" value=""/>
+     </antcall>
+     <antcall target="tests.tomcat-7.0.execute">
+        <param name="test.id" value="${test.tomcat-7.0.name}-endpoint-path-mapping"/>
+        <param name="test.war" value="${test.temp.lib}/tomcat-7.0/path-mapping.war"/>
+        <param name="test.archive.path" value=""/>
+     </antcall>
+   </target>
+
+   <target name="tests.tomcat-7.0">
+     <!-- spi tests -->
+     <antcall target="tests.tomcat-7.0.spi">
+        <param name="test.tomcat-7.0.name" value="RemoteTomcat_7_0"/>
+        <param name="test.tomcat-7.0.home" value="${TOMCAT_7_0_HOME}"/>
+     </antcall>
+
+     <!-- endpoint tests -->
+
+     <antcall target="tests.tomcat-7.0.endpoint">
+        <param name="test.tomcat-7.0.name" value="RemoteTomcat_7_0"/>
+        <param name="test.tomcat-7.0.home" value="${TOMCAT_7_0_HOME}"/>
+      </antcall>
+
+   </target>
+
    <target name="cargo.jetty-6.1.start" depends="cargo.setup">
       <cargo
          containerId="jetty6x"

Modified: components/wci/trunk/test/src/test/resources/config/servers.xml
===================================================================
--- components/wci/trunk/test/src/test/resources/config/servers.xml	2010-12-21 17:12:17 UTC (rev 5618)
+++ components/wci/trunk/test/src/test/resources/config/servers.xml	2010-12-21 18:31:20 UTC (rev 5619)
@@ -22,6 +22,28 @@
       </node>
    </server>
    <server>
+      <server-name>RemoteTomcat_7_0</server-name>
+      <node>
+         <node-id>default</node-id>
+         <service>
+            <service-name>TestDriverServer</service-name>
+            <interface>org.jboss.unit.remote.driver.RemoteTestDriver</interface>
+            <uri>socket://localhost:5400</uri>
+         </service>
+         <deployer>
+            <remote>
+               <name>tomcat7x</name>
+               <host>localhost</host>
+               <port>8080</port>
+            </remote>
+            <authentication>
+               <username>admin</username>
+               <password>admin</password>
+            </authentication>
+         </deployer>
+      </node>
+   </server>
+   <server>
       <server-name>RemoteJetty_6_1</server-name>
       <node>
          <node-id>default</node-id>
@@ -126,7 +148,7 @@
          </service>
          <deployer>
             <remote>
-               <name>jboss5x</name>
+               <name>jboss51x</name>
                <host>localhost</host>
                <port>8080</port>
             </remote>

Copied: components/wci/trunk/tomcat-tmp/tomcat6 (from rev 5615, components/wci/trunk/tomcat)

Modified: components/wci/trunk/tomcat-tmp/tomcat6/pom.xml
===================================================================
--- components/wci/trunk/tomcat/pom.xml	2010-12-20 16:09:27 UTC (rev 5615)
+++ components/wci/trunk/tomcat-tmp/tomcat6/pom.xml	2010-12-21 18:31:20 UTC (rev 5619)
@@ -5,9 +5,9 @@
       <version>2.1.0-Beta01-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
-   <artifactId>wci-tomcat</artifactId>
+   <artifactId>wci-tomcat6</artifactId>
    <packaging>jar</packaging>
-   <name>GateIn - WCI Tomcat compatibility component</name>
+   <name>GateIn - WCI Tomcat 6 compatibility component</name>
 
    <dependencies>
      <dependency>
@@ -17,12 +17,6 @@
      <dependency>
       <groupId>org.apache.tomcat</groupId>
       <artifactId>catalina</artifactId>
-      <exclusions>
-        <exclusion>
-          <groupId>org.apache.tomcat</groupId>
-          <artifactId>servlet-api</artifactId>
-        </exclusion>
-      </exclusions>
     </dependency>
    </dependencies>
 

Modified: components/wci/trunk/tomcat-tmp/tomcat6/src/main/java/org/gatein/wci/tomcat/TC6ServletContainerContext.java
===================================================================
--- components/wci/trunk/tomcat/src/main/java/org/gatein/wci/tomcat/TC6ServletContainerContext.java	2010-12-20 16:09:27 UTC (rev 5615)
+++ components/wci/trunk/tomcat-tmp/tomcat6/src/main/java/org/gatein/wci/tomcat/TC6ServletContainerContext.java	2010-12-21 18:31:20 UTC (rev 5619)
@@ -34,6 +34,8 @@
 import org.gatein.common.logging.Logger;
 import org.gatein.common.logging.LoggerFactory;
 import org.gatein.wci.RequestDispatchCallback;
+import org.gatein.wci.authentication.AuthenticationResult;
+import org.gatein.wci.authentication.GenericAuthentication;
 import org.gatein.wci.command.CommandDispatcher;
 import org.gatein.wci.impl.DefaultServletContainerFactory;
 import org.gatein.wci.spi.ServletContainerContext;
@@ -97,6 +99,16 @@
       this.registration = null;
    }
 
+   public AuthenticationResult login(HttpServletRequest request, HttpServletResponse response, String userName, String password, long validityMillis)
+   {
+      return GenericAuthentication.getInstance().login(userName, password, request, response, validityMillis);
+   }
+
+   public void logout(HttpServletRequest request, HttpServletResponse response)
+   {
+      GenericAuthentication.getInstance().logout(request, response);
+   }
+
    public synchronized void containerEvent(ContainerEvent event)
    {
       if (event.getData() instanceof Host)

Added: components/wci/trunk/tomcat-tmp/tomcat7/pom.xml
===================================================================
--- components/wci/trunk/tomcat-tmp/tomcat7/pom.xml	                        (rev 0)
+++ components/wci/trunk/tomcat-tmp/tomcat7/pom.xml	2010-12-21 18:31:20 UTC (rev 5619)
@@ -0,0 +1,24 @@
+<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">
+   <parent>
+      <groupId>org.gatein.wci</groupId>
+      <artifactId>wci-parent</artifactId>
+      <version>2.1.0-Alpha01-SNAPSHOT</version>
+   </parent>
+   <modelVersion>4.0.0</modelVersion>
+   <artifactId>wci-tomcat7</artifactId>
+   <packaging>jar</packaging>
+   <name>GateIn - WCI Tomcat 7 compatibility component</name>
+
+   <dependencies>
+     <dependency>
+       <groupId>org.gatein.wci</groupId>
+       <artifactId>wci-wci</artifactId>
+     </dependency>
+     <dependency>
+      <groupId>org.apache.tomcat</groupId>
+       <artifactId>tomcat-catalina</artifactId>
+       <version>7.0.2</version>
+    </dependency>
+   </dependencies>
+
+</project>

Added: components/wci/trunk/tomcat-tmp/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7ContainerServlet.java
===================================================================
--- components/wci/trunk/tomcat-tmp/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7ContainerServlet.java	                        (rev 0)
+++ components/wci/trunk/tomcat-tmp/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7ContainerServlet.java	2010-12-21 18:31:20 UTC (rev 5619)
@@ -0,0 +1,127 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat                                               *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual                    *
+ * contributors as indicated by the @authors tag. See the                     *
+ * copyright.txt in the distribution for a full listing of                    *
+ * individual contributors.                                                   *
+ *                                                                            *
+ * This is free software; you can redistribute it and/or modify it            *
+ * under the terms of the GNU Lesser General Public License as                *
+ * published by the Free Software Foundation; either version 2.1 of           *
+ * the License, or (at your option) any later version.                        *
+ *                                                                            *
+ * This software is distributed in the hope that it will be useful,           *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU           *
+ * Lesser General Public License for more details.                            *
+ *                                                                            *
+ * You should have received a copy of the GNU Lesser General Public           *
+ * License along with this software; if not, write to the Free                *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA         *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.                   *
+ ******************************************************************************/
+package org.gatein.wci.tomcat;
+
+import org.apache.catalina.Container;
+import org.apache.catalina.ContainerServlet;
+import org.apache.catalina.Engine;
+import org.apache.catalina.Wrapper;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+
+/**
+ * @author <a href="mailto:alain.defrance at exoplatform.com">Alain Defrance</a>
+ * @version $Revision: 1.0 $
+ */
+public class TC7ContainerServlet extends HttpServlet implements ContainerServlet
+{
+
+   /** . */
+   private Wrapper wrapper;
+
+   /** . */
+   private TC7ServletContainerContext containerContext;
+
+   /** . */
+   private boolean started;
+
+   public Wrapper getWrapper()
+   {
+      return wrapper;
+   }
+
+   public void setWrapper(Wrapper wrapper)
+   {
+      this.wrapper = wrapper;
+
+      //
+      if (wrapper != null)
+      {
+         attemptStart();
+      }
+      else
+      {
+         attemptStop();
+      }
+   }
+
+   public void init() throws ServletException
+   {
+      started = true;
+
+      //
+      attemptStart();
+   }
+
+   public void destroy()
+   {
+      started = false;
+
+      //
+      attemptStop();
+   }
+
+   private void attemptStart()
+   {
+      if (started && wrapper != null)
+      {
+         start();
+      }
+   }
+
+   private void attemptStop()
+   {
+      if (!started || wrapper == null)
+      {
+         stop();
+      }
+   }
+
+   private void start()
+   {
+      Container container = wrapper;
+      while (container.getParent() != null)
+      {
+         container = container.getParent();
+         if (container instanceof Engine)
+         {
+            Engine engine = (Engine)container;
+            containerContext = new TC7ServletContainerContext(engine);
+            containerContext.start();
+            break;
+         }
+      }
+   }
+
+   private void stop()
+   {
+      if (containerContext != null)
+      {
+         containerContext.stop();
+
+         //
+         containerContext = null;
+      }
+   }
+}

Added: components/wci/trunk/tomcat-tmp/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7LifecycleListener.java
===================================================================
--- components/wci/trunk/tomcat-tmp/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7LifecycleListener.java	                        (rev 0)
+++ components/wci/trunk/tomcat-tmp/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7LifecycleListener.java	2010-12-21 18:31:20 UTC (rev 5619)
@@ -0,0 +1,97 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat                                               *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual                    *
+ * contributors as indicated by the @authors tag. See the                     *
+ * copyright.txt in the distribution for a full listing of                    *
+ * individual contributors.                                                   *
+ *                                                                            *
+ * This is free software; you can redistribute it and/or modify it            *
+ * under the terms of the GNU Lesser General Public License as                *
+ * published by the Free Software Foundation; either version 2.1 of           *
+ * the License, or (at your option) any later version.                        *
+ *                                                                            *
+ * This software is distributed in the hope that it will be useful,           *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU           *
+ * Lesser General Public License for more details.                            *
+ *                                                                            *
+ * You should have received a copy of the GNU Lesser General Public           *
+ * License along with this software; if not, write to the Free                *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA         *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.                   *
+ ******************************************************************************/
+package org.gatein.wci.tomcat;
+
+import org.apache.catalina.Container;
+import org.apache.catalina.Engine;
+import org.apache.catalina.Lifecycle;
+import org.apache.catalina.LifecycleEvent;
+import org.apache.catalina.LifecycleListener;
+import org.apache.catalina.Server;
+import org.apache.catalina.Service;
+
+/**
+ * @author <a href="mailto:alain.defrance at exoplatform.com">Alain Defrance</a>
+ * @version $Revision: 1.0 $
+ */
+public class TC7LifecycleListener implements LifecycleListener
+{
+
+   /** . */
+   private TC7ServletContainerContext containerContext;
+
+   public synchronized void lifecycleEvent(LifecycleEvent event)
+   {
+      Lifecycle lifecycle = event.getLifecycle();
+
+      //
+      if (lifecycle instanceof Server)
+      {
+         Server server = (Server)lifecycle;
+
+         //
+         Engine engine = getEngine(server);
+
+         //
+         if (engine != null)
+         {
+            if (Lifecycle.START_EVENT.equals(event.getType()))
+            {
+               containerContext = new TC7ServletContainerContext(engine);
+               containerContext.start();
+            }
+            else if (Lifecycle.STOP_EVENT.equals(event.getType()))
+            {
+               if (containerContext != null)
+               {
+                  containerContext.stop();
+               }
+            }
+         }
+      }
+   }
+
+   private Engine getEngine(Server server)
+   {
+      Service[] services = server.findServices();
+      for (int i = 0; i < services.length; i++)
+      {
+         Service service = services[i];
+         Engine engine = getEngine(service.getContainer());
+         if (engine != null)
+         {
+            return engine;
+         }
+      }
+      return null;
+   }
+
+   private Engine getEngine(Container container)
+   {
+      if (container instanceof Engine)
+      {
+         return (Engine)container;
+      }
+      return null;
+   }
+}

Added: components/wci/trunk/tomcat-tmp/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7ServletContainerContext.java
===================================================================
--- components/wci/trunk/tomcat-tmp/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7ServletContainerContext.java	                        (rev 0)
+++ components/wci/trunk/tomcat-tmp/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7ServletContainerContext.java	2010-12-21 18:31:20 UTC (rev 5619)
@@ -0,0 +1,343 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat                                               *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual                    *
+ * contributors as indicated by the @authors tag. See the                     *
+ * copyright.txt in the distribution for a full listing of                    *
+ * individual contributors.                                                   *
+ *                                                                            *
+ * This is free software; you can redistribute it and/or modify it            *
+ * under the terms of the GNU Lesser General Public License as                *
+ * published by the Free Software Foundation; either version 2.1 of           *
+ * the License, or (at your option) any later version.                        *
+ *                                                                            *
+ * This software is distributed in the hope that it will be useful,           *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU           *
+ * Lesser General Public License for more details.                            *
+ *                                                                            *
+ * You should have received a copy of the GNU Lesser General Public           *
+ * License along with this software; if not, write to the Free                *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA         *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.                   *
+ ******************************************************************************/
+package org.gatein.wci.tomcat;
+
+import org.apache.catalina.Container;
+import org.apache.catalina.ContainerEvent;
+import org.apache.catalina.ContainerListener;
+import org.apache.catalina.Context;
+import org.apache.catalina.Engine;
+import org.apache.catalina.Host;
+import org.apache.catalina.Lifecycle;
+import org.apache.catalina.LifecycleEvent;
+import org.apache.catalina.LifecycleListener;
+import org.apache.catalina.LifecycleState;
+import org.apache.catalina.core.StandardContext;
+import org.gatein.common.logging.Logger;
+import org.gatein.common.logging.LoggerFactory;
+import org.gatein.wci.RequestDispatchCallback;
+import org.gatein.wci.authentication.AuthenticationResult;
+import org.gatein.wci.authentication.GenericAuthentication;
+import org.gatein.wci.authentication.GenericAuthenticationResult;
+import org.gatein.wci.authentication.ProgrammaticAuthenticationResult;
+import org.gatein.wci.authentication.TicketService;
+import org.gatein.wci.command.CommandDispatcher;
+import org.gatein.wci.impl.DefaultServletContainerFactory;
+import org.gatein.wci.security.Credentials;
+import org.gatein.wci.spi.ServletContainerContext;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * An implementation of the <code>ServletContainerContext</code> for Tomcat 7.
+ *
+ * @author <a href="mailto:alain.defrance at exoplatform.com">Alain Defrance</a>
+ * @version $Revision: 1.0 $
+ */
+public class TC7ServletContainerContext implements ServletContainerContext, ContainerListener, LifecycleListener
+{
+   private final static Logger log = LoggerFactory.getLogger(TC7ServletContainerContext.class);
+
+   /** . */
+   private final CommandDispatcher dispatcher = new CommandDispatcher("/tomcatgateinservlet");
+
+   /** The monitored hosts. */
+   private final Set<String> monitoredHosts = new HashSet<String>();
+
+   /** The monitored contexts. */
+   private final Set<String> monitoredContexts = new HashSet<String>();
+
+   /** . */
+   private final Engine engine;
+
+   /** . */
+   private Registration registration;
+
+   public TC7ServletContainerContext(Engine engine)
+   {
+      this.engine = engine;
+   }
+
+   public Object include(
+      ServletContext targetServletContext,
+      HttpServletRequest request,
+      HttpServletResponse response,
+      RequestDispatchCallback callback,
+      Object handback) throws ServletException, IOException
+   {
+      return dispatcher.include(targetServletContext, request, response, callback, handback);
+   }
+
+   public void setCallback(Registration registration)
+   {
+      this.registration = registration;
+   }
+
+   public void unsetCallback(Registration registration)
+   {
+      this.registration = null;
+   }
+
+   public AuthenticationResult login(HttpServletRequest request, HttpServletResponse response, String userName, String password, long validityMillis) throws ServletException
+   {
+      try
+      {
+         request.login(userName, password);
+      }
+      catch (ServletException se)
+      {
+         try
+         {
+            String ticket = GenericAuthentication.TICKET_SERVICE.createTicket(new Credentials(userName, password), TicketService.DEFAULT_VALIDITY);
+            String url = "j_security_check?j_username=" + userName + "&j_password=" + ticket;
+            url = response.encodeRedirectURL(url);
+            response.sendRedirect(url);
+            response.flushBuffer();
+         }
+         catch (Exception ignore)
+         {
+         }
+         return null;
+      }
+      return new ProgrammaticAuthenticationResult();
+   }
+
+   public void logout(HttpServletRequest request, HttpServletResponse response) throws ServletException
+   {
+      request.logout();
+      request.getSession().invalidate();
+   }
+
+  public synchronized void containerEvent(ContainerEvent event)
+   {
+      if (event.getData() instanceof Host)
+      {
+         Host host = (Host)event.getData();
+
+         //
+         if (Container.ADD_CHILD_EVENT.equals(event.getType()))
+         {
+            registerHost(host);
+         }
+         else if (Container.REMOVE_CHILD_EVENT.equals(event.getType()))
+         {
+            unregisterHost(host);
+         }
+      }
+      else if (event.getData() instanceof StandardContext)
+      {
+         StandardContext context = (StandardContext)event.getData();
+
+         //
+         if (Container.ADD_CHILD_EVENT.equals(event.getType()))
+         {
+            registerContext(context);
+         }
+         else if (Container.REMOVE_CHILD_EVENT.equals(event.getType()))
+         {
+            unregisterContext(context);
+         }
+      }
+   }
+
+   public void lifecycleEvent(LifecycleEvent event)
+   {
+      if (event.getSource() instanceof Context)
+      {
+         Context context = (Context)event.getSource();
+
+         //
+         if (Lifecycle.AFTER_START_EVENT.equals(event.getType()))
+         {
+            start(context);
+         }
+         else if (Lifecycle.BEFORE_STOP_EVENT.equals(event.getType()))
+         {
+            stop(context);
+         }
+      }
+   }
+
+   void start()
+   {
+      DefaultServletContainerFactory.registerContext(this);
+
+      //
+      Container[] childrenContainers = engine.findChildren();
+      for (Container childContainer : childrenContainers)
+      {
+         if (childContainer instanceof Host)
+         {
+            Host host = (Host)childContainer;
+            registerHost(host);
+         }
+      }
+
+      //
+      engine.addContainerListener(this);
+   }
+
+   void stop()
+   {
+      engine.removeContainerListener(this);
+
+      //
+      Container[] childrenContainers = engine.findChildren();
+      for (Container childContainer : childrenContainers)
+      {
+         if (childContainer instanceof Host)
+         {
+            Host host = (Host)childContainer;
+            unregisterHost(host);
+         }
+      }
+
+      //
+      registration.cancel();
+      registration = null;
+   }
+
+   /**
+    * Register an host for registration which means that we fire events for all the contexts it contains and we
+    * subscribe for its life cycle events. If the host is already monitored nothing is done.
+    *
+    * @param host the host to register for monitoring
+    */
+   private void registerHost(Host host)
+   {
+      if (!monitoredHosts.contains(host.getName()))
+      {
+         Container[] childrenContainers = host.findChildren();
+         for (Container childContainer : childrenContainers)
+         {
+            if (childContainer instanceof StandardContext)
+            {
+               StandardContext context = (StandardContext)childContainer;
+               registerContext(context);
+            }
+         }
+
+         //
+         host.addContainerListener(this);
+
+         //
+         monitoredHosts.add(host.getName());
+      }
+   }
+
+   private void unregisterHost(Host host)
+   {
+      if (monitoredHosts.contains(host.getName()))
+      {
+         monitoredHosts.remove(host.getName());
+
+         //
+         host.removeContainerListener(this);
+
+         //
+         Container[] childrenContainers = host.findChildren();
+         for (Container childContainer : childrenContainers)
+         {
+            if (childContainer instanceof StandardContext)
+            {
+               StandardContext context = (StandardContext)childContainer;
+               unregisterContext(context);
+            }
+         }
+      }
+   }
+
+   private void registerContext(StandardContext context)
+   {
+      if (!monitoredContexts.contains(context.getName()))
+      {
+         context.addLifecycleListener(this);
+
+         //
+         if (LifecycleState.STARTED.equals(context.getState()))
+         {
+            start(context);
+         }
+
+         //
+         monitoredContexts.add(context.getName());
+      }
+   }
+
+   private void unregisterContext(StandardContext context)
+   {
+      if (monitoredContexts.contains(context.getName()))
+      {
+         monitoredContexts.remove(context.getName());
+
+         //
+         if (LifecycleState.STARTED.equals(context.getState()))
+         {
+            stop(context);
+         }
+
+         //
+         context.removeLifecycleListener(this);
+      }
+   }
+
+   private void start(Context context)
+   {
+      try
+      {
+         log.debug("Context added " + context.getPath());
+         TC7WebAppContext webAppContext = new TC7WebAppContext(context);
+
+         //
+         if (registration != null)
+         {
+            registration.registerWebApp(webAppContext);
+         }
+      }
+      catch (Exception e)
+      {
+         e.printStackTrace();
+      }
+   }
+
+   private void stop(Context context)
+   {
+      try
+      {
+         if (registration != null)
+         {
+            registration.unregisterWebApp(context.getPath());
+         }
+      }
+      catch (Exception e)
+      {
+         e.printStackTrace();
+      }
+   }
+}

Added: components/wci/trunk/tomcat-tmp/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7WebAppContext.java
===================================================================
--- components/wci/trunk/tomcat-tmp/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7WebAppContext.java	                        (rev 0)
+++ components/wci/trunk/tomcat-tmp/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7WebAppContext.java	2010-12-21 18:31:20 UTC (rev 5619)
@@ -0,0 +1,127 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat                                               *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual                    *
+ * contributors as indicated by the @authors tag. See the                     *
+ * copyright.txt in the distribution for a full listing of                    *
+ * individual contributors.                                                   *
+ *                                                                            *
+ * This is free software; you can redistribute it and/or modify it            *
+ * under the terms of the GNU Lesser General Public License as                *
+ * published by the Free Software Foundation; either version 2.1 of           *
+ * the License, or (at your option) any later version.                        *
+ *                                                                            *
+ * This software is distributed in the hope that it will be useful,           *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU           *
+ * Lesser General Public License for more details.                            *
+ *                                                                            *
+ * You should have received a copy of the GNU Lesser General Public           *
+ * License along with this software; if not, write to the Free                *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA         *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.                   *
+ ******************************************************************************/
+package org.gatein.wci.tomcat;
+
+import org.apache.catalina.Context;
+import org.apache.catalina.Wrapper;
+import org.gatein.wci.command.CommandServlet;
+import org.gatein.wci.spi.WebAppContext;
+import org.w3c.dom.Document;
+
+import javax.servlet.ServletContext;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * @author <a href="mailto:alain.defrance at exoplatform.com">Alain Defrance</a>
+ * @version $Revision: 1.0 $
+ */
+public class TC7WebAppContext implements WebAppContext
+{
+
+   /** . */
+   private Document descriptor;
+
+   /** . */
+   private ServletContext servletContext;
+
+   /** . */
+   private ClassLoader loader;
+
+   /** . */
+   private String contextPath;
+
+   /** . */
+   private final Context context;
+
+   /** . */
+   private Wrapper commandServlet;
+
+   TC7WebAppContext(Context context) throws Exception
+   {
+      this.context = context;
+
+      //
+      servletContext = context.getServletContext();
+      loader = context.getLoader().getClassLoader();
+      contextPath = context.getPath();
+   }
+
+   public void start() throws Exception
+   {
+      try
+      {
+         commandServlet = context.createWrapper();
+         commandServlet.setName("TomcatGateInServlet");
+         commandServlet.setLoadOnStartup(0);
+         commandServlet.setServletClass(CommandServlet.class.getName());
+         context.addChild(commandServlet);
+         context.addServletMapping("/tomcatgateinservlet", "TomcatGateInServlet");
+      }
+      catch (Exception e)
+      {
+         cleanup();
+         throw e;
+      }
+   }
+
+   public void stop()
+   {
+      cleanup();
+   }
+
+   private void cleanup()
+   {
+      if (commandServlet != null)
+      {
+         try
+         {
+            context.removeServletMapping("tomcatgateinservlet");
+            context.removeChild(commandServlet);
+         }
+         catch (Exception e)
+         {
+         }
+      }
+   }
+
+   public ServletContext getServletContext()
+   {
+      return servletContext;
+   }
+
+   public ClassLoader getClassLoader()
+   {
+      return loader;
+   }
+
+   public String getContextPath()
+   {
+      return contextPath;
+   }
+
+   public boolean importFile(String parentDirRelativePath, String name, InputStream source, boolean overwrite) throws IOException
+   {
+      return false;
+   }
+}

Modified: components/wci/trunk/wci/pom.xml
===================================================================
--- components/wci/trunk/wci/pom.xml	2010-12-21 17:12:17 UTC (rev 5618)
+++ components/wci/trunk/wci/pom.xml	2010-12-21 18:31:20 UTC (rev 5619)
@@ -13,13 +13,12 @@
     <dependency>
       <groupId>org.gatein.common</groupId>
       <artifactId>common-common</artifactId>
-      <exclusions>
-        <exclusion>
-          <groupId>org.codehaus.cargo</groupId>
-          <artifactId>cargo-core-uberjar</artifactId>
-        </exclusion>
-      </exclusions>
     </dependency>
+    <dependency>
+      <groupId>javax.servlet</groupId>
+      <artifactId>servlet-api</artifactId>
+      <scope>provided</scope>
+    </dependency>
   </dependencies>
 
 </project>

Added: components/wci/trunk/wci/src/main/doc/wci-authentication.odp
===================================================================
(Binary files differ)


Property changes on: components/wci/trunk/wci/src/main/doc/wci-authentication.odp
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: components/wci/trunk/wci/src/main/doc/wci-authentication.pdf
===================================================================
(Binary files differ)


Property changes on: components/wci/trunk/wci/src/main/doc/wci-authentication.pdf
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: components/wci/trunk/wci/src/main/java/org/gatein/wci/ServletContainer.java
===================================================================
--- components/wci/trunk/wci/src/main/java/org/gatein/wci/ServletContainer.java	2010-12-21 17:12:17 UTC (rev 5618)
+++ components/wci/trunk/wci/src/main/java/org/gatein/wci/ServletContainer.java	2010-12-21 18:31:20 UTC (rev 5619)
@@ -1,6 +1,6 @@
 /******************************************************************************
  * JBoss, a division of Red Hat                                               *
- * Copyright 2006, Red Hat Middleware, LLC, and individual                    *
+ * Copyright 2010, Red Hat Middleware, LLC, and individual                    *
  * contributors as indicated by the @authors tag. See the                     *
  * copyright.txt in the distribution for a full listing of                    *
  * individual contributors.                                                   *
@@ -22,6 +22,8 @@
  ******************************************************************************/
 package org.gatein.wci;
 
+import org.gatein.wci.authentication.AuthenticationListener;
+import org.gatein.wci.authentication.AuthenticationResult;
 import org.gatein.wci.spi.ServletContainerContext;
 
 import javax.servlet.ServletContext;
@@ -91,4 +93,36 @@
     * @throws IllegalArgumentException if the context is null
     */
    void register(ServletContainerContext context);
+
+   /**
+    * Authentication support.
+    *
+    * @param request the request valid in the current servlet context
+    * @param response the response valid in the current servlet context
+    * @param userName the username which try to login
+    * @param password the password of the username
+    */
+   AuthenticationResult login(HttpServletRequest request, HttpServletResponse response, String userName, String password, long validityMillis) throws ServletException;
+
+   /**
+    * Authentication support.
+    *
+    * @param request the request valid in the current servlet context
+    * @param response the response valid in the current servlet context
+    */
+   void logout(HttpServletRequest request, HttpServletResponse response) throws ServletException;
+
+   /**
+    * Add the authentication listener.
+    *
+    * @param listener AuthenticationListener to add
+    */
+   void addAuthenticationListener(AuthenticationListener listener);
+
+   /**
+    * Remove the authentication listener.
+    *
+    * @param listener AuthenticationListener to remove
+    */
+   void removeAuthenticationlistener(AuthenticationListener listener);
 }

Added: components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/AuthenticationEvent.java
===================================================================
--- components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/AuthenticationEvent.java	                        (rev 0)
+++ components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/AuthenticationEvent.java	2010-12-21 18:31:20 UTC (rev 5619)
@@ -0,0 +1,92 @@
+/*
+* Copyright (C) 2003-2009 eXo Platform SAS.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package org.gatein.wci.authentication;
+
+import org.gatein.wci.security.Credentials;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * @author <a href="mailto:alain.defrance at exoplatform.com">Alain Defrance</a>
+ * @version $Revision$
+ */
+public class AuthenticationEvent
+{
+   private final HttpServletRequest request;
+   private final HttpServletResponse response;
+   private final Credentials credentials;
+
+   public AuthenticationEvent(HttpServletRequest request, HttpServletResponse response)
+   {
+
+      if (request == null)
+      {
+         throw new IllegalArgumentException("request is null");
+      }
+
+      if (response == null)
+      {
+         throw new IllegalArgumentException("response is null");
+      }
+
+      this.request = request;
+      this.response = response;
+      this.credentials = null;
+  }
+
+   public AuthenticationEvent(HttpServletRequest request, HttpServletResponse response, Credentials credentials)
+   {
+
+      if (request == null)
+      {
+         throw new IllegalArgumentException("request is null");
+      }
+
+      if (response == null)
+      {
+         throw new IllegalArgumentException("response is null");
+      }
+
+      if (credentials == null)
+      {
+         throw new IllegalArgumentException("credentials is null");
+      }
+
+      this.request = request;
+      this.response = response;
+      this.credentials = credentials;
+   }
+
+   public HttpServletRequest getRequest()
+   {
+      return request;
+   }
+
+   public HttpServletResponse getResponse()
+   {
+      return response;
+   }
+
+   public Credentials getCredentials()
+   {
+      return credentials;
+   }
+}

Added: components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/AuthenticationException.java
===================================================================
--- components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/AuthenticationException.java	                        (rev 0)
+++ components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/AuthenticationException.java	2010-12-21 18:31:20 UTC (rev 5619)
@@ -0,0 +1,46 @@
+/*
+* Copyright (C) 2003-2009 eXo Platform SAS.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package org.gatein.wci.authentication;
+
+/**
+ * @author <a href="mailto:alain.defrance at exoplatform.com">Alain Defrance</a>
+ * @version $Revision$
+ */
+public class AuthenticationException extends RuntimeException
+{
+   public AuthenticationException()
+   {
+   }
+
+   public AuthenticationException(String message)
+   {
+      super(message);
+   }
+
+   public AuthenticationException(String message, Throwable cause)
+   {
+      super(message, cause);
+   }
+
+   public AuthenticationException(Throwable cause)
+   {
+      super(cause);
+   }
+}

Added: components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/AuthenticationListener.java
===================================================================
--- components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/AuthenticationListener.java	                        (rev 0)
+++ components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/AuthenticationListener.java	2010-12-21 18:31:20 UTC (rev 5619)
@@ -0,0 +1,30 @@
+/*
+* Copyright (C) 2003-2009 eXo Platform SAS.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package org.gatein.wci.authentication;
+
+/**
+ * @author <a href="mailto:alain.defrance at exoplatform.com">Alain Defrance</a>
+ * @version $Revision$
+ */
+public interface AuthenticationListener
+{
+  void onLogin(AuthenticationEvent ae);
+  void onLogout(AuthenticationEvent ae);
+}

Added: components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/AuthenticationResult.java
===================================================================
--- components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/AuthenticationResult.java	                        (rev 0)
+++ components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/AuthenticationResult.java	2010-12-21 18:31:20 UTC (rev 5619)
@@ -0,0 +1,28 @@
+/*
+* Copyright (C) 2003-2009 eXo Platform SAS.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package org.gatein.wci.authentication;
+
+/**
+ * @author <a href="mailto:alain.defrance at exoplatform.com">Alain Defrance</a>
+ * @version $Revision$
+ */
+public abstract class AuthenticationResult
+{
+}

Added: components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/GenericAuthentication.java
===================================================================
--- components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/GenericAuthentication.java	                        (rev 0)
+++ components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/GenericAuthentication.java	2010-12-21 18:31:20 UTC (rev 5619)
@@ -0,0 +1,53 @@
+/*
+* Copyright (C) 2003-2009 eXo Platform SAS.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package org.gatein.wci.authentication;
+
+import org.gatein.wci.security.Credentials;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * @author <a href="mailto:alain.defrance at exoplatform.com">Alain Defrance</a>
+ * @version $Revision$
+ */
+public class GenericAuthentication
+{
+  public static final TicketService TICKET_SERVICE = new TicketService();
+  private static final GenericAuthentication GENERIC_AUTHENTICATION = new GenericAuthentication();
+
+  private GenericAuthentication() {}
+
+  public AuthenticationResult login(String login, String password, HttpServletRequest request, HttpServletResponse response, long validityMillis)
+  {
+     String ticket = TICKET_SERVICE.createTicket(new Credentials(login, password), validityMillis);
+
+     return new GenericAuthenticationResult(login, ticket);
+  }
+
+  public void logout(HttpServletRequest request, HttpServletResponse response)
+  {
+     request.getSession().invalidate();
+  }
+
+  public static GenericAuthentication getInstance() {
+    return GENERIC_AUTHENTICATION;
+  }
+}
\ No newline at end of file

Added: components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/GenericAuthenticationResult.java
===================================================================
--- components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/GenericAuthenticationResult.java	                        (rev 0)
+++ components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/GenericAuthenticationResult.java	2010-12-21 18:31:20 UTC (rev 5619)
@@ -0,0 +1,61 @@
+/*
+* Copyright (C) 2003-2009 eXo Platform SAS.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package org.gatein.wci.authentication;
+
+import org.gatein.wci.impl.DefaultServletContainer;
+import org.gatein.wci.impl.DefaultServletContainerFactory;
+import org.gatein.wci.security.Credentials;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:alain.defrance at exoplatform.com">Alain Defrance</a>
+ * @version $Revision$
+ */
+public class GenericAuthenticationResult extends AuthenticationResult {
+   private String username;
+   private String ticket;
+
+   public GenericAuthenticationResult(String username, String ticket) {
+      this.username = username;
+      this.ticket = ticket;
+   }
+
+   public String getTicket() {
+     return ticket;
+   }
+
+   public void perform(HttpServletRequest req, HttpServletResponse resp) throws IOException
+   {
+      req.getSession().removeAttribute(Credentials.CREDENTIALS);
+      String url = "j_security_check?j_username=" + username + "&j_password=" + ticket;
+      url = resp.encodeRedirectURL(url);
+      resp.sendRedirect(url);
+      resp.flushBuffer();
+
+      Object o = DefaultServletContainerFactory.getInstance().getServletContainer();
+      if (o instanceof DefaultServletContainer)
+      {
+        ((DefaultServletContainer)o).fireEvent(DefaultServletContainer.EventType.LOGIN, new AuthenticationEvent(req, resp, new Credentials(username, ticket)));  
+      }
+   }
+}

Added: components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/ProgrammaticAuthenticationResult.java
===================================================================
--- components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/ProgrammaticAuthenticationResult.java	                        (rev 0)
+++ components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/ProgrammaticAuthenticationResult.java	2010-12-21 18:31:20 UTC (rev 5619)
@@ -0,0 +1,27 @@
+/*
+* Copyright (C) 2003-2009 eXo Platform SAS.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package org.gatein.wci.authentication;
+
+/**
+ * @author <a href="mailto:alain.defrance at exoplatform.com">Alain Defrance</a>
+ * @version $Revision$
+ */
+public class ProgrammaticAuthenticationResult extends AuthenticationResult {
+}

Added: components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/Ticket.java
===================================================================
--- components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/Ticket.java	                        (rev 0)
+++ components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/Ticket.java	2010-12-21 18:31:20 UTC (rev 5619)
@@ -0,0 +1,56 @@
+/*
+* Copyright (C) 2003-2009 eXo Platform SAS.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package org.gatein.wci.authentication;
+
+import org.gatein.wci.security.Credentials;
+
+/**
+ * @author <a href="mailto:alain.defrance at exoplatform.com">Alain Defrance</a>
+ * @version $Revision$
+ */
+public class Ticket
+{
+   /** . */
+   private final long expirationTimeMillis;
+
+   /** . */
+   private final Credentials payload;
+
+   public Ticket(long expirationTimeMillis, Credentials payload)
+   {
+      this.expirationTimeMillis = expirationTimeMillis;
+      this.payload = payload;
+   }
+
+   public long getExpirationTimeMillis()
+   {
+      return expirationTimeMillis;
+   }
+
+   public Credentials getPayload()
+   {
+      return payload;
+   }
+
+   public boolean isExpired()
+   {
+      return System.currentTimeMillis() > expirationTimeMillis;
+   }
+}

Added: components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/TicketService.java
===================================================================
--- components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/TicketService.java	                        (rev 0)
+++ components/wci/trunk/wci/src/main/java/org/gatein/wci/authentication/TicketService.java	2010-12-21 18:31:20 UTC (rev 5619)
@@ -0,0 +1,98 @@
+/*
+* Copyright (C) 2003-2009 eXo Platform SAS.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package org.gatein.wci.authentication;
+
+import org.gatein.wci.security.Credentials;
+
+import java.util.Random;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * @author <a href="mailto:alain.defrance at exoplatform.com">Alain Defrance</a>
+ * @version $Revision$
+ */
+public class TicketService
+{
+   public static final long DEFAULT_VALIDITY = 60 * 1000;
+
+   protected final ConcurrentHashMap<String, Ticket> tickets = new ConcurrentHashMap<String, Ticket>();
+
+   protected final Random random = new Random();
+
+   public String createTicket(Credentials credentials, long validityMillis)
+   {
+      if (validityMillis < 0)
+      {
+         throw new IllegalArgumentException("validityMillis must be positive");
+      }
+      if (credentials == null)
+      {
+         throw new NullPointerException();
+      }
+      String tokenId = nextTicketId();
+      long expirationTimeMillis = System.currentTimeMillis() + validityMillis;
+      tickets.put(tokenId, new Ticket(expirationTimeMillis, credentials));
+      return tokenId;
+   }
+
+   public Credentials validateTicket(String stringKey, boolean remove)
+   {
+      if (stringKey == null)
+      {
+         throw new IllegalArgumentException("stringKey is null");
+      }
+
+      Ticket ticket;
+      if (remove)
+      {
+         ticket = tickets.remove(stringKey);
+      }
+      else
+      {
+         ticket = tickets.get(stringKey);
+      }
+
+      if (ticket != null)
+      {
+         boolean valid = ticket.getExpirationTimeMillis() > System.currentTimeMillis();
+
+         if (valid)
+         {
+            return ticket.getPayload();
+         }
+         else if (!remove)
+         {
+            tickets.remove(stringKey);
+         }
+         if (!valid)
+         {
+            throw new AuthenticationException("Ticket " +  stringKey + " has expired");
+         }
+
+      }
+
+      return null;
+   }
+
+   private String nextTicketId()
+   {
+      return "wci-ticket-" + random.nextInt();
+   }
+}

Modified: components/wci/trunk/wci/src/main/java/org/gatein/wci/impl/DefaultServletContainer.java
===================================================================
--- components/wci/trunk/wci/src/main/java/org/gatein/wci/impl/DefaultServletContainer.java	2010-12-21 17:12:17 UTC (rev 5618)
+++ components/wci/trunk/wci/src/main/java/org/gatein/wci/impl/DefaultServletContainer.java	2010-12-21 18:31:20 UTC (rev 5619)
@@ -1,6 +1,6 @@
 /******************************************************************************
  * JBoss, a division of Red Hat                                               *
- * Copyright 2006, Red Hat Middleware, LLC, and individual                    *
+ * Copyright 2010, Red Hat Middleware, LLC, and individual                    *
  * contributors as indicated by the @authors tag. See the                     *
  * copyright.txt in the distribution for a full listing of                    *
  * individual contributors.                                                   *
@@ -22,6 +22,11 @@
  ******************************************************************************/
 package org.gatein.wci.impl;
 
+import org.gatein.wci.authentication.AuthenticationEvent;
+import org.gatein.wci.authentication.AuthenticationListener;
+import org.gatein.wci.authentication.AuthenticationResult;
+import org.gatein.wci.authentication.GenericAuthenticationResult;
+import org.gatein.wci.security.Credentials;
 import org.gatein.wci.spi.ServletContainerContext;
 import org.gatein.wci.spi.WebAppContext;
 import org.gatein.wci.WebAppListener;
@@ -43,7 +48,9 @@
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 /**
  * A static registry for the servlet container context.
@@ -58,9 +65,12 @@
    /** . */
    private final Object lock = new Object();
 
-   /** The event listeners. */
-   private final ArrayList<WebAppListener> listeners = new ArrayList<WebAppListener>();
+   /** The event webapp listeners. */
+   private final ArrayList<WebAppListener> webAppListeners = new ArrayList<WebAppListener>();
 
+   /** The event authentication Listeners. */
+   private final List<AuthenticationListener> authenticationListeners = new CopyOnWriteArrayList<AuthenticationListener>();
+
    /** The web applications. */
    private final Map<String, WebAppImpl> webAppMap = new HashMap<String, WebAppImpl>();
 
@@ -88,6 +98,44 @@
       }
    }
 
+   /** . */
+   public AuthenticationResult login(HttpServletRequest request, HttpServletResponse response, String userName, String password, long validityMillis) throws ServletException
+   {
+      AuthenticationResult result = registration.context.login(request, response, userName, password, validityMillis);
+
+      //
+      if (!(result instanceof GenericAuthenticationResult))
+      {
+         fireEvent(EventType.LOGIN, new AuthenticationEvent(request, response, new Credentials(userName, password)));
+      }
+
+      return result;
+   }
+
+   public void logout(HttpServletRequest request, HttpServletResponse response) throws ServletException
+   {
+      registration.context.logout(request, response);
+
+      //
+      fireEvent(EventType.LOGOUT, new AuthenticationEvent(request, response));
+   }
+
+   public void addAuthenticationListener(AuthenticationListener listener) {
+      if (listener == null) {
+         throw new IllegalArgumentException("listener is null");
+      }
+      
+      authenticationListeners.add(listener);
+   }
+
+   public void removeAuthenticationlistener(AuthenticationListener listener) {
+      if (listener == null) {
+         throw new IllegalArgumentException("listener is null");
+      }
+      
+      authenticationListeners.remove(listener);
+   }
+
    public WebExecutor getExecutor(HttpServletRequest request, HttpServletResponse response)
    {
       throw new NotYetImplemented();
@@ -101,11 +149,11 @@
          {
             throw new IllegalArgumentException();
          }
-         if (listeners.contains(listener))
+         if (webAppListeners.contains(listener))
          {
             return false;
          }
-         listeners.add(listener);
+         webAppListeners.add(listener);
          for (Object response : webAppMap.values())
          {
             WebApp webApp = (WebApp)response;
@@ -124,7 +172,7 @@
          {
             throw new IllegalArgumentException();
          }
-         if (listeners.remove(listener))
+         if (webAppListeners.remove(listener))
          {
             for (WebApp webApp : webAppMap.values())
             {
@@ -161,12 +209,32 @@
 
    private void fireEvent(WebAppEvent event)
    {
-      for (WebAppListener listener : listeners)
+      for (WebAppListener listener : webAppListeners)
       {
          safeFireEvent(listener, event);
       }
    }
 
+   public void fireEvent(EventType type, AuthenticationEvent ae)
+   {
+      String methodName = String.format(
+            "on%s%s",
+            type.toString().substring(0, 1).toUpperCase(),
+            type.toString().substring(1).toLowerCase()
+      );
+      for (AuthenticationListener currentListener : authenticationListeners)
+      {
+         try
+         {
+            currentListener.getClass().getMethod(methodName, AuthenticationEvent.class).invoke(currentListener, ae);
+         }
+         catch (Exception ignore)
+         {
+            ignore.printStackTrace();
+         }
+      }
+   }
+
    /**
     * Generic detyped request dispatch to a servlet context using the include mechanism.
     *
@@ -198,6 +266,10 @@
       return registration.context.include(targetServletContext, request, response, callback, handback);
    }
 
+   public static enum EventType {
+      LOGIN, LOGOUT
+   }
+
    private static class RegistrationImpl implements ServletContainerContext.Registration
    {
 

Modified: components/wci/trunk/wci/src/main/java/org/gatein/wci/impl/generic/GenericServletContainerContext.java
===================================================================
--- components/wci/trunk/wci/src/main/java/org/gatein/wci/impl/generic/GenericServletContainerContext.java	2010-12-21 17:12:17 UTC (rev 5618)
+++ components/wci/trunk/wci/src/main/java/org/gatein/wci/impl/generic/GenericServletContainerContext.java	2010-12-21 18:31:20 UTC (rev 5619)
@@ -1,6 +1,6 @@
 /******************************************************************************
  * JBoss, a division of Red Hat                                               *
- * Copyright 2006, Red Hat Middleware, LLC, and individual                    *
+ * Copyright 2010, Red Hat Middleware, LLC, and individual                    *
  * contributors as indicated by the @authors tag. See the                     *
  * copyright.txt in the distribution for a full listing of                    *
  * individual contributors.                                                   *
@@ -23,6 +23,8 @@
 package org.gatein.wci.impl.generic;
 
 import org.gatein.wci.RequestDispatchCallback;
+import org.gatein.wci.authentication.AuthenticationResult;
+import org.gatein.wci.authentication.GenericAuthentication;
 import org.gatein.wci.impl.DefaultServletContainerFactory;
 import org.gatein.wci.spi.ServletContainerContext;
 import org.gatein.wci.command.CommandDispatcher;
@@ -128,6 +130,15 @@
       this.registration = null;
    }
 
+   public AuthenticationResult login(HttpServletRequest request, HttpServletResponse response, String userName, String password, long validityMillis)
+   {
+      return GenericAuthentication.getInstance().login(userName, password, request, response, validityMillis);
+   }
+
+   public void logout(HttpServletRequest request, HttpServletResponse response)
+   {
+      GenericAuthentication.getInstance().logout(request, response);
+   }
    //
 
    public void contextInitialized(ServletContextEvent servletContextEvent)

Added: components/wci/trunk/wci/src/main/java/org/gatein/wci/security/Credentials.java
===================================================================
--- components/wci/trunk/wci/src/main/java/org/gatein/wci/security/Credentials.java	                        (rev 0)
+++ components/wci/trunk/wci/src/main/java/org/gatein/wci/security/Credentials.java	2010-12-21 18:31:20 UTC (rev 5619)
@@ -0,0 +1,79 @@
+/*
+* Copyright (C) 2003-2009 eXo Platform SAS.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package org.gatein.wci.security;
+
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:alain.defrance at exoplatform.com">Alain Defrance</a>
+ * @version $Revision$
+ */
+public class Credentials implements Serializable
+{
+   /** . */
+   private final String username;
+
+   /** . */
+   private final String password;
+
+   /** . */
+   public static final String CREDENTIALS = "credentials";
+
+   /**
+    * Construct a new instance.
+    *
+    * @param username the username value
+    * @param password the password value
+    * @throws NullPointerException if any argument is null
+    */
+   public Credentials(String username, String password) throws NullPointerException
+   {
+      if (username == null)
+      {
+         throw new IllegalArgumentException("Username is null");
+      }
+      if (password == null)
+      {
+         throw new IllegalArgumentException("Password is null");
+      }
+      this.username = username;
+      this.password = password;
+   }
+
+   /**
+    * Returns the username.
+    *
+    * @return the username
+    */
+   public String getUsername()
+   {
+      return username;
+   }
+
+   /**
+    * Returns the password.
+    *
+    * @return the password
+    */
+   public String getPassword()
+   {
+      return password;
+   }
+}

Added: components/wci/trunk/wci/src/main/java/org/gatein/wci/security/WCILoginController.java
===================================================================
--- components/wci/trunk/wci/src/main/java/org/gatein/wci/security/WCILoginController.java	                        (rev 0)
+++ components/wci/trunk/wci/src/main/java/org/gatein/wci/security/WCILoginController.java	2010-12-21 18:31:20 UTC (rev 5619)
@@ -0,0 +1,78 @@
+/*
+* Copyright (C) 2003-2009 eXo Platform SAS.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package org.gatein.wci.security;
+
+import org.gatein.common.logging.Logger;
+import org.gatein.common.logging.LoggerFactory;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:alain.defrance at exoplatform.com">Alain Defrance</a>
+ * @version $Revision$
+ */
+public class WCILoginController extends HttpServlet
+{
+   /** . */
+   private static final Logger log = LoggerFactory.getLogger(WCILoginController.class);
+
+   /** . */
+   protected Credentials credentials;
+
+   protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+   {
+      String username = req.getParameter("username");
+      String password = req.getParameter("password");
+
+      if (
+            req.getSession().getAttribute(Credentials.CREDENTIALS) != null
+            && username == null
+            && password == null
+       ) return;
+
+      //
+      if (username == null)
+      {
+         log.error("Tried to access the portal login controller without username provided");
+         resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "No username provided");
+         return;
+      }
+      if (password == null)
+      {
+         log.error("Tried to access the portal login controller without password provided");
+         resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "No password provided");
+         return;
+      }
+
+      //
+      log.debug("Found username and password and set credentials in http session");
+      credentials = new Credentials(username, password);
+      req.getSession().setAttribute(Credentials.CREDENTIALS, credentials);
+   }
+
+   protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+   {
+      doGet(req, resp);
+   }
+}

Added: components/wci/trunk/wci/src/main/java/org/gatein/wci/security/WCILoginModule.java
===================================================================
--- components/wci/trunk/wci/src/main/java/org/gatein/wci/security/WCILoginModule.java	                        (rev 0)
+++ components/wci/trunk/wci/src/main/java/org/gatein/wci/security/WCILoginModule.java	2010-12-21 18:31:20 UTC (rev 5619)
@@ -0,0 +1,89 @@
+/*
+* Copyright (C) 2003-2009 eXo Platform SAS.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package org.gatein.wci.security;
+
+import org.gatein.wci.authentication.GenericAuthentication;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.login.LoginException;
+import javax.security.auth.spi.LoginModule;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:alain.defrance at exoplatform.com">Alain Defrance</a>
+ * @version $Revision$
+ */
+
+public class WCILoginModule implements LoginModule {
+   private Subject subject;
+   private CallbackHandler callbackHandler;
+   private Map sharedState;
+   private Map options;
+   
+   public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options) {
+      this.subject = subject;
+      this.callbackHandler = callbackHandler;
+      this.sharedState = sharedState;
+      this.options = options;
+   }
+
+   /**
+    * @see javax.security.auth.spi.LoginModule#login()
+    */
+   @SuppressWarnings("unchecked")
+   public boolean login() throws LoginException {
+      Callback[] callbacks = new Callback[2];
+      callbacks[0] = new NameCallback("Username");
+      callbacks[1] = new PasswordCallback("Password", false);
+
+      try
+      {
+         callbackHandler.handle(callbacks);
+         String password = new String(((PasswordCallback)callbacks[1]).getPassword());
+
+         Credentials credentials = GenericAuthentication.TICKET_SERVICE.validateTicket(password, true);
+         sharedState.put("javax.security.auth.login.name", credentials.getUsername());
+         sharedState.put("javax.security.auth.login.password", credentials.getPassword());
+      }
+      catch (Exception e)
+      {
+         LoginException le = new LoginException();
+         le.initCause(e);
+         throw le;
+      }
+      return true;
+   }
+
+   public boolean commit() throws LoginException {
+      return true;
+   }
+
+   public boolean abort() throws LoginException {
+      return true;
+   }
+
+   public boolean logout() throws LoginException {
+      return true;
+   }
+}

Modified: components/wci/trunk/wci/src/main/java/org/gatein/wci/spi/ServletContainerContext.java
===================================================================
--- components/wci/trunk/wci/src/main/java/org/gatein/wci/spi/ServletContainerContext.java	2010-12-21 17:12:17 UTC (rev 5618)
+++ components/wci/trunk/wci/src/main/java/org/gatein/wci/spi/ServletContainerContext.java	2010-12-21 18:31:20 UTC (rev 5619)
@@ -1,6 +1,6 @@
 /******************************************************************************
  * JBoss, a division of Red Hat                                               *
- * Copyright 2006, Red Hat Middleware, LLC, and individual                    *
+ * Copyright 2010, Red Hat Middleware, LLC, and individual                    *
  * contributors as indicated by the @authors tag. See the                     *
  * copyright.txt in the distribution for a full listing of                    *
  * individual contributors.                                                   *
@@ -22,14 +22,16 @@
  ******************************************************************************/
 package org.gatein.wci.spi;
 
-import org.gatein.wci.RequestDispatchCallback;
+import java.io.IOException;
 
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-import java.io.IOException;
 
+import org.gatein.wci.RequestDispatchCallback;
+import org.gatein.wci.authentication.AuthenticationResult;
+
 /**
  * Defines the service provider interface for a servlet container. It is an attempt to abstract the non
  * portable services required by a portal with respect to the web container layer.
@@ -74,6 +76,24 @@
    void unsetCallback(Registration registration);
 
    /**
+    * Authentication support.
+    *
+    * @param request the request valid in the current servlet context
+    * @param response the response valid in the current servlet context
+    * @param userName the username which try to login
+    * @param password the password of the username
+    */
+   AuthenticationResult login(HttpServletRequest request, HttpServletResponse response, String userName, String password, long validityMillis) throws ServletException;
+
+   /**
+    * Authentication support.
+    *
+    * @param request the request valid in the current servlet context
+    * @param response the response valid in the current servlet context
+    */
+   void logout(HttpServletRequest request, HttpServletResponse response) throws ServletException;
+
+   /**
     * The callback interface that a servlet container context can obtain from its registration against
     * the <code>org.jboss.portal.web.ServletContainer</code> singleton.
     */



More information about the gatein-commits mailing list