Author: alain_defrance
Date: 2010-10-01 05:50:50 -0400 (Fri, 01 Oct 2010)
New Revision: 4456
Removed:
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/AuthenticationListenerSupport.java
Modified:
components/wci/branches/adf/jetty/src/main/java/org/gatein/wci/jetty/Jetty6ServletContainerContext.java
components/wci/branches/adf/test/core/src/main/java/org/gatein/wci/authentication/AuthenticationTestCase.java
components/wci/branches/adf/test/core/src/main/java/org/gatein/wci/container/ServletContainerContextImpl.java
components/wci/branches/adf/tomcat6/src/main/java/org/gatein/wci/tomcat/TC6ServletContainerContext.java
components/wci/branches/adf/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7ServletContainerContext.java
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/ServletContainer.java
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/AuthenticationEvent.java
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/impl/DefaultServletContainer.java
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/impl/generic/GenericServletContainerContext.java
Log:
authentication events refactoring
Modified:
components/wci/branches/adf/jetty/src/main/java/org/gatein/wci/jetty/Jetty6ServletContainerContext.java
===================================================================
---
components/wci/branches/adf/jetty/src/main/java/org/gatein/wci/jetty/Jetty6ServletContainerContext.java 2010-10-01
08:44:53 UTC (rev 4455)
+++
components/wci/branches/adf/jetty/src/main/java/org/gatein/wci/jetty/Jetty6ServletContainerContext.java 2010-10-01
09:50:50 UTC (rev 4456)
@@ -10,8 +10,6 @@
import javax.servlet.http.HttpServletResponse;
import org.gatein.wci.RequestDispatchCallback;
-import org.gatein.wci.authentication.AuthenticationEvent;
-import org.gatein.wci.authentication.AuthenticationListenerSupport;
import org.gatein.wci.authentication.AuthenticationResult;
import org.gatein.wci.authentication.GenericAuthentication;
import org.gatein.wci.command.CommandDispatcher;
@@ -33,7 +31,6 @@
private Container container;
private Server server;
private ContextHandlerCollection chc;
- private AuthenticationListenerSupport listenerSupport = new
AuthenticationListenerSupport();
/** The monitored contexts. */
private final Set<String> monitoredContexts = new HashSet<String>();
@@ -65,29 +62,15 @@
this.registration = null;
}
- public AuthenticationResult login(HttpServletRequest request, HttpServletResponse
response, String userName, String password) {
- AuthenticationResult result = GenericAuthentication.getInstance().login(userName,
password, request, response);
+ public AuthenticationResult login(HttpServletRequest request, HttpServletResponse
response, String userName, String password) {
+ return GenericAuthentication.getInstance().login(userName, password, request,
response);
+ }
- //
- listenerSupport.fireEvent(
- AuthenticationListenerSupport.EventType.LOGIN,
- new AuthenticationEvent(AuthenticationListenerSupport.EventType.LOGIN, request,
response, userName, password
- ));
+ public void logout(HttpServletRequest request, HttpServletResponse response) {
+ GenericAuthentication.getInstance().logout(request, response);
+ }
- return result;
- }
- public void logout(HttpServletRequest request, HttpServletResponse response) {
- GenericAuthentication.getInstance().logout(request, response);
-
- //
- listenerSupport.fireEvent(
- AuthenticationListenerSupport.EventType.LOGOUT,
- new AuthenticationEvent(AuthenticationListenerSupport.EventType.LOGOUT, request,
response
- ));
- }
-
-
public void start()
{
DefaultServletContainerFactory.registerContext(this);
Modified:
components/wci/branches/adf/test/core/src/main/java/org/gatein/wci/authentication/AuthenticationTestCase.java
===================================================================
---
components/wci/branches/adf/test/core/src/main/java/org/gatein/wci/authentication/AuthenticationTestCase.java 2010-10-01
08:44:53 UTC (rev 4455)
+++
components/wci/branches/adf/test/core/src/main/java/org/gatein/wci/authentication/AuthenticationTestCase.java 2010-10-01
09:50:50 UTC (rev 4456)
@@ -21,6 +21,9 @@
import org.jboss.unit.api.pojo.annotations.Test;
+import static org.jboss.unit.api.Assert.*;
+
+
/**
* @author <a href="mailto:alain.defrance@exoplatform.com">Alain
Defrance</a>
* @version $Revision$
@@ -32,6 +35,11 @@
TicketService tService = GenericAuthentication.TICKET_SERVICE;
WCICredentials credentials = new WCICredentials("foo", "bar");
String strTicket = tService.createTicket(credentials);
+ WCICredentials credentialsFromTs = tService.validateToken(strTicket, false);
+ assertEquals(credentials.getUsername(), credentialsFromTs.getUsername());
+ assertEquals(credentials.getPassword(), credentialsFromTs.getPassword());
+ assertNotNull(tService.validateToken(strTicket, true));
+ assertNull(tService.validateToken(strTicket, true));
}
Modified:
components/wci/branches/adf/test/core/src/main/java/org/gatein/wci/container/ServletContainerContextImpl.java
===================================================================
---
components/wci/branches/adf/test/core/src/main/java/org/gatein/wci/container/ServletContainerContextImpl.java 2010-10-01
08:44:53 UTC (rev 4455)
+++
components/wci/branches/adf/test/core/src/main/java/org/gatein/wci/container/ServletContainerContextImpl.java 2010-10-01
09:50:50 UTC (rev 4456)
@@ -22,10 +22,7 @@
******************************************************************************/
package org.gatein.wci.container;
-import org.gatein.wci.authentication.AuthenticationEvent;
-import org.gatein.wci.authentication.AuthenticationListenerSupport;
import org.gatein.wci.authentication.AuthenticationResult;
-import org.gatein.wci.authentication.GenericAuthentication;
import org.gatein.wci.spi.ServletContainerContext;
import org.gatein.wci.RequestDispatchCallback;
Modified:
components/wci/branches/adf/tomcat6/src/main/java/org/gatein/wci/tomcat/TC6ServletContainerContext.java
===================================================================
---
components/wci/branches/adf/tomcat6/src/main/java/org/gatein/wci/tomcat/TC6ServletContainerContext.java 2010-10-01
08:44:53 UTC (rev 4455)
+++
components/wci/branches/adf/tomcat6/src/main/java/org/gatein/wci/tomcat/TC6ServletContainerContext.java 2010-10-01
09:50:50 UTC (rev 4456)
@@ -34,8 +34,6 @@
import org.gatein.common.logging.Logger;
import org.gatein.common.logging.LoggerFactory;
import org.gatein.wci.RequestDispatchCallback;
-import org.gatein.wci.authentication.AuthenticationEvent;
-import org.gatein.wci.authentication.AuthenticationListenerSupport;
import org.gatein.wci.authentication.AuthenticationResult;
import org.gatein.wci.authentication.GenericAuthentication;
import org.gatein.wci.command.CommandDispatcher;
@@ -76,9 +74,6 @@
/** . */
private Registration registration;
- /** . */
- private AuthenticationListenerSupport listenerSupport = new
AuthenticationListenerSupport();
-
public TC6ServletContainerContext(Engine engine)
{
this.engine = engine;
@@ -106,26 +101,12 @@
public AuthenticationResult login(HttpServletRequest request, HttpServletResponse
response, String userName, String password)
{
- AuthenticationResult result = GenericAuthentication.getInstance().login(userName,
password, request, response);
-
- //
- listenerSupport.fireEvent(
- AuthenticationListenerSupport.EventType.LOGIN,
- new AuthenticationEvent(AuthenticationListenerSupport.EventType.LOGIN, request,
response, userName, password
- ));
-
- return result;
+ return GenericAuthentication.getInstance().login(userName, password, request,
response);
}
public void logout(HttpServletRequest request, HttpServletResponse response)
{
GenericAuthentication.getInstance().logout(request, response);
-
- //
- listenerSupport.fireEvent(
- AuthenticationListenerSupport.EventType.LOGOUT,
- new AuthenticationEvent(AuthenticationListenerSupport.EventType.LOGOUT, request,
response
- ));
}
public synchronized void containerEvent(ContainerEvent event)
Modified:
components/wci/branches/adf/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7ServletContainerContext.java
===================================================================
---
components/wci/branches/adf/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7ServletContainerContext.java 2010-10-01
08:44:53 UTC (rev 4455)
+++
components/wci/branches/adf/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7ServletContainerContext.java 2010-10-01
09:50:50 UTC (rev 4456)
@@ -36,8 +36,6 @@
import org.gatein.common.logging.Logger;
import org.gatein.common.logging.LoggerFactory;
import org.gatein.wci.RequestDispatchCallback;
-import org.gatein.wci.authentication.AuthenticationEvent;
-import org.gatein.wci.authentication.AuthenticationListenerSupport;
import org.gatein.wci.authentication.AuthenticationResult;
import org.gatein.wci.authentication.ProgrammaticAuthenticationResult;
import org.gatein.wci.command.CommandDispatcher;
@@ -77,9 +75,6 @@
/** . */
private Registration registration;
- /** . */
- private AuthenticationListenerSupport listenerSupport = new
AuthenticationListenerSupport();
-
public TC7ServletContainerContext(Engine engine)
{
this.engine = engine;
@@ -110,12 +105,6 @@
try
{
request.login(userName, password);
-
- //
- listenerSupport.fireEvent(
- AuthenticationListenerSupport.EventType.LOGIN,
- new AuthenticationEvent(AuthenticationListenerSupport.EventType.LOGIN,
request, response, userName, password
- ));
}
catch (ServletException e)
{
@@ -129,12 +118,6 @@
try
{
request.logout();
-
- //
- listenerSupport.fireEvent(
- AuthenticationListenerSupport.EventType.LOGOUT,
- new AuthenticationEvent(AuthenticationListenerSupport.EventType.LOGOUT,
request, response
- ));
}
catch (ServletException e)
{
Modified:
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/ServletContainer.java
===================================================================
---
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/ServletContainer.java 2010-10-01
08:44:53 UTC (rev 4455)
+++
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/ServletContainer.java 2010-10-01
09:50:50 UTC (rev 4456)
@@ -22,6 +22,7 @@
******************************************************************************/
package org.gatein.wci;
+import org.gatein.wci.authentication.AuthenticationListener;
import org.gatein.wci.authentication.AuthenticationResult;
import org.gatein.wci.spi.ServletContainerContext;
@@ -110,4 +111,18 @@
* @param response the response valid in the current servlet context
*/
void logout(HttpServletRequest request, HttpServletResponse response);
+
+ /**
+ * 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);
}
Modified:
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/AuthenticationEvent.java
===================================================================
---
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/AuthenticationEvent.java 2010-10-01
08:44:53 UTC (rev 4455)
+++
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/AuthenticationEvent.java 2010-10-01
09:50:50 UTC (rev 4456)
@@ -28,17 +28,12 @@
*/
public class AuthenticationEvent
{
- private AuthenticationListenerSupport.EventType eventType;
private HttpServletRequest request;
private HttpServletResponse response;
private String username;
private String password;
- public AuthenticationEvent(AuthenticationListenerSupport.EventType eventType,
HttpServletRequest request, HttpServletResponse response) {
-
- if (eventType == null) {
- throw new IllegalArgumentException("eventType is null");
- }
+ public AuthenticationEvent(HttpServletRequest request, HttpServletResponse response) {
if (request == null) {
throw new IllegalArgumentException("request is null");
@@ -48,13 +43,12 @@
throw new IllegalArgumentException("response is null");
}
- this.eventType = eventType;
this.request = request;
this.response = response;
}
- public AuthenticationEvent(AuthenticationListenerSupport.EventType eventType,
HttpServletRequest request, HttpServletResponse response, String username, String
password) {
- this(eventType, request, response);
+ public AuthenticationEvent(HttpServletRequest request, HttpServletResponse response,
String username, String password) {
+ this(request, response);
if (username == null) {
throw new IllegalArgumentException("username is null");
@@ -68,10 +62,6 @@
this.password = password;
}
- public AuthenticationListenerSupport.EventType getEventType() {
- return eventType;
- }
-
public HttpServletRequest getRequest() {
return request;
}
Deleted:
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/AuthenticationListenerSupport.java
===================================================================
---
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/AuthenticationListenerSupport.java 2010-10-01
08:44:53 UTC (rev 4455)
+++
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/AuthenticationListenerSupport.java 2010-10-01
09:50:50 UTC (rev 4456)
@@ -1,68 +0,0 @@
-/*
-* 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 javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author <a href="mailto:alain.defrance@exoplatform.com">Alain
Defrance</a>
- * @version $Revision$
- */
-public class AuthenticationListenerSupport
-{
- public enum EventType
- {
- LOGIN, LOGOUT
- }
-
- private List<AuthenticationListener> authenticationListeners = new
ArrayList<AuthenticationListener>();
-
- public void addAuthenticationListener(AuthenticationListener listener)
- {
- authenticationListeners.add(listener);
- }
-
- protected List<AuthenticationListener> getAuthenticationListeners()
- {
- return authenticationListeners;
- }
-
- public void fireEvent(EventType type, AuthenticationEvent ae)
- {
- String methodName = String.format(
- "on%1%2",
- type.toString().substring(0, 1).toUpperCase(),
- type.toString().substring(1)
- );
- for (AuthenticationListener currentListener : authenticationListeners)
- {
- try
- {
- currentListener.getClass().getMethod(methodName,
AuthenticationEvent.class).invoke(currentListener, ae);
- }
- catch (Exception ignore)
- {
- }
- }
- }
-}
Modified:
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/impl/DefaultServletContainer.java
===================================================================
---
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/impl/DefaultServletContainer.java 2010-10-01
08:44:53 UTC (rev 4455)
+++
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/impl/DefaultServletContainer.java 2010-10-01
09:50:50 UTC (rev 4456)
@@ -22,6 +22,8 @@
******************************************************************************/
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.spi.ServletContainerContext;
import org.gatein.wci.spi.WebAppContext;
@@ -59,9 +61,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 ArrayList<AuthenticationListener> authenticationListeners = new
ArrayList<AuthenticationListener>();
+
/** The web applications. */
private final Map<String, WebAppImpl> webAppMap = new HashMap<String,
WebAppImpl>();
@@ -92,14 +97,38 @@
/** . */
public AuthenticationResult login(HttpServletRequest request, HttpServletResponse
response, String userName, String password)
{
- return registration.context.login(request, response, userName, password);
+ AuthenticationResult result = registration.context.login(request, response,
userName, password);
+
+ //
+ fireEvent(EventType.LOGIN, new AuthenticationEvent(request, response, userName,
password));
+
+ return result;
}
public void logout(HttpServletRequest request, HttpServletResponse response) {
registration.context.logout(request, response);
+
+ //
+ fireEvent(EventType.LOGOUT, new AuthenticationEvent(request, response));
}
- public WebExecutor getExecutor(HttpServletRequest request, HttpServletResponse
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();
}
@@ -112,11 +141,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;
@@ -135,7 +164,7 @@
{
throw new IllegalArgumentException();
}
- if (listeners.remove(listener))
+ if (webAppListeners.remove(listener))
{
for (WebApp webApp : webAppMap.values())
{
@@ -172,12 +201,31 @@
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%1%2",
+ type.toString().substring(0, 1).toUpperCase(),
+ type.toString().substring(1)
+ );
+ for (AuthenticationListener currentListener : authenticationListeners)
+ {
+ try
+ {
+ currentListener.getClass().getMethod(methodName,
AuthenticationEvent.class).invoke(currentListener, ae);
+ }
+ catch (Exception ignore)
+ {
+ }
+ }
+ }
+
/**
* Generic detyped request dispatch to a servlet context using the include mechanism.
*
@@ -209,6 +257,10 @@
return registration.context.include(targetServletContext, request, response,
callback, handback);
}
+ public enum EventType {
+ LOGIN, LOGOUT
+ }
+
private static class RegistrationImpl implements ServletContainerContext.Registration
{
Modified:
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/impl/generic/GenericServletContainerContext.java
===================================================================
---
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/impl/generic/GenericServletContainerContext.java 2010-10-01
08:44:53 UTC (rev 4455)
+++
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/impl/generic/GenericServletContainerContext.java 2010-10-01
09:50:50 UTC (rev 4456)
@@ -23,8 +23,6 @@
package org.gatein.wci.impl.generic;
import org.gatein.wci.RequestDispatchCallback;
-import org.gatein.wci.authentication.AuthenticationEvent;
-import org.gatein.wci.authentication.AuthenticationListenerSupport;
import org.gatein.wci.authentication.AuthenticationResult;
import org.gatein.wci.authentication.GenericAuthentication;
import org.gatein.wci.impl.DefaultServletContainerFactory;
@@ -56,9 +54,6 @@
private static GenericServletContainerContext instance;
private static HashMap<ServletContext, String> requestDispatchMap = new
HashMap<ServletContext, String>();
-
- /** . */
- private AuthenticationListenerSupport listenerSupport = new
AuthenticationListenerSupport();
public static GenericServletContainerContext getInstance()
{
@@ -137,26 +132,12 @@
public AuthenticationResult login(HttpServletRequest request, HttpServletResponse
response, String userName, String password)
{
- AuthenticationResult result = GenericAuthentication.getInstance().login(userName,
password, request, response);
-
- //
- listenerSupport.fireEvent(
- AuthenticationListenerSupport.EventType.LOGIN,
- new AuthenticationEvent(AuthenticationListenerSupport.EventType.LOGIN, request,
response, userName, password
- ));
-
- return result;
+ return GenericAuthentication.getInstance().login(userName, password, request,
response);
}
public void logout(HttpServletRequest request, HttpServletResponse response)
{
GenericAuthentication.getInstance().logout(request, response);
-
- //
- listenerSupport.fireEvent(
- AuthenticationListenerSupport.EventType.LOGOUT,
- new AuthenticationEvent(AuthenticationListenerSupport.EventType.LOGOUT, request,
response
- ));
}
//