axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From az...@apache.org
Subject svn commit: r440404 - in /webservices/axis2/trunk/java/modules/rahas: src/org/apache/rahas/SimpleTokenStore.java src/org/apache/rahas/TokenStorage.java test/org/apache/rahas/SimpleTokenStoreTest.java
Date Tue, 05 Sep 2006 17:06:20 GMT
Author: azeez
Date: Tue Sep  5 10:06:19 2006
New Revision: 440404

URL: http://svn.apache.org/viewvc?view=rev&rev=440404
Log:
Improvements to the Rahas TokenStorage interface and SimpleTokenStore implemetation 

Modified:
    webservices/axis2/trunk/java/modules/rahas/src/org/apache/rahas/SimpleTokenStore.java
    webservices/axis2/trunk/java/modules/rahas/src/org/apache/rahas/TokenStorage.java
    webservices/axis2/trunk/java/modules/rahas/test/org/apache/rahas/SimpleTokenStoreTest.java

Modified: webservices/axis2/trunk/java/modules/rahas/src/org/apache/rahas/SimpleTokenStore.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/rahas/src/org/apache/rahas/SimpleTokenStore.java?view=diff&rev=440404&r1=440403&r2=440404
==============================================================================
--- webservices/axis2/trunk/java/modules/rahas/src/org/apache/rahas/SimpleTokenStore.java
(original)
+++ webservices/axis2/trunk/java/modules/rahas/src/org/apache/rahas/SimpleTokenStore.java
Tue Sep  5 10:06:19 2006
@@ -16,6 +16,8 @@
 
 package org.apache.rahas;
 
+import java.util.List;
+import java.util.Map;
 import java.util.ArrayList;
 import java.util.Hashtable;
 import java.util.Iterator;
