cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject svn commit: r1176442 - in /cxf/trunk/services/sts/sts-core/src: main/java/org/apache/cxf/sts/cache/ main/java/org/apache/cxf/sts/operation/ main/java/org/apache/cxf/sts/token/canceller/ main/java/org/apache/cxf/sts/token/provider/ main/java/org/apache/...
Date Tue, 27 Sep 2011 15:51:41 GMT
Author: coheigea
Date: Tue Sep 27 15:51:40 2011
New Revision: 1176442

URL: http://svn.apache.org/viewvc?rev=1176442&view=rev
Log:
[CXF-3826] - Implementation of caching in STS
 - Patch applied, thanks

Added:
    cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/HazelCastTokenStore.java
    cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/cache/HazelCastTokenStoreTest.java
      - copied, changed from r1176317, cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/cache/HazelCastCacheTest.java
Removed:
    cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/DefaultInMemoryCache.java
    cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/HazelCastCache.java
    cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/STSCache.java
    cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/cache/DefaultInMemoryCacheTest.java
    cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/cache/HazelCastCacheTest.java
Modified:
    cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/AbstractOperation.java
    cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/TokenCancelOperation.java
    cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/TokenValidateOperation.java
    cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/canceller/SCTCanceller.java
    cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/canceller/TokenCancellerParameters.java
    cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/provider/SCTProvider.java
    cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/provider/TokenProviderParameters.java
    cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/validator/SCTValidator.java
    cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/validator/TokenValidatorParameters.java
    cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/CancelSCTUnitTest.java
    cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueSCTUnitTest.java
    cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/ValidateSCTUnitTest.java
    cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/canceller/SCTCancellerTest.java
    cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/provider/SCTProviderTest.java
    cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/validator/SCTValidatorTest.java

Added: cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/HazelCastTokenStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/HazelCastTokenStore.java?rev=1176442&view=auto
==============================================================================
--- cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/HazelCastTokenStore.java
(added)
+++ cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/HazelCastTokenStore.java
Tue Sep 27 15:51:40 2011
@@ -0,0 +1,120 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.sts.cache;
+
+import java.util.Collection;
+import java.util.concurrent.TimeUnit;
+
+import com.hazelcast.core.Hazelcast;
+import com.hazelcast.core.IMap;
+
+import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.ws.security.tokenstore.SecurityToken;
+import org.apache.cxf.ws.security.tokenstore.SecurityToken.State;
+
+public class HazelCastTokenStore implements STSTokenStore {
+
+    IMap<Object, Object> cacheMap;
+    boolean autoRemove = true;
+    
+    public HazelCastTokenStore(String mapName) {
+        cacheMap = Hazelcast.getDefaultInstance().getMap(mapName);
+        
+    }
+    
+    public void add(SecurityToken token) {
+        if (token != null && !StringUtils.isEmpty(token.getId())) {
+            cacheMap.put(token.getId(), token);
+        }
+    }
+
+    public void update(SecurityToken token) {
+        if (autoRemove 
+            && (token.getState() == State.EXPIRED || token.getState() == State.CANCELLED))
{
+            remove(token);
+        } else {
+            add(token);
+        }
+    }
+
+    public void remove(SecurityToken token) {
+        if (token != null && !StringUtils.isEmpty(token.getId())) {
+            cacheMap.remove(token.getId());
+        }
+    }
+    
+    public Collection<String> getTokenIdentifiers() {
+        return CastUtils.cast((Collection<?>)cacheMap.keySet());
+    }
+
+    public Collection<SecurityToken> getExpiredTokens() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    
+    public Collection<SecurityToken> getValidTokens() {
+        return CastUtils.cast((Collection<?>)cacheMap.keySet());
+    }
+
+    public Collection<SecurityToken> getRenewedTokens() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Collection<SecurityToken> getCancelledTokens() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public SecurityToken getToken(String id) {
+        return (SecurityToken)cacheMap.get(id);
+    }
+
+    public SecurityToken getTokenByAssociatedHash(int hashCode) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public void removeExpiredTokens() {
+        // TODO Auto-generated method stub
+        
+    }
+
+    
+    public void removeCancelledTokens() {
+        // TODO Auto-generated method stub
+        
+    }
+
+    
+    public void setAutoRemoveTokens(boolean auto) {
+        this.autoRemove = auto;
+    }
+
+    
+    public void add(SecurityToken token, Integer timeToLiveSeconds) {
+        if (token != null && !StringUtils.isEmpty(token.getId())) {
+            cacheMap.put(token.getId(), token, timeToLiveSeconds, TimeUnit.SECONDS);
+        }
+    }
+
+}

