[gatein-commits] gatein SVN: r5167 - portal/branches/branch-GTNPORTAL-1643/component/web/security/src/main/java/org/exoplatform/web/security/security.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Nov 18 23:25:35 EST 2010


Author: hoang_to
Date: 2010-11-18 23:25:34 -0500 (Thu, 18 Nov 2010)
New Revision: 5167

Added:
   portal/branches/branch-GTNPORTAL-1643/component/web/security/src/main/java/org/exoplatform/web/security/security/AbstractCodec.java
   portal/branches/branch-GTNPORTAL-1643/component/web/security/src/main/java/org/exoplatform/web/security/security/ToThrowAwayCodec.java
Modified:
   portal/branches/branch-GTNPORTAL-1643/component/web/security/src/main/java/org/exoplatform/web/security/security/CookieTokenService.java
   portal/branches/branch-GTNPORTAL-1643/component/web/security/src/main/java/org/exoplatform/web/security/security/TokenContainer.java
Log:
GTNPORTAL-1533: Passwords saved by CookieTokenService are in JCR DB in plain form

Added: portal/branches/branch-GTNPORTAL-1643/component/web/security/src/main/java/org/exoplatform/web/security/security/AbstractCodec.java
===================================================================
--- portal/branches/branch-GTNPORTAL-1643/component/web/security/src/main/java/org/exoplatform/web/security/security/AbstractCodec.java	                        (rev 0)
+++ portal/branches/branch-GTNPORTAL-1643/component/web/security/src/main/java/org/exoplatform/web/security/security/AbstractCodec.java	2010-11-19 04:25:34 UTC (rev 5167)
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 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.exoplatform.web.security.security;
+
+import org.exoplatform.container.component.BaseComponentPlugin;
+
+/**
+ * Abstract codec used to encode/decode password stored/loaded on/from token entry
+ * 
+ * @author <a href="mailto:hoang281283 at gmail.com">Minh Hoang TO</a>
+ * Nov 19, 2010
+ */
+
+public abstract class AbstractCodec extends BaseComponentPlugin
+{
+
+   public String getName()
+   {
+      return this.getClass().toString();
+   }
+   
+   public abstract String encode(String plainInput);
+   
+   public abstract String decode(String encodedInput);
+   
+}

Modified: portal/branches/branch-GTNPORTAL-1643/component/web/security/src/main/java/org/exoplatform/web/security/security/CookieTokenService.java
===================================================================
--- portal/branches/branch-GTNPORTAL-1643/component/web/security/src/main/java/org/exoplatform/web/security/security/CookieTokenService.java	2010-11-19 03:05:25 UTC (rev 5166)
+++ portal/branches/branch-GTNPORTAL-1643/component/web/security/src/main/java/org/exoplatform/web/security/security/CookieTokenService.java	2010-11-19 04:25:34 UTC (rev 5167)
@@ -24,6 +24,7 @@
 import org.exoplatform.commons.chromattic.ChromatticManager;
 import org.exoplatform.commons.chromattic.ContextualTask;
 import org.exoplatform.commons.chromattic.SessionContext;
+import org.exoplatform.container.component.ComponentPlugin;
 import org.exoplatform.container.xml.InitParams;
 import org.exoplatform.web.security.Credentials;
 import org.exoplatform.web.security.GateInToken;
@@ -47,6 +48,9 @@
    /** . */
    private String lifecycleName="autologin";
 
+   //TODO: Introduce the concept of priority and store the plugins in a map structure
+   private AbstractCodec codec;
+   
    public CookieTokenService(InitParams initParams, ChromatticManager chromatticManager)
    {
       super(initParams);
@@ -56,8 +60,19 @@
     	  lifecycleName = (String)initParams.getValuesParam(SERVICE_CONFIG).getValues().get(3);
       }
       this.chromatticLifeCycle = chromatticManager.getLifeCycle(lifecycleName);
+      
+      //Set the default codec
+      this.codec = new ToThrowAwayCodec();
    }
 
