Author: mstruk
Date: 2011-02-24 09:36:44 -0500 (Thu, 24 Feb 2011)
New Revision: 5933
Added:
components/wci/branches/logout/test/core/src/main/java/org/gatein/wci/spi/TestController.java
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/security/WCIController.java
Modified:
components/wci/branches/logout/jboss/jboss6/src/main/java/org/gatein/wci/jboss/JB6ServletContainerContext.java
components/wci/branches/logout/jetty/src/main/java/org/gatein/wci/jetty/Jetty6ServletContainerContext.java
components/wci/branches/logout/test/core/src/main/java/org/gatein/wci/container/ServletContainerContextImpl.java
components/wci/branches/logout/test/core/src/main/java/org/gatein/wci/spi/SPIAuthenticationTestCase.java
components/wci/branches/logout/test/servers/jetty6/pom.xml
components/wci/branches/logout/test/servers/pom.xml
components/wci/branches/logout/tomcat/tomcat6/src/main/java/org/gatein/wci/tomcat/TC6ServletContainerContext.java
components/wci/branches/logout/tomcat/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7ServletContainerContext.java
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/ServletContainer.java
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/authentication/AuthenticationEvent.java
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/authentication/GenericAuthentication.java
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/authentication/TicketService.java
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/impl/DefaultServletContainer.java
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/impl/generic/GenericServletContainerContext.java
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/spi/ServletContainerContext.java
Log:
Merged wci trunk changes up to r5932
Modified:
components/wci/branches/logout/jboss/jboss6/src/main/java/org/gatein/wci/jboss/JB6ServletContainerContext.java
===================================================================
---
components/wci/branches/logout/jboss/jboss6/src/main/java/org/gatein/wci/jboss/JB6ServletContainerContext.java 2011-02-24
10:24:53 UTC (rev 5932)
+++
components/wci/branches/logout/jboss/jboss6/src/main/java/org/gatein/wci/jboss/JB6ServletContainerContext.java 2011-02-24
14:36:44 UTC (rev 5933)
@@ -37,10 +37,7 @@
import org.gatein.wci.RequestDispatchCallback;
import org.gatein.wci.ServletContainerVisitor;
import org.gatein.wci.WebApp;
-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;
@@ -102,21 +99,30 @@
this.registration = null;
}
- public AuthenticationResult login(HttpServletRequest request, HttpServletResponse
response, String userName,
- String password, long validityMillis) throws ServletException
- {
+ public void login(HttpServletRequest request, HttpServletResponse response,
Credentials credentials, long validityMillis) throws ServletException, IOException
+ {
+ login(request, response, credentials, validityMillis, null);
+ }
+
+ public void login(HttpServletRequest request, HttpServletResponse response,
Credentials credentials, long validityMillis, String initialURI) throws ServletException,
IOException
+ {
+ if (initialURI == null)
+ {
+ initialURI = request.getRequestURI();
+ }
try
{
- request.login(userName, password);
+ request.login(credentials.getUsername(), credentials.getPassword());
+ response.sendRedirect(response.encodeRedirectURL(initialURI));
}
catch (ServletException se)
{
se.printStackTrace();
try
{
- String ticket = GenericAuthentication.TICKET_SERVICE.createTicket(new
Credentials(userName, password),
+ String ticket = GenericAuthentication.TICKET_SERVICE.createTicket(new
Credentials(credentials.getUsername(), credentials.getUsername()),
TicketService.DEFAULT_VALIDITY);
- String url = "j_security_check?j_username=" + userName +
"&j_password=" + ticket;
+ String url = "j_security_check?j_username=" +
credentials.getUsername() + "&j_password=" + ticket +
"&initialURI=" + initialURI;
url = response.encodeRedirectURL(url);
response.sendRedirect(url);
response.flushBuffer();
@@ -124,11 +130,10 @@
catch (Exception ignore)
{
}
- return null;
}
- return new ProgrammaticAuthenticationResult();
- }
+ }
+
public void logout(HttpServletRequest request, HttpServletResponse response) throws
ServletException
{
HttpSession sess = request.getSession(false);
@@ -148,6 +153,11 @@
});
}
+ public String getContainerInfo()
+ {
+ return "JBossas/6.x";
+ }
+
public synchronized void containerEvent(ContainerEvent event)
{
if (event.getData() instanceof Host)
Modified:
components/wci/branches/logout/jetty/src/main/java/org/gatein/wci/jetty/Jetty6ServletContainerContext.java
===================================================================
---
components/wci/branches/logout/jetty/src/main/java/org/gatein/wci/jetty/Jetty6ServletContainerContext.java 2011-02-24
10:24:53 UTC (rev 5932)
+++
components/wci/branches/logout/jetty/src/main/java/org/gatein/wci/jetty/Jetty6ServletContainerContext.java 2011-02-24
14:36:44 UTC (rev 5933)
@@ -10,10 +10,10 @@
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.security.Credentials;
import org.gatein.wci.spi.ServletContainerContext;
import org.mortbay.component.Container;
import org.mortbay.component.LifeCycle;
@@ -31,6 +31,9 @@
private Container container;
private Server server;
private ContextHandlerCollection chc;
+
+ /** . */
+ private GenericAuthentication authentication = new GenericAuthentication();
/** The monitored contexts. */
private final Set<String> monitoredContexts = new HashSet<String>();
@@ -49,7 +52,7 @@
HttpServletRequest request, HttpServletResponse response,
RequestDispatchCallback callback, Object handback)
throws ServletException, IOException
- {
+ {
return dispatcher.include(targetServletContext, request, response,
callback, handback);
}
@@ -62,17 +65,27 @@
this.registration = null;
}
- public AuthenticationResult login(HttpServletRequest request, HttpServletResponse
response, String userName, String password, long validityMillis)
+ public void login(HttpServletRequest request, HttpServletResponse response,
Credentials credentials, long validityMillis) throws IOException
{
- return GenericAuthentication.getInstance().login(userName, password, request,
response, validityMillis);
+ authentication.login(credentials, request, response, validityMillis, null);
}
- public void logout(HttpServletRequest request, HttpServletResponse response)
+ public void login(HttpServletRequest request, HttpServletResponse response,
Credentials credentials, long validityMillis, String initialURI) throws IOException
{
- GenericAuthentication.getInstance().logout(request, response);
+ authentication.login(credentials, request, response, validityMillis, initialURI);
}
- public void start()
+ public void logout(HttpServletRequest request, HttpServletResponse response) throws
ServletException
+ {
+ authentication.logout(request, response);
+ }
+
+ public String getContainerInfo()
+ {
+ return "Jetty/6.x";
+ }
+
+ public void start()
{
DefaultServletContainerFactory.registerContext(this);
Modified:
components/wci/branches/logout/test/core/src/main/java/org/gatein/wci/container/ServletContainerContextImpl.java
===================================================================
---
components/wci/branches/logout/test/core/src/main/java/org/gatein/wci/container/ServletContainerContextImpl.java 2011-02-24
10:24:53 UTC (rev 5932)
+++
components/wci/branches/logout/test/core/src/main/java/org/gatein/wci/container/ServletContainerContextImpl.java 2011-02-24
14:36:44 UTC (rev 5933)
@@ -22,7 +22,7 @@
******************************************************************************/
package org.gatein.wci.container;
-import org.gatein.wci.authentication.AuthenticationResult;
+import org.gatein.wci.security.Credentials;
import org.gatein.wci.spi.ServletContainerContext;
import org.gatein.wci.RequestDispatchCallback;
@@ -61,13 +61,23 @@
this.registration = null;
}
- public AuthenticationResult login(HttpServletRequest request, HttpServletResponse
response, String userName, String password, long validityMillis)
+ public void login(HttpServletRequest request, HttpServletResponse response,
Credentials credentials, long validityMillis)
{
throw new UnsupportedOperationException();
-}
+ }
+ public void login(HttpServletRequest request, HttpServletResponse response,
Credentials credentials, long validityMillis, String initialURI)
+ {
+ throw new UnsupportedOperationException();
+ }
+
public void logout(HttpServletRequest request, HttpServletResponse response)
{
throw new UnsupportedOperationException();
}
+
+ public String getContainerInfo()
+ {
+ return "Impl";
+ }
}
Modified:
components/wci/branches/logout/test/core/src/main/java/org/gatein/wci/spi/SPIAuthenticationTestCase.java
===================================================================
---
components/wci/branches/logout/test/core/src/main/java/org/gatein/wci/spi/SPIAuthenticationTestCase.java 2011-02-24
10:24:53 UTC (rev 5932)
+++
components/wci/branches/logout/test/core/src/main/java/org/gatein/wci/spi/SPIAuthenticationTestCase.java 2011-02-24
14:36:44 UTC (rev 5933)
@@ -27,13 +27,11 @@
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.gatein.wci.security.WCIController;
import org.jboss.unit.Failure;
import org.jboss.unit.driver.DriverCommand;
import org.jboss.unit.driver.DriverResponse;
@@ -45,6 +43,8 @@
import javax.servlet.ServletException;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
/**
* @author <a href="mailto:alain.defrance@exoplatform.com">Alain
Defrance</a>
@@ -52,8 +52,6 @@
*/
public class SPIAuthenticationTestCase extends ServletTestCase
{
- private final String username = "foo";
- private final String password = "bar";
/** . */
private ServletContainer container;
@@ -62,100 +60,109 @@
private final Value v = new Value();
/** . */
- private AuthenticationResult result;
+ private WCIController wciController = new TestController();
@Override
public DriverResponse service(TestServlet testServlet, WebRequest req, WebResponse
resp) throws ServletException, IOException
{
+ Credentials credentials = wciController.getCredentials(req, resp);
+
if (getRequestCount() == 0)
{
+ assertEquals("/home", wciController.getInitialURI(req));
+ req.setAttribute("javax.servlet.forward.request_uri",
"/foo");
+ assertEquals("/foo", wciController.getInitialURI(req));
+
+ // Test Ticket Expiration
+ 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(""));
+
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)
+ container.login(req, resp, credentials, TicketService.DEFAULT_VALIDITY);
+
+ if ("Tomcat/7.x".equals(container.getContainerInfo()) ||
"JBossas/6.x".equals(container.getContainerInfo()))
{
- 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(""));
-
-
+ assertEquals("login", v.value);
+ assertNotNull(req.getUserPrincipal());
+ assertTrue(req.isUserInRole("test"));
+ }
+ else
+ {
// Test Ticket Service
- Credentials srcCredentials = new Credentials(username, password);
- String ticket =
GenericAuthentication.TICKET_SERVICE.createTicket(srcCredentials,
TicketService.DEFAULT_VALIDITY);
+ String ticket =
GenericAuthentication.TICKET_SERVICE.createTicket(credentials,
TicketService.DEFAULT_VALIDITY);
Credentials resultCredentials =
GenericAuthentication.TICKET_SERVICE.validateTicket(ticket, false);
- assertEquals(srcCredentials.getUsername(), resultCredentials.getUsername());
- assertEquals(srcCredentials.getPassword(), resultCredentials.getPassword());
+ assertEquals(credentials.getUsername(), resultCredentials.getUsername());
+ assertEquals(credentials.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);
+ Map<String, String[]> params = new HashMap<String, String[]>();
+ params.put("initialURI", new String[]{"/bar"});
+ String url = resp.renderURL("/", params, null);
return new InvokeGetResponse(url);
}
else if (getRequestCount() == 1)
{
- if (result instanceof GenericAuthenticationResult)
+ assertEquals("/bar", wciController.getInitialURI(req));
+
+ if ("Tomcat/7.x".equals(container.getContainerInfo()) ||
"JBossas/6.x".equals(container.getContainerInfo()))
{
- // 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);
+ assertNull(req.getUserPrincipal());
}
- else if (result instanceof ProgrammaticAuthenticationResult)
+ else
{
+ // 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);
- assertNull(req.getUserPrincipal());
}
+
+ String url = resp.renderURL("/", null, null);
+ return new InvokeGetResponse(url);
+ }
+ else if (getRequestCount() == 2)
+ {
+ assertEquals(
+ "/home/j_security_check?j_username=foo&j_password=bar",
+ wciController.getAuthURI(req, resp, credentials.getUsername(),
credentials.getPassword())
+ );
+ wciController.sendAuth(req, resp, credentials.getUsername(),
credentials.getPassword());
+ assertTrue(resp.isCommitted());
return new EndTestResponse();
}
- return new FailureResponse(Failure.createAssertionFailure(""));
+ return new FailureResponse(Failure.createAssertionFailure("End test
reached"));
}
@Override
Added:
components/wci/branches/logout/test/core/src/main/java/org/gatein/wci/spi/TestController.java
===================================================================
---
components/wci/branches/logout/test/core/src/main/java/org/gatein/wci/spi/TestController.java
(rev 0)
+++
components/wci/branches/logout/test/core/src/main/java/org/gatein/wci/spi/TestController.java 2011-02-24
14:36:44 UTC (rev 5933)
@@ -0,0 +1,57 @@
+/*
+* 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.security.Credentials;
+import org.gatein.wci.security.WCIController;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:alain.defrance@exoplatform.com">Alain
Defrance</a>
+ * @version $Revision$
+ */
+public class TestController extends WCIController
+{
+ @Override
+ public void showLoginForm(final HttpServletRequest req, final HttpServletResponse
resp) throws ServletException, IOException
+ {
+ }
+
+ @Override
+ public void showErrorLoginForm(final HttpServletRequest req, final HttpServletResponse
resp) throws ServletException, IOException
+ {
+ }
+
+ @Override
+ public Credentials getCredentials(final HttpServletRequest req, final
HttpServletResponse resp)
+ {
+ return new Credentials("foo", "bar");
+ }
+
+ @Override
+ public String getHomeURI(final HttpServletRequest req)
+ {
+ return "/home";
+ }
+}
Modified: components/wci/branches/logout/test/servers/jetty6/pom.xml
===================================================================
--- components/wci/branches/logout/test/servers/jetty6/pom.xml 2011-02-24 10:24:53 UTC
(rev 5932)
+++ components/wci/branches/logout/test/servers/jetty6/pom.xml 2011-02-24 14:36:44 UTC
(rev 5933)
@@ -2,7 +2,7 @@
<parent>
<groupId>org.gatein.wci</groupId>
<artifactId>wci-test-server-parent</artifactId>
- <version>2.1.0-Beta01-SNAPSHOT</version>
+ <version>2.1.0-Alpha04-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>wci-test-jetty6</artifactId>
Modified: components/wci/branches/logout/test/servers/pom.xml
===================================================================
--- components/wci/branches/logout/test/servers/pom.xml 2011-02-24 10:24:53 UTC (rev
5932)
+++ components/wci/branches/logout/test/servers/pom.xml 2011-02-24 14:36:44 UTC (rev
5933)
@@ -65,9 +65,9 @@
<modules>
<module>tomcat6</module>
<module>tomcat7</module>
- <module>jboss42</module>
<module>jboss51</module>
<module>jboss6</module>
+ <module>jetty6</module>
</modules>
</profile>
<profile>
@@ -77,7 +77,6 @@
<module>tomcat7</module>
<module>jboss42</module>
<module>jboss51</module>
- <module>jboss6</module>
<module>jetty6</module>
</modules>
</profile>
Modified:
components/wci/branches/logout/tomcat/tomcat6/src/main/java/org/gatein/wci/tomcat/TC6ServletContainerContext.java
===================================================================
---
components/wci/branches/logout/tomcat/tomcat6/src/main/java/org/gatein/wci/tomcat/TC6ServletContainerContext.java 2011-02-24
10:24:53 UTC (rev 5932)
+++
components/wci/branches/logout/tomcat/tomcat6/src/main/java/org/gatein/wci/tomcat/TC6ServletContainerContext.java 2011-02-24
14:36:44 UTC (rev 5933)
@@ -36,10 +36,11 @@
import org.gatein.wci.RequestDispatchCallback;
import org.gatein.wci.ServletContainerVisitor;
import org.gatein.wci.WebApp;
-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.security.Credentials;
import org.gatein.wci.spi.ServletContainerContext;
import org.apache.catalina.core.StandardContext;
@@ -80,6 +81,9 @@
/** perform cross context session invalidation on logout, or not */
private boolean invalidateSessionInAllCtx = true;
+ /** . */
+ private GenericAuthentication authentication = new GenericAuthentication();
+
public TC6ServletContainerContext(Engine engine)
{
this.engine = engine;
@@ -105,11 +109,16 @@
this.registration = null;
}
- public AuthenticationResult login(HttpServletRequest request, HttpServletResponse
response, String userName, String password, long validityMillis)
+ public void login(HttpServletRequest request, HttpServletResponse response,
Credentials credentials, long validityMillis) throws IOException
{
- return GenericAuthentication.getInstance().login(userName, password, request,
response, validityMillis);
+ authentication.login(credentials, request, response, validityMillis);
}
+ public void login(HttpServletRequest request, HttpServletResponse response,
Credentials credentials, long validityMillis, String initialURI) throws IOException
+ {
+ authentication.login(credentials, request, response, validityMillis, initialURI);
+ }
+
public void logout(HttpServletRequest request, HttpServletResponse response)
{
HttpSession sess = request.getSession(false);
@@ -132,6 +141,11 @@
});
}
+ public String getContainerInfo()
+ {
+ return "Tomcat/6.x";
+ }
+
public synchronized void containerEvent(ContainerEvent event)
{
if (event.getData() instanceof Host)
Modified:
components/wci/branches/logout/tomcat/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7ServletContainerContext.java
===================================================================
---
components/wci/branches/logout/tomcat/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7ServletContainerContext.java 2011-02-24
10:24:53 UTC (rev 5932)
+++
components/wci/branches/logout/tomcat/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7ServletContainerContext.java 2011-02-24
14:36:44 UTC (rev 5933)
@@ -38,10 +38,9 @@
import org.gatein.wci.RequestDispatchCallback;
import org.gatein.wci.ServletContainerVisitor;
import org.gatein.wci.WebApp;
-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;
@@ -107,18 +106,28 @@
this.registration = null;
}
- public AuthenticationResult login(HttpServletRequest request, HttpServletResponse
response, String userName, String password, long validityMillis) throws ServletException
+ public void login(HttpServletRequest request, HttpServletResponse response,
Credentials credentials, long validityMillis) throws ServletException, IOException
{
+ login(request, response, credentials, validityMillis, null);
+ }
+
+ public void login(HttpServletRequest request, HttpServletResponse response,
Credentials credentials, long validityMillis, String initialURI) throws ServletException,
IOException
+ {
+ if (initialURI == null)
+ {
+ initialURI = request.getRequestURI();
+ }
try
{
- request.login(userName, password);
+ request.login(credentials.getUsername(), credentials.getPassword());
+ response.sendRedirect(response.encodeRedirectURL(initialURI));
}
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;
+ String ticket = GenericAuthentication.TICKET_SERVICE.createTicket(new
Credentials(credentials.getUsername(), credentials.getPassword()),
TicketService.DEFAULT_VALIDITY);
+ String url = "j_security_check?j_username=" +
credentials.getUsername() + "&j_password=" + ticket +
"&initialURI=" + initialURI;
url = response.encodeRedirectURL(url);
response.sendRedirect(url);
response.flushBuffer();
@@ -126,9 +135,7 @@
catch (Exception ignore)
{
}
- return null;
}
- return new ProgrammaticAuthenticationResult();
}
public void logout(HttpServletRequest request, HttpServletResponse response) throws
ServletException
@@ -150,8 +157,13 @@
});
}
- public synchronized void containerEvent(ContainerEvent event)
+ public String getContainerInfo()
{
+ return "Tomcat/7.x";
+ }
+
+ public synchronized void containerEvent(ContainerEvent event)
+ {
if (event.getData() instanceof Host)
{
Host host = (Host)event.getData();
Modified:
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/ServletContainer.java
===================================================================
---
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/ServletContainer.java 2011-02-24
10:24:53 UTC (rev 5932)
+++
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/ServletContainer.java 2011-02-24
14:36:44 UTC (rev 5933)
@@ -23,7 +23,7 @@
package org.gatein.wci;
import org.gatein.wci.authentication.AuthenticationListener;
-import org.gatein.wci.authentication.AuthenticationResult;
+import org.gatein.wci.security.Credentials;
import org.gatein.wci.spi.ServletContainerContext;
import javax.servlet.ServletContext;
@@ -99,17 +99,25 @@
*
* @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
+ * @param credentials the credentials which try to authenticate
*/
- AuthenticationResult login(HttpServletRequest request, HttpServletResponse response,
String userName, String password, long validityMillis) throws ServletException;
+ void login(HttpServletRequest request, HttpServletResponse response, Credentials
credentials, long validityMillis) throws ServletException, IOException;
/**
* Authentication support.
*
* @param request the request valid in the current servlet context
* @param response the response valid in the current servlet context
+ * @param credentials the credentials which try to authenticate
*/
+ void login(HttpServletRequest request, HttpServletResponse response, Credentials
credentials, long validityMillis, String initialURI) throws ServletException,
IOException;
+
+ /**
+ * 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;
/**
@@ -127,9 +135,21 @@
void removeAuthenticationlistener(AuthenticationListener listener);
/**
+ * Returns the name and version of the servlet container in which the
+ * context is running.
+ *
+ * <P>
+ * The form of the returned string is
<code>containername/versionnumber</code>.
+ *
+ *
+ * @return the string containing at least name and version number
+ */
+ public String getContainerInfo();
+
+ /**
* Visit the registered WebApps
*
* @param visitor ServletContainerVisitor instance
*/
- void visit(ServletContainerVisitor visitor);
+ void visit(ServletContainerVisitor visitor);
}
Modified:
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/authentication/AuthenticationEvent.java
===================================================================
---
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/authentication/AuthenticationEvent.java 2011-02-24
10:24:53 UTC (rev 5932)
+++
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/authentication/AuthenticationEvent.java 2011-02-24
14:36:44 UTC (rev 5933)
@@ -19,7 +19,9 @@
package org.gatein.wci.authentication;
+import org.gatein.wci.ServletContainer;
import org.gatein.wci.security.Credentials;
+import org.gatein.wci.spi.ServletContainerContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -33,8 +35,9 @@
private final HttpServletRequest request;
private final HttpServletResponse response;
private final Credentials credentials;
+ private final ServletContainerContext containerContext;
- public AuthenticationEvent(HttpServletRequest request, HttpServletResponse response)
+ public AuthenticationEvent(HttpServletRequest request, HttpServletResponse response,
ServletContainerContext containerContext)
{
if (request == null)
@@ -47,12 +50,18 @@
throw new IllegalArgumentException("response is null");
}
+ if (containerContext == null)
+ {
+ throw new IllegalArgumentException("containerContext is null");
+ }
+
this.request = request;
this.response = response;
this.credentials = null;
+ this.containerContext = containerContext;
}
- public AuthenticationEvent(HttpServletRequest request, HttpServletResponse response,
Credentials credentials)
+ public AuthenticationEvent(HttpServletRequest request, HttpServletResponse response,
Credentials credentials, ServletContainerContext containerContext)
{
if (request == null)
@@ -70,9 +79,15 @@
throw new IllegalArgumentException("credentials is null");
}
+ if (containerContext == null)
+ {
+ throw new IllegalArgumentException("container is null");
+ }
+
this.request = request;
this.response = response;
this.credentials = credentials;
+ this.containerContext = containerContext;
}
public HttpServletRequest getRequest()
@@ -89,4 +104,9 @@
{
return credentials;
}
+
+ public ServletContainerContext getContainerContext()
+ {
+ return containerContext;
+ }
}
Modified:
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/authentication/GenericAuthentication.java
===================================================================
---
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/authentication/GenericAuthentication.java 2011-02-24
10:24:53 UTC (rev 5932)
+++
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/authentication/GenericAuthentication.java 2011-02-24
14:36:44 UTC (rev 5933)
@@ -23,6 +23,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
/**
* @author <a href="mailto:alain.defrance@exoplatform.com">Alain
Defrance</a>
@@ -31,23 +32,29 @@
public class GenericAuthentication
{
public static final TicketService TICKET_SERVICE = new TicketService();
- private static final GenericAuthentication GENERIC_AUTHENTICATION = new
GenericAuthentication();
- private GenericAuthentication() {}
+ public void login(Credentials credentials, HttpServletRequest request,
HttpServletResponse response, long validityMillis) throws IOException
+ {
+ login(credentials, request, response, validityMillis, null);
+ }
- public AuthenticationResult login(String login, String password, HttpServletRequest
request, HttpServletResponse response, long validityMillis)
+ public void login(Credentials credentials, HttpServletRequest request,
HttpServletResponse response, long validityMillis, String initialURI) throws IOException
{
- String ticket = TICKET_SERVICE.createTicket(new Credentials(login, password),
validityMillis);
+ String ticket = TICKET_SERVICE.createTicket(new
Credentials(credentials.getUsername(), credentials.getPassword()), validityMillis);
- return new GenericAuthenticationResult(login, ticket);
+ request.getSession().removeAttribute(Credentials.CREDENTIALS);
+
+ if (initialURI == null) {
+ initialURI = request.getRequestURI();
+ }
+ String url = "j_security_check?j_username=" + credentials.getUsername() +
"&j_password=" + ticket + "&initialURI=" + initialURI;
+ url = response.encodeRedirectURL(url);
+ response.sendRedirect(url);
+ response.flushBuffer();
}
public void logout(HttpServletRequest request, HttpServletResponse response)
{
request.getSession().invalidate();
}
-
- public static GenericAuthentication getInstance() {
- return GENERIC_AUTHENTICATION;
- }
}
\ No newline at end of file
Modified:
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/authentication/TicketService.java
===================================================================
---
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/authentication/TicketService.java 2011-02-24
10:24:53 UTC (rev 5932)
+++
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/authentication/TicketService.java 2011-02-24
14:36:44 UTC (rev 5933)
@@ -44,7 +44,7 @@
}
if (credentials == null)
{
- throw new NullPointerException();
+ throw new IllegalArgumentException("credentials is null");
}
String tokenId = nextTicketId();
long expirationTimeMillis = System.currentTimeMillis() + validityMillis;
Modified:
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/impl/DefaultServletContainer.java
===================================================================
---
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/impl/DefaultServletContainer.java 2011-02-24
10:24:53 UTC (rev 5932)
+++
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/impl/DefaultServletContainer.java 2011-02-24
14:36:44 UTC (rev 5933)
@@ -25,8 +25,6 @@
import org.gatein.wci.ServletContainerVisitor;
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;
@@ -100,17 +98,18 @@
}
/** . */
- public AuthenticationResult login(HttpServletRequest request, HttpServletResponse
response, String userName, String password, long validityMillis) throws ServletException
+ public void login(HttpServletRequest request, HttpServletResponse response,
Credentials credentials, long validityMillis) throws ServletException, IOException
{
- AuthenticationResult result = registration.context.login(request, response,
userName, password, validityMillis);
+ login(request, response, credentials, validityMillis, null);
+ }
+ /** . */
+ public void login(HttpServletRequest request, HttpServletResponse response,
Credentials credentials, long validityMillis, String initialURI) throws ServletException,
IOException
+ {
+ registration.context.login(request, response, credentials, validityMillis,
initialURI);
+
//
- if (!(result instanceof GenericAuthenticationResult))
- {
- fireEvent(EventType.LOGIN, new AuthenticationEvent(request, response, new
Credentials(userName, password)));
- }
-
- return result;
+ fireEvent(EventType.LOGIN, new AuthenticationEvent(request, response, credentials,
registration.context));
}
public void logout(HttpServletRequest request, HttpServletResponse response) throws
ServletException
@@ -118,7 +117,7 @@
registration.context.logout(request, response);
//
- fireEvent(EventType.LOGOUT, new AuthenticationEvent(request, response));
+ fireEvent(EventType.LOGOUT, new AuthenticationEvent(request, response,
registration.context));
}
public void addAuthenticationListener(AuthenticationListener listener) {
@@ -137,6 +136,11 @@
authenticationListeners.remove(listener);
}
+ public String getContainerInfo()
+ {
+ return registration.context.getContainerInfo();
+ }
+
public WebExecutor getExecutor(HttpServletRequest request, HttpServletResponse
response)
{
throw new NotYetImplemented();
Modified:
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/impl/generic/GenericServletContainerContext.java
===================================================================
---
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/impl/generic/GenericServletContainerContext.java 2011-02-24
10:24:53 UTC (rev 5932)
+++
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/impl/generic/GenericServletContainerContext.java 2011-02-24
14:36:44 UTC (rev 5933)
@@ -23,9 +23,9 @@
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.security.Credentials;
import org.gatein.wci.spi.ServletContainerContext;
import org.gatein.wci.command.CommandDispatcher;
@@ -54,6 +54,9 @@
private static GenericServletContainerContext instance;
private static HashMap<ServletContext, String> requestDispatchMap = new
HashMap<ServletContext, String>();
+
+ /** . */
+ private GenericAuthentication authentication = new GenericAuthentication();
public static GenericServletContainerContext getInstance()
{
@@ -99,7 +102,6 @@
}
/** . */
- //private final CommandDispatcher dispatcher = new
CommandDispatcher("/gateinservlet");
public Object include(
ServletContext targetServletContext,
@@ -130,15 +132,26 @@
this.registration = null;
}
- public AuthenticationResult login(HttpServletRequest request, HttpServletResponse
response, String userName, String password, long validityMillis)
+ public void login(HttpServletRequest request, HttpServletResponse response,
Credentials credentials, long validityMillis) throws IOException
{
- return GenericAuthentication.getInstance().login(userName, password, request,
response, validityMillis);
+ authentication.login(credentials, request, response, validityMillis);
}
- public void logout(HttpServletRequest request, HttpServletResponse response)
+ public void login(HttpServletRequest request, HttpServletResponse response,
Credentials credentials, long validityMillis, String initialURI) throws IOException
{
- GenericAuthentication.getInstance().logout(request, response);
+ authentication.login(credentials, request, response, validityMillis, initialURI);
}
+
+ public void logout(HttpServletRequest request, HttpServletResponse response) throws
ServletException
+ {
+ authentication.logout(request, response);
+ }
+
+ public String getContainerInfo()
+ {
+ return "Generic";
+ }
+
//
public void contextInitialized(ServletContextEvent servletContextEvent)
Added:
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/security/WCIController.java
===================================================================
---
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/security/WCIController.java
(rev 0)
+++
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/security/WCIController.java 2011-02-24
14:36:44 UTC (rev 5933)
@@ -0,0 +1,67 @@
+/*
+* 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 javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:alain.defrance@exoplatform.com">Alain
Defrance</a>
+ * @version $Revision$
+ */
+public abstract class WCIController
+{
+ public void sendAuth(HttpServletRequest req, HttpServletResponse resp, String
jUsername, String jPassword) throws IOException
+ {
+ resp.sendRedirect(getAuthURI(req, resp, jUsername, jPassword));
+ }
+
+ public String getInitialURI(HttpServletRequest req)
+ {
+ String initialURI = req.getParameter("initialURI");
+ if (initialURI == null)
+ {
+ initialURI =
(String)req.getAttribute("javax.servlet.forward.request_uri");
+ }
+ if (initialURI == null)
+ {
+ initialURI = getHomeURI(req);
+ }
+ return initialURI;
+ }
+
+ public String getAuthURI(HttpServletRequest req, HttpServletResponse resp, String
jUsername, String jPassword)
+ {
+ String initialURI = getInitialURI(req);
+ if (!initialURI.endsWith("/"))
+ {
+ initialURI += "/";
+ }
+ String url = initialURI + "j_security_check?j_username=" + jUsername +
"&j_password=" + jPassword;
+ return resp.encodeRedirectURL(url);
+ }
+
+ abstract public void showLoginForm(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException;
+ abstract public void showErrorLoginForm(HttpServletRequest req, HttpServletResponse
resp) throws ServletException, IOException;
+ abstract public Credentials getCredentials (HttpServletRequest req,
HttpServletResponse resp);
+ abstract public String getHomeURI(HttpServletRequest req);
+}
Modified:
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/spi/ServletContainerContext.java
===================================================================
---
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/spi/ServletContainerContext.java 2011-02-24
10:24:53 UTC (rev 5932)
+++
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/spi/ServletContainerContext.java 2011-02-24
14:36:44 UTC (rev 5933)
@@ -30,7 +30,7 @@
import javax.servlet.http.HttpServletResponse;
import org.gatein.wci.RequestDispatchCallback;
-import org.gatein.wci.authentication.AuthenticationResult;
+import org.gatein.wci.security.Credentials;
/**
* Defines the service provider interface for a servlet container. It is an attempt to
abstract the non
@@ -80,19 +80,41 @@
*
* @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
+ * @param credentials the credentials which try to authenticate
+ * @param validityMillis the validity of the authentication
*/
- AuthenticationResult login(HttpServletRequest request, HttpServletResponse response,
String userName, String password, long validityMillis) throws ServletException;
+ void login(HttpServletRequest request, HttpServletResponse response, Credentials
credentials, long validityMillis) throws ServletException, IOException;
/**
* Authentication support.
*
* @param request the request valid in the current servlet context
* @param response the response valid in the current servlet context
+ * @param credentials the credentials which try to authenticate
+ * @param validityMillis the validity of the authentication
*/
+ void login(HttpServletRequest request, HttpServletResponse response, Credentials
credentials, long validityMillis, String initialURI) throws ServletException,
IOException;
+
+ /**
+ * 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;
+ /**
+ * Returns the name and version of the servlet container in which the
+ * context is running.
+ *
+ * <P>
+ * The form of the returned string is
<code>containername/versionnumber</code>.
+ *
+ *
+ * @return the string containing at least name and version number
+ */
+ public String getContainerInfo();
+
/**
* The callback interface that a servlet container context can obtain from its
registration against
* the <code>org.jboss.portal.web.ServletContainer</code> singleton.