Modified: cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/AbstractOperation.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/AbstractOperation.java?rev=1176442&r1=1176441&r2=1176442&view=diff
==============================================================================
--- cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/AbstractOperation.java
(original)
+++ cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/AbstractOperation.java
Tue Sep 27 15:51:40 2011
@@ -41,7 +41,7 @@ import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.sts.QNameConstants;
 import org.apache.cxf.sts.STSConstants;
 import org.apache.cxf.sts.STSPropertiesMBean;
-import org.apache.cxf.sts.cache.STSCache;
+import org.apache.cxf.sts.cache.STSTokenStore;
 import org.apache.cxf.sts.claims.RequestClaimCollection;
 import org.apache.cxf.sts.request.KeyRequirements;
 import org.apache.cxf.sts.request.RequestParser;
@@ -86,7 +86,7 @@ public abstract class AbstractOperation 
     protected List<ServiceMBean> services;
     protected List<TokenProvider> tokenProviders = new ArrayList<TokenProvider>();
     protected boolean returnReferences = true;
-    protected STSCache cache;
+    protected STSTokenStore tokenStore;
     
     public boolean isReturnReferences() {
         return returnReferences;
@@ -96,12 +96,12 @@ public abstract class AbstractOperation 
         this.returnReferences = returnReferences;
     }
     
