Author: alain_defrance
Date: 2010-09-23 12:23:08 -0400 (Thu, 23 Sep 2010)
New Revision: 4362
Added:
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/AbstractAuthentication.java
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/Authentication.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/authentication/AuthenticationListener.java
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/GenericAuthentication.java
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/Ticket.java
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/TicketService.java
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/WCICredentials.java
Log:
Login support in progress.
Added:
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/AbstractAuthentication.java
===================================================================
---
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/AbstractAuthentication.java
(rev 0)
+++
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/AbstractAuthentication.java 2010-09-23
16:23:08 UTC (rev 4362)
@@ -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 java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:alain.defrance@exoplatform.com">Alain
Defrance</a>
+ * @version $Revision$
+ */
+public abstract class AbstractAuthentication implements Authentication {
+ protected 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;
+ }
+
+ protected 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) {}
+ }
+ }
+}
Added:
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/Authentication.java
===================================================================
---
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/Authentication.java
(rev 0)
+++
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/Authentication.java 2010-09-23
16:23:08 UTC (rev 4362)
@@ -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@exoplatform.com">Alain
Defrance</a>
+ * @version $Revision$
+ */
+public interface Authentication {
+ public WCICredentials login(String login, char[] password);
+ public void logout();
+ public void addAuthenticationListener(AuthenticationListener listener);
+}
Added:
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
(rev 0)
+++
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/AuthenticationEvent.java 2010-09-23
16:23:08 UTC (rev 4362)
@@ -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@exoplatform.com">Alain
Defrance</a>
+ * @version $Revision$
+ */
+public interface AuthenticationEvent {
+}
Added:
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/AuthenticationListener.java
===================================================================
---
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/AuthenticationListener.java
(rev 0)
+++
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/AuthenticationListener.java 2010-09-23
16:23:08 UTC (rev 4362)
@@ -0,0 +1,29 @@
+/*
+* 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@exoplatform.com">Alain
Defrance</a>
+ * @version $Revision$
+ */
+public interface AuthenticationListener {
+ void onLogin(AuthenticationEvent ae);
+ void onLogout(AuthenticationEvent ae);
+}
Added:
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/GenericAuthentication.java
===================================================================
---
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/GenericAuthentication.java
(rev 0)
+++
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/GenericAuthentication.java 2010-09-23
16:23:08 UTC (rev 4362)
@@ -0,0 +1,38 @@
+/*
+* 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@exoplatform.com">Alain
Defrance</a>
+ * @version $Revision$
+ */
+public class GenericAuthentication extends AbstractAuthentication {
+ public static final TicketService TICKET_SERVICE = new TicketService();
+
+ public WCICredentials login(String login, char[] password) {
+ WCICredentials credentials = TICKET_SERVICE.validateToken(new String(password),
true);
+ fireEvent(EventType.LOGIN, null); // TODO : create parameter
+ return credentials;
+ }
+
+ public void logout() {
+ fireEvent(EventType.LOGOUT, null); // TODO : create parameter
+ }
+}
Added:
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/Ticket.java
===================================================================
---
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/Ticket.java
(rev 0)
+++
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/Ticket.java 2010-09-23
16:23:08 UTC (rev 4362)
@@ -0,0 +1,59 @@
+/*
+* 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@exoplatform.com">Alain
Defrance</a>
+ * @version $Revision$
+ */
+public class Ticket {
+ //public static String EXPIRE_MILI = "expirationMilis";
+
+ //public static String USERNAME = "userName"
+
+ //public static String PASSWORD = "password";
+
+ /** . */
+ private final long expirationTimeMillis;
+
+ /** . */
+ private final WCICredentials payload;
+
+ public Ticket(long expirationTimeMillis, WCICredentials payload)
+ {
+ this.expirationTimeMillis = expirationTimeMillis;
+ this.payload = payload;
+ }
+
+ public long getExpirationTimeMillis()
+ {
+ return expirationTimeMillis;
+ }
+
+ public WCICredentials getPayload()
+ {
+ return payload;
+ }
+
+ public boolean isExpired()
+ {
+ return System.currentTimeMillis() > expirationTimeMillis;
+ }
+}
Added:
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/TicketService.java
===================================================================
---
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/TicketService.java
(rev 0)
+++
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/TicketService.java 2010-09-23
16:23:08 UTC (rev 4362)
@@ -0,0 +1,97 @@
+/*
+* 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 java.util.Random;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * @author <a href="mailto:alain.defrance@exoplatform.com">Alain
Defrance</a>
+ * @version $Revision$
+ */
+public class TicketService {
+
+ protected long validityMillis = 1000 * 60; // TODO : Init from confguration
+
+ protected final ConcurrentHashMap<String, Ticket> tickets = new
ConcurrentHashMap<String, Ticket>();
+
+ protected final Random random = new Random();
+
+ public String createToken(WCICredentials credentials)
+ {
+ if (validityMillis < 0)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (credentials == null)
+ {
+ throw new NullPointerException();
+ }
+ String tokenId = nextTicketId();
+ long expirationTimeMillis = System.currentTimeMillis() + validityMillis;
+ tickets.put(tokenId, new Ticket(expirationTimeMillis, credentials));
+ return tokenId;
+ }
+
+ public WCICredentials validateToken(String stringKey, boolean remove)
+ {
+ if (stringKey == null)
+ {
+ throw new IllegalArgumentException("stringKey is null");
+ }
+
+ Ticket token;
+ try
+ {
+ if (remove)
+ {
+ token = tickets.remove(stringKey);
+ }
+ else
+ {
+ token = tickets.get(stringKey);
+ }
+
+ if (token != null)
+ {
+ boolean valid = token.getExpirationTimeMillis() > System.currentTimeMillis();
+
+ if (valid)
+ {
+ return token.getPayload();
+ }
+ else if (!remove)
+ {
+ tickets.remove(stringKey);
+ }
+
+ }
+ }
+ catch (Exception ignore)
+ {
+ }
+
+ return null;
+ }
+
+ private String nextTicketId() {
+ return "ticket" + random.nextInt(); // TODO : maybe change this token from
configuration
+ }
+}
Added:
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/WCICredentials.java
===================================================================
---
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/WCICredentials.java
(rev 0)
+++
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/WCICredentials.java 2010-09-23
16:23:08 UTC (rev 4362)
@@ -0,0 +1,75 @@
+/*
+* 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 java.io.Serializable;
+
+/**
+ * @author <a href="mailto:alain.defrance@exoplatform.com">Alain
Defrance</a>
+ * @version $Revision$
+ */
+public class WCICredentials implements Serializable {
+ /** . */
+ private final String username;
+
+ /** . */
+ private final String password;
+
+ /**
+ * Construct a new instance.
+ *
+ * @param username the username value
+ * @param password the password value
+ * @throws NullPointerException if any argument is null
+ */
+ public WCICredentials(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;
+ }
+}