You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by ve...@apache.org on 2017/01/14 14:32:23 UTC

svn commit: r1778775 - /axis/axis2/java/rampart/branches/RAMPART-423/modules/rampart-trust/src/main/java/org/apache/rahas/SimpleTokenStore.java

Author: veithen
Date: Sat Jan 14 14:32:23 2017
New Revision: 1778775

URL: http://svn.apache.org/viewvc?rev=1778775&view=rev
Log:
Apply the patch provided by Boris Dushanov for RAMPART-423.

Modified:
    axis/axis2/java/rampart/branches/RAMPART-423/modules/rampart-trust/src/main/java/org/apache/rahas/SimpleTokenStore.java

Modified: axis/axis2/java/rampart/branches/RAMPART-423/modules/rampart-trust/src/main/java/org/apache/rahas/SimpleTokenStore.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/rampart/branches/RAMPART-423/modules/rampart-trust/src/main/java/org/apache/rahas/SimpleTokenStore.java?rev=1778775&r1=1778774&r2=1778775&view=diff
==============================================================================
--- axis/axis2/java/rampart/branches/RAMPART-423/modules/rampart-trust/src/main/java/org/apache/rahas/SimpleTokenStore.java (original)
+++ axis/axis2/java/rampart/branches/RAMPART-423/modules/rampart-trust/src/main/java/org/apache/rahas/SimpleTokenStore.java Sat Jan 14 14:32:23 2017
@@ -16,18 +16,23 @@
 
 package org.apache.rahas;
 
-import org.apache.axiom.om.OMElement;
-import org.apache.ws.security.WSConstants;
-import org.apache.ws.security.message.token.Reference;
-
-import javax.xml.namespace.QName;
-
 import java.io.Serializable;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.ws.security.WSConstants;
+import org.apache.ws.security.message.token.Reference;
+
 /**
  * In-memory implementation of the token storage
  */
@@ -86,17 +91,17 @@ public class SimpleTokenStore implements
     }
 
     public String[] getTokenIdentifiers() throws TrustException {       
-        List identifiers = new ArrayList();
         
+    	String [] tokenIdentifiers = null;
+    	
         readLock.lock();
-        try {
-            for (Iterator iterator = tokens.keySet().iterator(); iterator.hasNext();) {
-                identifiers.add(iterator.next());
-            }
-        } finally {
-            readLock.unlock();
-        }
-        return (String[]) identifiers.toArray(new String[identifiers.size()]);
+        
+        Set identifiers = tokens.keySet();
+        tokenIdentifiers = (String[]) identifiers.toArray(new String[identifiers.size()]); 
+        
+        readLock.unlock();
+        
+        return tokenIdentifiers;
     }
 
     public Token[] getValidTokens() throws TrustException {
@@ -117,7 +122,6 @@ public class SimpleTokenStore implements
     }
 
     private Token[] getTokens(int[] states) throws TrustException {
-        processTokenExpiry();
         List tokens = new ArrayList();
         
         readLock.lock();
@@ -125,6 +129,7 @@ public class SimpleTokenStore implements
         try {
             for (Iterator iterator = this.tokens.values().iterator(); iterator.hasNext();) {
                 Token token = (Token) iterator.next();
+                processTokenExpiry(token);
                 for (int i = 0; i < states.length; i++) {
                     if (token.getState() == states[i]) {
                         tokens.add(token);
@@ -139,54 +144,38 @@ public class SimpleTokenStore implements
     }
 
     private Token[] getTokens(int state) throws TrustException {
-        processTokenExpiry();
-        List tokens = new ArrayList();
-        
-        readLock.lock();
-        
-        try {
-            for (Iterator iterator = this.tokens.values().iterator(); iterator.hasNext();) {
-                Token token = (Token) iterator.next();
-                if (token.getState() == state) {
-                    tokens.add(token);
-                }
-            }
-        } finally {
-            readLock.unlock();
-        }
-        return (Token[]) tokens.toArray(new Token[tokens.size()]);
+        int[] states = new int[]{state};        
+        return getTokens(states);
     }
 
     public Token getToken(String id) throws TrustException {
-        processTokenExpiry();
-        
         readLock.lock();
         
         Token token;
         
         try {
-            
-            token = (Token) this.tokens.get(id);
-            
-            if(token == null) {
-                //Try to find the token using attached refs & unattached refs
-                for (Iterator iterator = this.tokens.values().iterator(); iterator.hasNext();) {
-                    Token tempToken = (Token) iterator.next();
-                    OMElement elem = tempToken.getAttachedReference();
-                    if(elem != null && id.equals(this.getIdFromSTR(elem))) {
-                        token = tempToken;
-                    }
-                    elem = tempToken.getUnattachedReference();
-                    if(elem != null && id.equals(this.getIdFromSTR(elem))) {
-                        token = tempToken;
-                    }
-                    
-                }
-                
-            }
-        
+
+        	token = (Token) this.tokens.get(id);            
+        	if(token != null) {
+        		processTokenExpiry(token);                
+        	}else{
+        		//Try to find the token using attached refs & unattached refs
+        		for (Iterator iterator = this.tokens.values().iterator(); iterator.hasNext();) {
+        			Token tempToken = (Token) iterator.next();
+        			processTokenExpiry(tempToken);
+        			OMElement elem = tempToken.getAttachedReference();
+        			if(elem != null && id.equals(this.getIdFromSTR(elem))) {
+        				token = tempToken;
+        			}
+        			elem = tempToken.getUnattachedReference();
+        			if(elem != null && id.equals(this.getIdFromSTR(elem))) {
+        				token = tempToken;
+        			}                    
+        		}
+        	}
+
         } finally {
-            readLock.unlock();
+        	readLock.unlock();
         }        
         return token;
     }
@@ -202,20 +191,10 @@ public class SimpleTokenStore implements
         }        
     }
     
-    protected void processTokenExpiry() throws TrustException {
-        
-        readLock.lock();
-        
-        try {
-            for (Iterator iterator = tokens.values().iterator(); iterator.hasNext();) {
-                Token token = (Token) iterator.next();
-                if (token.getExpires() != null &&
-                    token.getExpires().getTime() < System.currentTimeMillis()) {
-                    token.setState(Token.EXPIRED);
-                }
-            }
-        } finally {
-            readLock.unlock();
+    protected void processTokenExpiry(Token token) throws TrustException {
+    	if (token.getExpires() != null &&
+            token.getExpires().getTime() < System.currentTimeMillis()) {
+            token.setState(Token.EXPIRED);
         }
     }