-    public STSCache getCache() {
-        return cache;
+    public STSTokenStore getTokenStore() {
+        return tokenStore;
     }
 
-    public void setCache(STSCache cache) {
-        this.cache = cache;
+    public void setTokenStore(STSTokenStore tokenStore) {
+        this.tokenStore = tokenStore;
     }
 
     public void setStsProperties(STSPropertiesMBean stsProperties) {
@@ -400,7 +400,7 @@ public abstract class AbstractOperation 
         providerParameters.setStsProperties(stsProperties);
         providerParameters.setPrincipal(context.getUserPrincipal());
         providerParameters.setWebServiceContext(context);
-        providerParameters.setCache(getCache());
+        providerParameters.setTokenStore(getTokenStore());
         
         KeyRequirements keyRequirements = requestParser.getKeyRequirements();
         TokenRequirements tokenRequirements = requestParser.getTokenRequirements();

Modified: cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/TokenCancelOperation.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/TokenCancelOperation.java?rev=1176442&r1=1176441&r2=1176442&view=diff
==============================================================================
--- cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/TokenCancelOperation.java
(original)
+++ cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/TokenCancelOperation.java
Tue Sep 27 15:51:40 2011
@@ -84,7 +84,7 @@ public class TokenCancelOperation extend
         cancellerParameters.setStsProperties(stsProperties);
         cancellerParameters.setPrincipal(context.getUserPrincipal());
         cancellerParameters.setWebServiceContext(context);
-        cancellerParameters.setCache(getCache());
+        cancellerParameters.setTokenStore(getTokenStore());
         
         cancellerParameters.setKeyRequirements(keyRequirements);
         cancellerParameters.setTokenRequirements(tokenRequirements);   

Modified: cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/TokenValidateOperation.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/TokenValidateOperation.java?rev=1176442&r1=1176441&r2=1176442&view=diff
==============================================================================
--- cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/TokenValidateOperation.java
(original)
+++ cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/TokenValidateOperation.java
Tue Sep 27 15:51:40 2011
@@ -95,7 +95,7 @@ public class TokenValidateOperation exte
         validatorParameters.setStsProperties(stsProperties);
         validatorParameters.setPrincipal(context.getUserPrincipal());
         validatorParameters.setWebServiceContext(context);
-        validatorParameters.setCache(getCache());
+        validatorParameters.setTokenStore(getTokenStore());
         
         validatorParameters.setKeyRequirements(keyRequirements);
         validatorParameters.setTokenRequirements(tokenRequirements);

Modified: cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/canceller/SCTCanceller.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/canceller/SCTCanceller.java?rev=1176442&r1=1176441&r2=1176442&view=diff
==============================================================================
--- cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/canceller/SCTCanceller.java
(original)
+++ cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/canceller/SCTCanceller.java
Tue Sep 27 15:51:40 2011
@@ -27,6 +27,7 @@ import org.w3c.dom.Element;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.sts.request.ReceivedToken;
 import org.apache.cxf.sts.request.TokenRequirements;
+import org.apache.cxf.ws.security.tokenstore.SecurityToken;
 import org.apache.cxf.ws.security.trust.STSUtils;
 import org.apache.ws.security.WSSecurityException;
 import org.apache.ws.security.message.token.SecurityContextToken;
@@ -68,7 +69,7 @@ public class SCTCanceller implements Tok
         TokenCancellerResponse response = new TokenCancellerResponse();
         response.setTokenCancelled(false);
         
-        if (tokenParameters.getCache() == null) {
+        if (tokenParameters.getTokenStore() == null) {
             LOG.log(Level.FINE, "A cache must be configured to use the SCTCanceller");
             return response;
         }
@@ -78,12 +79,12 @@ public class SCTCanceller implements Tok
                 Element cancelTargetElement = (Element)cancelTarget.getToken();
                 SecurityContextToken sct = new SecurityContextToken(cancelTargetElement);
                 String identifier = sct.getIdentifier();
-                byte[] secret = (byte[])tokenParameters.getCache().get(identifier);
-                if (secret == null) {
+                SecurityToken token = tokenParameters.getTokenStore().getToken(identifier);
+                if (token == null) {
                     LOG.fine("Identifier: " + identifier + " is not found in the cache");
                     return response;
                 }
-                tokenParameters.getCache().remove(identifier);
+                tokenParameters.getTokenStore().remove(token);
                 response.setTokenCancelled(true);
             } catch (WSSecurityException ex) {
                 LOG.log(Level.WARNING, "", ex);

Modified: cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/canceller/TokenCancellerParameters.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/canceller/TokenCancellerParameters.java?rev=1176442&r1=1176441&r2=1176442&view=diff
==============================================================================
--- cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/canceller/TokenCancellerParameters.java
(original)
+++ cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/canceller/TokenCancellerParameters.java
Tue Sep 27 15:51:40 2011
@@ -24,7 +24,7 @@ import java.security.Principal;
 import javax.xml.ws.WebServiceContext;
 
 import org.apache.cxf.sts.STSPropertiesMBean;
-import org.apache.cxf.sts.cache.STSCache;
+import org.apache.cxf.sts.cache.STSTokenStore;
 import org.apache.cxf.sts.request.KeyRequirements;
 import org.apache.cxf.sts.request.TokenRequirements;
 
@@ -40,14 +40,14 @@ public class TokenCancellerParameters {
     private WebServiceContext webServiceContext;
     private KeyRequirements keyRequirements;
     private TokenRequirements tokenRequirements;
-    private STSCache cache;
+    private STSTokenStore tokenStore;
     
-    public STSCache getCache() {
-        return cache;
+    public STSTokenStore getTokenStore() {
+        return tokenStore;
     }
 
-    public void setCache(STSCache cache) {
-        this.cache = cache;
+    public void setTokenStore(STSTokenStore tokenStore) {
+        this.tokenStore = tokenStore;
     }
     
     public TokenRequirements getTokenRequirements() {

Modified: cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/provider/SCTProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/provider/SCTProvider.java?rev=1176442&r1=1176441&r2=1176442&view=diff
==============================================================================
--- cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/provider/SCTProvider.java
(original)
+++ cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/provider/SCTProvider.java
Tue Sep 27 15:51:40 2011
@@ -28,6 +28,7 @@ import org.apache.cxf.common.logging.Log
 import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.sts.request.TokenRequirements;
 import org.apache.cxf.ws.security.sts.provider.STSException;
+import org.apache.cxf.ws.security.tokenstore.SecurityToken;
 import org.apache.cxf.ws.security.trust.STSUtils;
 
 import org.apache.ws.security.conversation.ConversationConstants;
@@ -94,7 +95,7 @@ public class SCTProvider implements Toke
         TokenRequirements tokenRequirements = tokenParameters.getTokenRequirements();
         LOG.fine("Handling token of type: " + tokenRequirements.getTokenType());
         
-        if (tokenParameters.getCache() == null) {
+        if (tokenParameters.getTokenStore() == null) {
             LOG.log(Level.FINE, "A cache must be configured to use the SCTProvider");
             throw new STSException("Can't serialize SCT", STSException.REQUEST_FAILED);
         }
@@ -118,13 +119,13 @@ public class SCTProvider implements Toke
             response.setComputedKey(keyHandler.isComputedKey());
             
             // putting the secret key into the cache
+            SecurityToken token = new SecurityToken(sct.getIdentifier());
+            token.setSecret(keyHandler.getSecret());
             if (lifetime > 0) {
                 Integer lifetimeInteger = new Integer(Long.valueOf(lifetime).intValue());
-                tokenParameters.getCache().put(
-                    sct.getIdentifier(), keyHandler.getSecret(), lifetimeInteger
-                );
+                tokenParameters.getTokenStore().add(token, lifetimeInteger);
             } else {
-                tokenParameters.getCache().put(sct.getIdentifier(), keyHandler.getSecret());
+                tokenParameters.getTokenStore().add(token);
             }
             
             // Create the references

Modified: cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/provider/TokenProviderParameters.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/provider/TokenProviderParameters.java?rev=1176442&r1=1176441&r2=1176442&view=diff
==============================================================================
--- cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/provider/TokenProviderParameters.java
(original)
+++ cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/provider/TokenProviderParameters.java
Tue Sep 27 15:51:40 2011
@@ -25,7 +25,7 @@ import java.util.Map;
 import javax.xml.ws.WebServiceContext;
 
 import org.apache.cxf.sts.STSPropertiesMBean;
-import org.apache.cxf.sts.cache.STSCache;
+import org.apache.cxf.sts.cache.STSTokenStore;
 import org.apache.cxf.sts.claims.ClaimsManager;
 import org.apache.cxf.sts.claims.RequestClaimCollection;
 import org.apache.cxf.sts.request.KeyRequirements;
@@ -49,14 +49,14 @@ public class TokenProviderParameters {
     private String appliesToAddress;
     private ClaimsManager claimsManager;
     private Map<String, Object> additionalProperties;
-    private STSCache cache;
+    private STSTokenStore tokenStore;
     
-    public STSCache getCache() {
-        return cache;
+    public STSTokenStore getTokenStore() {
+        return tokenStore;
     }
 
-    public void setCache(STSCache cache) {
-        this.cache = cache;
+    public void setTokenStore(STSTokenStore tokenStore) {
+        this.tokenStore = tokenStore;
     }
 
     public ClaimsManager getClaimsManager() {

Modified: cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/validator/SCTValidator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/validator/SCTValidator.java?rev=1176442&r1=1176441&r2=1176442&view=diff
==============================================================================
--- cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/validator/SCTValidator.java
(original)
+++ cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/validator/SCTValidator.java
Tue Sep 27 15:51:40 2011
@@ -29,6 +29,7 @@ import org.apache.cxf.common.logging.Log
 import org.apache.cxf.sts.request.ReceivedToken;
 import org.apache.cxf.sts.request.TokenRequirements;
 
+import org.apache.cxf.ws.security.tokenstore.SecurityToken;
 import org.apache.cxf.ws.security.trust.STSUtils;
 
 import org.apache.ws.security.WSSecurityException;
@@ -73,7 +74,7 @@ public class SCTValidator implements Tok
     public TokenValidatorResponse validateToken(TokenValidatorParameters tokenParameters)
{
         LOG.fine("Validating SecurityContextToken");
         
-        if (tokenParameters.getCache() == null) {
+        if (tokenParameters.getTokenStore() == null) {
             LOG.log(Level.FINE, "A cache must be configured to use the SCTValidator");
             TokenValidatorResponse response = new TokenValidatorResponse();
             response.setValid(false);
@@ -91,11 +92,12 @@ public class SCTValidator implements Tok
                 Element validateTargetElement = (Element)validateTarget.getToken();
                 SecurityContextToken sct = new SecurityContextToken(validateTargetElement);
                 String identifier = sct.getIdentifier();
-                byte[] secret = (byte[])tokenParameters.getCache().get(identifier);
-                if (secret == null) {
+                SecurityToken token = tokenParameters.getTokenStore().getToken(identifier);
+                if (token == null) {
                     LOG.fine("Identifier: " + identifier + " is not found in the cache");
                     return response;
                 }
+                byte[] secret = (byte[])token.getSecret();
                 response.setValid(true);
                 Map<String, Object> properties = new HashMap<String, Object>();
                 properties.put(SCT_VALIDATOR_SECRET, secret);

Modified: cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/validator/TokenValidatorParameters.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/validator/TokenValidatorParameters.java?rev=1176442&r1=1176441&r2=1176442&view=diff
==============================================================================
--- cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/validator/TokenValidatorParameters.java
(original)
+++ cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/validator/TokenValidatorParameters.java
Tue Sep 27 15:51:40 2011
@@ -24,7 +24,7 @@ import java.security.Principal;
 import javax.xml.ws.WebServiceContext;
 
 import org.apache.cxf.sts.STSPropertiesMBean;
-import org.apache.cxf.sts.cache.STSCache;
+import org.apache.cxf.sts.cache.STSTokenStore;
 import org.apache.cxf.sts.request.KeyRequirements;
 import org.apache.cxf.sts.request.TokenRequirements;
 
@@ -40,14 +40,14 @@ public class TokenValidatorParameters {
     private WebServiceContext webServiceContext;
     private KeyRequirements keyRequirements;
     private TokenRequirements tokenRequirements;
-    private STSCache cache;
+    private STSTokenStore tokenStore;
     
-    public STSCache getCache() {
-        return cache;
+    public STSTokenStore getTokenStore() {
+        return tokenStore;
     }
 
-    public void setCache(STSCache cache) {
-        this.cache = cache;
+    public void setTokenStore(STSTokenStore tokenStore) {
+        this.tokenStore = tokenStore;
     }
     
     public TokenRequirements getTokenRequirements() {

Copied: cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/cache/HazelCastTokenStoreTest.java
(from r1176317, cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/cache/HazelCastCacheTest.java)
URL: http://svn.apache.org/viewvc/cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/cache/HazelCastTokenStoreTest.java?p2=cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/cache/HazelCastTokenStoreTest.java&p1=cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/cache/HazelCastCacheTest.java&r1=1176317&r2=1176442&rev=1176442&view=diff
==============================================================================
--- cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/cache/HazelCastCacheTest.java
(original)
+++ cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/cache/HazelCastTokenStoreTest.java
Tue Sep 27 15:51:40 2011
@@ -18,39 +18,49 @@
  */
 package org.apache.cxf.sts.cache;
 
+import org.apache.cxf.ws.security.tokenstore.SecurityToken;
 import org.junit.BeforeClass;
 
-public class HazelCastCacheTest extends org.junit.Assert {
+public class HazelCastTokenStoreTest extends org.junit.Assert {
   
-    private static STSCache cache;
+    private static STSTokenStore store;
     
     @BeforeClass
     public static void init() throws Exception {
-        cache = new HazelCastCache("default");
+        store = new HazelCastTokenStore("default");
     }
     
     // tests STSCache apis for storing in the cache.
     @org.junit.Test
-    public void testCacheStore() {
+    @org.junit.Ignore
+    public void testCacheStore() throws Exception {
         String key = "key";
-        String value = "value";
-        cache.put(key, value);
-        assertEquals(value, cache.get(key));
-        cache.remove(key);
-        assertNull(cache.get(key));
+        SecurityToken token = new SecurityToken(key);
+        store.add(token);
+        assertEquals(token, store.getToken(key));
+        store.remove(token);
+        assertNull(store.getToken(key));
+        store.add(token, new Integer(1));
+        assertNotNull(store.getToken(key));
+        Thread.sleep(2000);
+        assertNull(store.getToken(key));
     }
     
     // tests STSCache apis for removing from the cache.
     @org.junit.Test
+    @org.junit.Ignore
     public void testCacheRemove() {
-        cache.put("test1", "test1");
-        cache.put("test2", "test2");
-        cache.put("test3", "test3");
-        assertTrue(cache.size() == 3);
-        assertTrue(cache.remove("test3"));
-        assertFalse(cache.remove("test3"));
-        assertNull(cache.get("test3"));
-        cache.removeAll();
-        assertTrue(cache.size() == 0);
+        SecurityToken token1 = new SecurityToken("token1");
+        SecurityToken token2 = new SecurityToken("token2");
+        SecurityToken token3 = new SecurityToken("token3");
+        store.add(token1);
+        store.add(token2);
+        store.add(token3);
+        assertTrue(store.getValidTokens().size() == 3);
+        store.remove(token3);
+        assertNull(store.getToken("test3"));
+        store.remove(token1);
+        store.remove(token2);
+        assertTrue(store.getValidTokens().size() == 0);
     }
 }

Modified: cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/CancelSCTUnitTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/CancelSCTUnitTest.java?rev=1176442&r1=1176441&r2=1176442&view=diff
==============================================================================
--- cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/CancelSCTUnitTest.java
(original)
+++ cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/CancelSCTUnitTest.java
Tue Sep 27 15:51:40 2011
@@ -36,8 +36,8 @@ import org.apache.cxf.security.SecurityC
 import org.apache.cxf.sts.QNameConstants;
 import org.apache.cxf.sts.STSPropertiesMBean;
 import org.apache.cxf.sts.StaticSTSProperties;
-import org.apache.cxf.sts.cache.DefaultInMemoryCache;
-import org.apache.cxf.sts.cache.STSCache;
+import org.apache.cxf.sts.cache.DefaultInMemoryTokenStore;
+import org.apache.cxf.sts.cache.STSTokenStore;
 import org.apache.cxf.sts.common.PasswordCallbackHandler;
 import org.apache.cxf.sts.request.KeyRequirements;
 import org.apache.cxf.sts.request.TokenRequirements;
@@ -68,7 +68,7 @@ public class CancelSCTUnitTest extends o
     private static final QName QNAME_REQ_TOKEN_CANCELLED = 
         QNameConstants.WS_TRUST_FACTORY.createRequestedTokenCancelled(null).getName();
     
-    private static STSCache cache = new DefaultInMemoryCache();
+    private static STSTokenStore tokenStore = new DefaultInMemoryTokenStore();
     
     /**
      * Test to successfully cancel a SecurityContextToken
@@ -76,7 +76,7 @@ public class CancelSCTUnitTest extends o
     @org.junit.Test
     public void testCancelSCT() throws Exception {
         TokenCancelOperation cancelOperation = new TokenCancelOperation();
-        cancelOperation.setCache(cache);
+        cancelOperation.setTokenStore(tokenStore);
         
         // Add Token Canceller
         List<TokenCanceller> cancellerList = new ArrayList<TokenCanceller>();
@@ -198,7 +198,7 @@ public class CancelSCTUnitTest extends o
         KeyRequirements keyRequirements = new KeyRequirements();
         parameters.setKeyRequirements(keyRequirements);
 
-        parameters.setCache(cache);
+        parameters.setTokenStore(tokenStore);
         
         parameters.setPrincipal(new CustomTokenPrincipal("alice"));
         // Mock up message context

Modified: cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueSCTUnitTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueSCTUnitTest.java?rev=1176442&r1=1176441&r2=1176442&view=diff
==============================================================================
--- cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueSCTUnitTest.java
(original)
+++ cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueSCTUnitTest.java
Tue Sep 27 15:51:40 2011
@@ -39,8 +39,8 @@ import org.apache.cxf.sts.QNameConstants
 import org.apache.cxf.sts.STSConstants;
 import org.apache.cxf.sts.STSPropertiesMBean;
 import org.apache.cxf.sts.StaticSTSProperties;
-import org.apache.cxf.sts.cache.DefaultInMemoryCache;
-import org.apache.cxf.sts.cache.STSCache;
+import org.apache.cxf.sts.cache.DefaultInMemoryTokenStore;
+import org.apache.cxf.sts.cache.STSTokenStore;
 import org.apache.cxf.sts.common.PasswordCallbackHandler;
 import org.apache.cxf.sts.common.TestUtils;
 import org.apache.cxf.sts.service.EncryptionProperties;
@@ -71,7 +71,7 @@ public class IssueSCTUnitTest extends or
     public static final QName UNATTACHED_REFERENCE = 
         QNameConstants.WS_TRUST_FACTORY.createRequestedUnattachedReference(null).getName();
     
-    private static STSCache cache = new DefaultInMemoryCache();
+    private static STSTokenStore tokenStore = new DefaultInMemoryTokenStore();
     
     private static boolean unrestrictedPoliciesInstalled;
     
@@ -85,7 +85,7 @@ public class IssueSCTUnitTest extends or
     @org.junit.Test
     public void testIssueSCT() throws Exception {
         TokenIssueOperation issueOperation = new TokenIssueOperation();
-        issueOperation.setCache(cache);
+        issueOperation.setTokenStore(tokenStore);
         
         // Add Token Provider
         List<TokenProvider> providerList = new ArrayList<TokenProvider>();
@@ -157,7 +157,7 @@ public class IssueSCTUnitTest extends or
     @org.junit.Test
     public void testIssueEncryptedSCT() throws Exception {
         TokenIssueOperation issueOperation = new TokenIssueOperation();
-        issueOperation.setCache(cache);
+        issueOperation.setTokenStore(tokenStore);
         issueOperation.setEncryptIssuedToken(true);
         
         // Add Token Provider
@@ -236,7 +236,7 @@ public class IssueSCTUnitTest extends or
     @org.junit.Test
     public void testIssueSCTNoReferences() throws Exception {
         TokenIssueOperation issueOperation = new TokenIssueOperation();
-        issueOperation.setCache(cache);
+        issueOperation.setTokenStore(tokenStore);
         issueOperation.setReturnReferences(false);
         
         // Add Token Provider

Modified: cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/ValidateSCTUnitTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/ValidateSCTUnitTest.java?rev=1176442&r1=1176441&r2=1176442&view=diff
==============================================================================
--- cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/ValidateSCTUnitTest.java
(original)
+++ cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/ValidateSCTUnitTest.java
Tue Sep 27 15:51:40 2011
@@ -37,8 +37,8 @@ import org.apache.cxf.sts.QNameConstants
 import org.apache.cxf.sts.STSConstants;
 import org.apache.cxf.sts.STSPropertiesMBean;
 import org.apache.cxf.sts.StaticSTSProperties;
-import org.apache.cxf.sts.cache.DefaultInMemoryCache;
-import org.apache.cxf.sts.cache.STSCache;
+import org.apache.cxf.sts.cache.DefaultInMemoryTokenStore;
+import org.apache.cxf.sts.cache.STSTokenStore;
 import org.apache.cxf.sts.common.PasswordCallbackHandler;
 import org.apache.cxf.sts.request.KeyRequirements;
 import org.apache.cxf.sts.request.TokenRequirements;
@@ -69,7 +69,7 @@ public class ValidateSCTUnitTest extends
     private static final QName QNAME_WST_STATUS = 
         QNameConstants.WS_TRUST_FACTORY.createStatus(null).getName();
     
-    private static STSCache cache = new DefaultInMemoryCache();
+    private static STSTokenStore tokenStore = new DefaultInMemoryTokenStore();
     
     /**
      * Test to successfully validate a SecurityContextToken
@@ -77,7 +77,7 @@ public class ValidateSCTUnitTest extends
     @org.junit.Test
     public void testValidateSCT() throws Exception {
         TokenValidateOperation validateOperation = new TokenValidateOperation();
-        validateOperation.setCache(cache);
+        validateOperation.setTokenStore(tokenStore);
         
         // Add Token Validator
         List<TokenValidator> validatorList = new ArrayList<TokenValidator>();
@@ -132,7 +132,8 @@ public class ValidateSCTUnitTest extends
         assertTrue(validateResponse(response));
         
         // Now remove the token from the cache before validating again
-        assertTrue(cache.remove(providerResponse.getTokenId()));
+        tokenStore.remove(tokenStore.getToken(providerResponse.getTokenId()));
+        assertNull(tokenStore.getToken(providerResponse.getTokenId()));
         response = validateOperation.validate(request, webServiceContext);
         assertFalse(validateResponse(response));
     }
@@ -206,7 +207,7 @@ public class ValidateSCTUnitTest extends
         KeyRequirements keyRequirements = new KeyRequirements();
         parameters.setKeyRequirements(keyRequirements);
 
-        parameters.setCache(cache);
+        parameters.setTokenStore(tokenStore);
         
         parameters.setPrincipal(new CustomTokenPrincipal("alice"));
         // Mock up message context

Modified: cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/canceller/SCTCancellerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/canceller/SCTCancellerTest.java?rev=1176442&r1=1176441&r2=1176442&view=diff
==============================================================================
--- cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/canceller/SCTCancellerTest.java
(original)
+++ cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/canceller/SCTCancellerTest.java
Tue Sep 27 15:51:40 2011
@@ -28,8 +28,8 @@ import org.apache.cxf.jaxws.context.Wrap
 import org.apache.cxf.message.MessageImpl;
 import org.apache.cxf.sts.STSConstants;
 import org.apache.cxf.sts.StaticSTSProperties;
-import org.apache.cxf.sts.cache.DefaultInMemoryCache;
-import org.apache.cxf.sts.cache.STSCache;
+import org.apache.cxf.sts.cache.DefaultInMemoryTokenStore;
+import org.apache.cxf.sts.cache.STSTokenStore;
 import org.apache.cxf.sts.common.PasswordCallbackHandler;
 import org.apache.cxf.sts.request.KeyRequirements;
 import org.apache.cxf.sts.request.ReceivedToken;
@@ -51,7 +51,7 @@ import org.apache.ws.security.message.to
  */
 public class SCTCancellerTest extends org.junit.Assert {
     
-    private static STSCache cache = new DefaultInMemoryCache();
+    private static STSTokenStore tokenStore = new DefaultInMemoryTokenStore();
     
     /**
      * Get a (valid) SecurityContextToken and successfully cancel it.
@@ -119,7 +119,7 @@ public class SCTCancellerTest extends or
         
         KeyRequirements keyRequirements = new KeyRequirements();
         parameters.setKeyRequirements(keyRequirements);
-        parameters.setCache(cache);
+        parameters.setTokenStore(tokenStore);
         
         parameters.setPrincipal(new CustomTokenPrincipal("alice"));
         // Mock up message context
@@ -152,7 +152,7 @@ public class SCTCancellerTest extends or
         KeyRequirements keyRequirements = new KeyRequirements();
         parameters.setKeyRequirements(keyRequirements);
 
-        parameters.setCache(cache);
+        parameters.setTokenStore(tokenStore);
         
         parameters.setPrincipal(new CustomTokenPrincipal("alice"));
         // Mock up message context

Modified: cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/provider/SCTProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/provider/SCTProviderTest.java?rev=1176442&r1=1176441&r2=1176442&view=diff
==============================================================================
--- cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/provider/SCTProviderTest.java
(original)
+++ cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/provider/SCTProviderTest.java
Tue Sep 27 15:51:40 2011
@@ -26,8 +26,8 @@ import org.apache.cxf.jaxws.context.WebS
 import org.apache.cxf.jaxws.context.WrappedMessageContext;
 import org.apache.cxf.message.MessageImpl;
 import org.apache.cxf.sts.StaticSTSProperties;
-import org.apache.cxf.sts.cache.DefaultInMemoryCache;
-import org.apache.cxf.sts.cache.STSCache;
+import org.apache.cxf.sts.cache.DefaultInMemoryTokenStore;
+import org.apache.cxf.sts.cache.STSTokenStore;
 import org.apache.cxf.sts.common.PasswordCallbackHandler;
 import org.apache.cxf.sts.request.KeyRequirements;
 import org.apache.cxf.sts.request.TokenRequirements;
@@ -46,7 +46,7 @@ import org.apache.ws.security.util.DOM2W
  */
 public class SCTProviderTest extends org.junit.Assert {
     
-    private static STSCache cache = new DefaultInMemoryCache();
+    private static STSTokenStore tokenStore = new DefaultInMemoryTokenStore();
     
     /**
      * Create a SecurityContextToken
@@ -132,8 +132,8 @@ public class SCTProviderTest extends org
         Element token = providerResponse.getToken();
         SecurityContextToken sctToken = new SecurityContextToken(token);
         String identifier = sctToken.getIdentifier();
-        assertNotNull(cache.get(identifier));
-        assertNull(cache.get(identifier + "1234"));
+        assertNotNull(tokenStore.getToken(identifier));
+        assertNull(tokenStore.getToken(identifier + "1234"));
     }
     
     /**
@@ -176,7 +176,7 @@ public class SCTProviderTest extends org
         KeyRequirements keyRequirements = new KeyRequirements();
         parameters.setKeyRequirements(keyRequirements);
 
-        parameters.setCache(cache);
+        parameters.setTokenStore(tokenStore);
         
         parameters.setPrincipal(new CustomTokenPrincipal("alice"));
         // Mock up message context

Modified: cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/validator/SCTValidatorTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/validator/SCTValidatorTest.java?rev=1176442&r1=1176441&r2=1176442&view=diff
==============================================================================
--- cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/validator/SCTValidatorTest.java
(original)
+++ cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/validator/SCTValidatorTest.java
Tue Sep 27 15:51:40 2011
@@ -28,8 +28,8 @@ import org.apache.cxf.jaxws.context.Wrap
 import org.apache.cxf.message.MessageImpl;
 import org.apache.cxf.sts.STSConstants;
 import org.apache.cxf.sts.StaticSTSProperties;
-import org.apache.cxf.sts.cache.DefaultInMemoryCache;
-import org.apache.cxf.sts.cache.STSCache;
+import org.apache.cxf.sts.cache.DefaultInMemoryTokenStore;
+import org.apache.cxf.sts.cache.STSTokenStore;
 import org.apache.cxf.sts.common.PasswordCallbackHandler;
 import org.apache.cxf.sts.request.KeyRequirements;
 import org.apache.cxf.sts.request.ReceivedToken;
@@ -52,7 +52,7 @@ import org.apache.ws.security.message.to
  */
 public class SCTValidatorTest extends org.junit.Assert {
     
-    private static STSCache cache = new DefaultInMemoryCache();
+    private static STSTokenStore tokenStore = new DefaultInMemoryTokenStore();
     
     /**
      * Test a valid SecurityContextToken
@@ -79,7 +79,8 @@ public class SCTValidatorTest extends or
         );
         
         // Now remove the SCT from the cache
-        assertTrue(cache.remove(providerResponse.getTokenId()));
+        tokenStore.remove(tokenStore.getToken(providerResponse.getTokenId()));
+        assertNull(tokenStore.getToken(providerResponse.getTokenId()));
         validatorResponse = sctValidator.validateToken(validatorParameters);
         assertTrue(validatorResponse != null);
         assertFalse(validatorResponse.isValid());
@@ -126,7 +127,7 @@ public class SCTValidatorTest extends or
         
         KeyRequirements keyRequirements = new KeyRequirements();
         parameters.setKeyRequirements(keyRequirements);
-        parameters.setCache(cache);
+        parameters.setTokenStore(tokenStore);
         
         parameters.setPrincipal(new CustomTokenPrincipal("alice"));
         // Mock up message context
@@ -159,7 +160,7 @@ public class SCTValidatorTest extends or
         KeyRequirements keyRequirements = new KeyRequirements();
         parameters.setKeyRequirements(keyRequirements);
 
-        parameters.setCache(cache);
+        parameters.setTokenStore(tokenStore);
         
         parameters.setPrincipal(new CustomTokenPrincipal("alice"));
         // Mock up message context



Mime
View raw message