@@ -25,93 +27,76 @@
  */
 public class SimpleTokenStore implements TokenStorage {
 
-    private Hashtable tokens = new Hashtable();
+    private Map tokens = new Hashtable();
 
     public void add(Token token) throws TrustException {
-        if (token != null && !"".equals(token.getId()) && 
-                token.getId() != null) {
+        if (token != null && !"".equals(token.getId()) &&
+            token.getId() != null) {
             if (this.tokens.keySet().size() == 0
-                    || (this.tokens.keySet().size() > 0 && !this.tokens
-                            .keySet().contains(token.getId()))) {
+                || (this.tokens.keySet().size() > 0 && !this.tokens
+                    .keySet().contains(token.getId()))) {
                 tokens.put(token.getId(), token);
             } else {
                 throw new TrustException("tokenAlreadyExists",
-                        new String[] { token.getId() });
+                                         new String[]{token.getId()});
             }
 
         }
     }
 
     public void update(Token token) throws TrustException {
-        if (token != null && !"".equals(token.getId()) && 
-                token.getId() != null) {
-            if(this.tokens.keySet().size() == 0 ||
-                    (this.tokens.keySet().size() > 0 && 
-                            !this.tokens.keySet().contains(token.getId()))) {
-                    throw new TrustException("noTokenToUpdate",
-                        new String[] { token.getId() });
+        if (token != null && token.getId() != null && token.getId().trim().length()
!= 0) {
+
+            if (!this.tokens.keySet().contains(token.getId())) {
+                throw new TrustException("noTokenToUpdate", new String[]{token.getId()});
             }
             this.tokens.remove(this.tokens.get(token.getId()));
             this.tokens.put(token.getId(), token);
         }
     }
 
-    public String[] getTokenIdentifiers() throws TrustException {
-        if (this.tokens.size() == 0) {
-            return null;
-        }
-        String[] ids = new String[this.tokens.size()];
-        Iterator iter = this.tokens.keySet().iterator();
-        for (int i = 0; i < ids.length; i++) {
-            ids[i] = (String) iter.next();
+     public String[] getTokenIdentifiers() throws TrustException {
+        List identifiers = new ArrayList();
+        for (Iterator iterator = tokens.keySet().iterator(); iterator.hasNext();) {
+            identifiers.add(iterator.next());
         }
-        return ids;
+        return (String[]) identifiers.toArray(new String[identifiers.size()]);
     }
 
-    public ArrayList getExpiredTokens() throws TrustException {
+    public List getExpiredTokens() throws TrustException {
         return getTokens(Token.EXPIRED);
     }
 
-    public ArrayList getCancelledTokens() throws TrustException {
-        return getTokens(Token.CANCELLED);
-    }
-    
-    public ArrayList getValidTokens() throws TrustException {
+    public List getValidTokens() throws TrustException {
         ArrayList issued = getTokens(Token.ISSUED);
-        ArrayList renewed = getTokens(Token.RENEWED);
-        Iterator renewedIter = renewed.iterator();
-        while (renewedIter.hasNext()) {
-            issued.add(renewedIter.next());
+        List renewed = getTokens(Token.RENEWED);
+        for (Iterator iterator = renewed.iterator(); iterator.hasNext();) {
+            issued.add(iterator.next());
         }
         return issued;
     }
 
-    public ArrayList getRenewedTokens() throws TrustException {
+    public List getRenewedTokens() throws TrustException {
         return getTokens(Token.RENEWED);
     }
-    
-    private ArrayList getTokens(int state) throws TrustException {
-        if (this.tokens.size() == 0) {
-            return null;
-        }
-        Iterator iter = this.tokens.keySet().iterator();
-        ArrayList list = new ArrayList();
-        while (iter.hasNext()) {
-            String id = (String) iter.next();
-            Token tok = (Token)this.tokens.get(id);
-            if(tok.getState() == state) {
-                list.add(tok);
+
+
+    public List getCancelledTokens() throws TrustException {
+        return getTokens(Token.CANCELLED);
+    }
+
+    private ArrayList getTokens(int state) {
+        ArrayList expiredTokens = new ArrayList();
+        for (Iterator iterator = this.tokens.values().iterator(); iterator.hasNext();) {
+            Token token = (Token) iterator.next();
+            if (token.getState() == state) {
+                expiredTokens.add(token);
             }
         }
-        if(list.size() > 0) {
-            return list;
-        } else {
-            return null;
-        }
-             
+        return expiredTokens;
     }
 
     public Token getToken(String id) throws TrustException {
-        return (Token)this.tokens.get(id);
+        return (Token) this.tokens.get(id);
     }
 }

Modified: webservices/axis2/trunk/java/modules/rahas/src/org/apache/rahas/TokenStorage.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/rahas/src/org/apache/rahas/TokenStorage.java?view=diff&rev=440404&r1=440403&r2=440404
==============================================================================
--- webservices/axis2/trunk/java/modules/rahas/src/org/apache/rahas/TokenStorage.java (original)
+++ webservices/axis2/trunk/java/modules/rahas/src/org/apache/rahas/TokenStorage.java Tue
Sep  5 10:06:19 2006
@@ -16,7 +16,7 @@
 
 package org.apache.rahas;
 
-import java.util.ArrayList;
+import java.util.List;
 
 /**
  * The storage interface to store security tokens and
@@ -54,28 +54,28 @@
      * @return
      * @throws TrustException
      */
-    public ArrayList getExpiredTokens() throws TrustException;
+    public List getExpiredTokens() throws TrustException;
     
     /**
      * Return the list of ISSUED and RENEWED tokens.
      * @return
      * @throws TrustException
      */
-    public ArrayList getValidTokens() throws TrustException;
+    public List getValidTokens() throws TrustException;
     
     /**
      * Return the list of RENEWED tokens.
      * @return
      * @throws TrustException
      */
-    public ArrayList getRenewedTokens() throws TrustException;
+    public List getRenewedTokens() throws TrustException;
     
     /**
      * Return the list of CANCELLED tokens
      * @return
      * @throws TrustException
      */
-    public ArrayList getCancelledTokens() throws TrustException;
+    public List getCancelledTokens() throws TrustException;
     
     /**
      * Returns the <code>Token</code> of the given id

Modified: webservices/axis2/trunk/java/modules/rahas/test/org/apache/rahas/SimpleTokenStoreTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/rahas/test/org/apache/rahas/SimpleTokenStoreTest.java?view=diff&rev=440404&r1=440403&r2=440404
==============================================================================
--- webservices/axis2/trunk/java/modules/rahas/test/org/apache/rahas/SimpleTokenStoreTest.java
(original)
+++ webservices/axis2/trunk/java/modules/rahas/test/org/apache/rahas/SimpleTokenStoreTest.java
Tue Sep  5 10:06:19 2006
@@ -18,7 +18,7 @@
 
 import junit.framework.TestCase;
 
-import java.util.ArrayList;
+import java.util.List;
 
 public class SimpleTokenStoreTest extends TestCase {
 
@@ -29,23 +29,23 @@
             store.add(token);
         } catch (TrustException e) {
             fail("Adding a new token to an empty store should not fail, " +
-                    "message : " + e.getMessage());
+                 "message : " + e.getMessage());
         }
         try {
             store.add(token);
             fail("Adding an existing token must throw an exception");
         } catch (TrustException e) {
-            assertEquals("Incorrect exception message", 
-                    TrustException.getMessage("tokenAlreadyExists", 
-                    new String[] {token.getId()}), e.getMessage());
+            assertEquals("Incorrect exception message",
+                         TrustException.getMessage("tokenAlreadyExists",
+                                                   new String[] {token.getId()}), e.getMessage());
         }
     }
-    
+
     public void testGettokenIdentifiers() {
         SimpleTokenStore store = new SimpleTokenStore();
         try {
             String[] ids = store.getTokenIdentifiers();
-            assertNull("There should not be any token ids at this point", ids);
+            assertEquals("There should not be any token ids at this point", 0, ids.length);
         } catch (TrustException e) {
             fail(e.getMessage());
         }
@@ -59,7 +59,7 @@
             fail(e.getMessage());
         }
     }
-    
+
     public void testUpdate() {
         SimpleTokenStore store = new SimpleTokenStore();
         Token token1 = new Token("id-1");
@@ -72,20 +72,19 @@
                             .getId() }), e.getMessage());
         }
         try {
-            Token token = token1;
-            store.add(token);
+            store.add(token1);
             store.add(new Token("id-2"));
             store.add(new Token("id-3"));
-            token.setState(Token.EXPIRED);
-            store.update(token);
+            token1.setState(Token.EXPIRED);
+            store.update(token1);
         } catch (TrustException e) {
             fail(e.getMessage());
         }
     }
-    
+
     public void testGetValidExpiredRenewedTokens() {
         SimpleTokenStore store = new SimpleTokenStore();
-        
+
         Token token1 = new Token("id-1");
         Token token2 = new Token("id-2");
         Token token3 = new Token("id-3");
@@ -93,7 +92,7 @@
         Token token5 = new Token("id-5");
         Token token6 = new Token("id-6");
         Token token7 = new Token("id-7");
-        
+
         token1.setState(Token.ISSUED);
         token2.setState(Token.ISSUED);
         token3.setState(Token.ISSUED);
@@ -101,7 +100,7 @@
         token5.setState(Token.RENEWED);
         token6.setState(Token.EXPIRED);
         token7.setState(Token.CANCELLED);
-        
+
         try {
             store.add(token1);
             store.add(token2);
@@ -110,18 +109,18 @@
             store.add(token5);
             store.add(token6);
             store.add(token7);
-            
-            ArrayList list = store.getValidTokens();
-            ArrayList list2 = store.getExpiredTokens();
-            ArrayList list3 = store.getRenewedTokens();
-            ArrayList list4 = store.getCancelledTokens();
-            
+
+            List list = store.getValidTokens();
+            List list2 = store.getExpiredTokens();
+            List list3 = store.getRenewedTokens();
+            List list4 = store.getCancelledTokens();
+
             assertEquals("Incorrect number of valid tokens", 5, list.size());
-            assertEquals("Incorrect number of expired tokens", 1, 
-                    list2.size());
+            assertEquals("Incorrect number of expired tokens", 1,
+                         list2.size());
             assertEquals("Incorrect number of newed tokens", 2, list3.size());
             assertEquals("Incorrect number of newed tokens", 1, list4.size());
-            
+
         } catch (TrustException e) {
             fail(e.getMessage());
         }



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org


Mime
View raw message