+   public final void setupCodec(ComponentPlugin codecPlugin)
+   {
+      if(codecPlugin instanceof AbstractCodec)
+      {
+         this.codec = (AbstractCodec)codecPlugin;
+      }
+   }
+   
    public String createToken(final Credentials credentials)
    {
       if (validityMillis < 0)
@@ -76,7 +91,9 @@
             long expirationTimeMillis = System.currentTimeMillis() + validityMillis;
             GateInToken token = new GateInToken(expirationTimeMillis, credentials);
             TokenContainer container = getTokenContainer();
-            container.saveToken(tokenId, token.getPayload(), new Date(token.getExpirationTimeMillis()));
+            
+            //Save the token, password is encoded thanks to the codec
+            container.encodeAndSaveToken(tokenId, token.getPayload(), new Date(expirationTimeMillis), codec);
             return tokenId;
          }
       }.executeWith(chromatticLifeCycle);
@@ -89,7 +106,8 @@
          @Override
          protected GateInToken execute()
          {
-            return getTokenContainer().getToken((String)id);
+            //Get the token, encoded password is decoded thanks to codec
+            return getTokenContainer().getTokenAndDecode(id, codec);
          }
       }.executeWith(chromatticLifeCycle);
    }

Added: portal/branches/branch-GTNPORTAL-1643/component/web/security/src/main/java/org/exoplatform/web/security/security/ToThrowAwayCodec.java
===================================================================
--- portal/branches/branch-GTNPORTAL-1643/component/web/security/src/main/java/org/exoplatform/web/security/security/ToThrowAwayCodec.java	                        (rev 0)
+++ portal/branches/branch-GTNPORTAL-1643/component/web/security/src/main/java/org/exoplatform/web/security/security/ToThrowAwayCodec.java	2010-11-19 04:25:34 UTC (rev 5167)
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 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.exoplatform.web.security.security;
+
+/**
+ * @author <a href="mailto:hoang281283 at gmail.com">Minh Hoang TO</a>
+ * Nov 19, 2010
+ */
+
+public class ToThrowAwayCodec extends AbstractCodec
+{
+
+   @Override
+   public String decode(String encodedInput)
+   {
+      return encodedInput;
+   }
+
+   @Override
+   public String encode(String plainInput)
+   {
+      return plainInput;
+   }
+
+}

Modified: portal/branches/branch-GTNPORTAL-1643/component/web/security/src/main/java/org/exoplatform/web/security/security/TokenContainer.java
===================================================================
--- portal/branches/branch-GTNPORTAL-1643/component/web/security/src/main/java/org/exoplatform/web/security/security/TokenContainer.java	2010-11-19 03:05:25 UTC (rev 5166)
+++ portal/branches/branch-GTNPORTAL-1643/component/web/security/src/main/java/org/exoplatform/web/security/security/TokenContainer.java	2010-11-19 04:25:34 UTC (rev 5167)
@@ -84,5 +84,37 @@
       entry.setExpirationTime(expirationTime);
       return entry.getToken();
    }
+   
+   public GateInToken encodeAndSaveToken(String tokenId, Credentials credentials, Date expirationTime, AbstractCodec codec)
+   {
+      Map<String, TokenEntry> tokens = getTokens();
+      TokenEntry entry = tokens.get(tokenId);
+      if (entry == null)
+      {
+         entry = createToken();
+         tokens.put(tokenId, entry);
+         entry.setUserName(credentials.getUsername());
+         entry.setPassword(codec.encode(credentials.getPassword()));
+      }
+      entry.setExpirationTime(expirationTime);
+      return entry.getToken();
+   }
+   
+   public GateInToken getTokenAndDecode(String tokenId, AbstractCodec codec)
+   {
+      Map<String, TokenEntry> tokens = getTokens();
+      TokenEntry entry = tokens.get(tokenId);
+      if(entry != null)
+      {
+         GateInToken gateInToken = entry.getToken();
+         Credentials payload = gateInToken.getPayload();
+         
+         //Return a cloned GateInToken
+         return new GateInToken(gateInToken.getExpirationTimeMillis(), new Credentials(payload.getUsername(), codec
+               .decode(payload.getPassword())));
 
+      }
+      return null;
+   }
+
 }



More information about the gatein-commits mailing list