cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1336257 - in /cxf/branches/2.5.x-fixes: rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/ rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/ services/sts/systests/basic/src/test/java/org/apache/cxf/systest/sts/asy...
Date Wed, 09 May 2012 16:07:07 GMT
Author: dkulp
Date: Wed May  9 16:07:06 2012
New Revision: 1336257

URL: http://svn.apache.org/viewvc?rev=1336257&view=rev
Log:
Merged revisions 1332833 via  git cherry-pick from
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1332833 | dkulp | 2012-05-01 17:15:00 -0400 (Tue, 01 May 2012) | 3 lines

  [CXF-4279] Try to make sure the ehcache cache manager gets shutdown when
  we're done with it.

........

Added:
    cxf/branches/2.5.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheManagerHolder.java
  (with props)
Modified:
    cxf/branches/2.5.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheReplayCache.java
    cxf/branches/2.5.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/WSSecurityPolicyLoader.java
    cxf/branches/2.5.x-fixes/services/sts/systests/basic/src/test/java/org/apache/cxf/systest/sts/asymmetric/AsymmetricBindingTest.java
    cxf/branches/2.5.x-fixes/services/sts/systests/basic/src/test/java/org/apache/cxf/systest/sts/username_actas/UsernameActAsTest.java

Added: cxf/branches/2.5.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheManagerHolder.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheManagerHolder.java?rev=1336257&view=auto
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheManagerHolder.java
(added)
+++ cxf/branches/2.5.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheManagerHolder.java
Wed May  9 16:07:06 2012
@@ -0,0 +1,62 @@
+/**
+ * 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.ws.security.cache;
+
+import java.net.URL;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import net.sf.ehcache.CacheManager;
+
+/**
+ * We need to reference count the EHCacheManager things
+ */
+public final class EHCacheManagerHolder {
+    private static final ConcurrentHashMap<String, AtomicInteger> COUNTS 
+        = new ConcurrentHashMap<String, AtomicInteger>(8, 0.75f, 2);
+    
+    private EHCacheManagerHolder() {
+        //utility
+    }
+    
+    public static CacheManager getCacheManager(URL configFileURL) {
+        CacheManager cacheManager;
+        if (configFileURL == null) {
+            cacheManager = CacheManager.create();
+        } else {
+            cacheManager = CacheManager.create(configFileURL);
+        }
+        AtomicInteger a = COUNTS.get(cacheManager.getName());
+        if (a == null) {
+            COUNTS.putIfAbsent(cacheManager.getName(), new AtomicInteger());
+            a = COUNTS.get(cacheManager.getName());
+        }
+        a.incrementAndGet();
+        return cacheManager;
+    }
+    
+    public static void releaseCacheManger(CacheManager cacheManager) {
+        AtomicInteger a = COUNTS.get(cacheManager.getName());
+        if (a.decrementAndGet() == 0) {
+            cacheManager.shutdown();
+        }
+    }
+    
+}

Propchange: cxf/branches/2.5.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheManagerHolder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/branches/2.5.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheManagerHolder.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/branches/2.5.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheReplayCache.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheReplayCache.java?rev=1336257&r1=1336256&r2=1336257&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheReplayCache.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheReplayCache.java
Wed May  9 16:07:06 2012
@@ -19,6 +19,8 @@
 
 package org.apache.cxf.ws.security.cache;
 
+import java.io.Closeable;
+import java.io.IOException;
 import java.net.URL;
 
 import net.sf.ehcache.Cache;
@@ -31,7 +33,7 @@ import org.apache.ws.security.cache.Repl
  * An in-memory EHCache implementation of the ReplayCache interface. The default TTL is 60
minutes and the
  * max TTL is 12 hours.
  */
-public class EHCacheReplayCache implements ReplayCache {
+public class EHCacheReplayCache implements ReplayCache, Closeable {
     
     public static final long DEFAULT_TTL = 3600L;
     public static final long MAX_TTL = DEFAULT_TTL * 12L;
@@ -40,13 +42,7 @@ public class EHCacheReplayCache implemen
     private long ttl = DEFAULT_TTL;
     
     public EHCacheReplayCache(String key, URL configFileURL) {
-        if (cacheManager == null) {
-            if (configFileURL == null) {
-                cacheManager = CacheManager.create();
-            } else {
-                cacheManager = CacheManager.create(configFileURL);
-            }
-        }
+        cacheManager = EHCacheManagerHolder.getCacheManager(configFileURL);
         if (!cacheManager.cacheExists(key)) {
             cache = new Cache(key, 50000, true, false, DEFAULT_TTL, DEFAULT_TTL);
             cacheManager.addCache(cache);
@@ -117,5 +113,13 @@ public class EHCacheReplayCache implemen
         }
         return false;
     }
+
+    public void close() throws IOException {
+        if (cacheManager != null) {
+            EHCacheManagerHolder.releaseCacheManger(cacheManager);
+            cacheManager = null;
+            cache = null;
+        }
+    }
     
 }

Modified: cxf/branches/2.5.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/WSSecurityPolicyLoader.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/WSSecurityPolicyLoader.java?rev=1336257&r1=1336256&r2=1336257&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/WSSecurityPolicyLoader.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/WSSecurityPolicyLoader.java
Wed May  9 16:07:06 2012
@@ -19,6 +19,8 @@
 
 package org.apache.cxf.ws.security.policy;
 
+import java.io.Closeable;
+import java.io.IOException;
 import java.util.Arrays;
 import java.util.List;
 
@@ -26,12 +28,20 @@ import javax.xml.namespace.QName;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.common.injection.NoJSR250Annotations;
+import org.apache.cxf.endpoint.Client;
+import org.apache.cxf.endpoint.ClientLifeCycleListener;
+import org.apache.cxf.endpoint.ClientLifeCycleManager;
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.endpoint.ServerLifeCycleListener;
+import org.apache.cxf.endpoint.ServerLifeCycleManager;
+import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.ws.policy.AssertionBuilderLoader;
 import org.apache.cxf.ws.policy.AssertionBuilderRegistry;
 import org.apache.cxf.ws.policy.PolicyBuilder;
 import org.apache.cxf.ws.policy.PolicyInterceptorProviderLoader;
 import org.apache.cxf.ws.policy.PolicyInterceptorProviderRegistry;
 import org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertionBuilder;
+import org.apache.cxf.ws.security.SecurityConstants;
 import org.apache.cxf.ws.security.policy.builders.AlgorithmSuiteBuilder;
 import org.apache.cxf.ws.security.policy.builders.AsymmetricBindingBuilder;
 import org.apache.cxf.ws.security.policy.builders.ContentEncryptedElementsBuilder;
@@ -77,6 +87,7 @@ import org.apache.cxf.ws.security.policy
 import org.apache.cxf.ws.security.policy.interceptors.UsernameTokenInterceptorProvider;
 import org.apache.cxf.ws.security.policy.interceptors.WSSecurityInterceptorProvider;
 import org.apache.cxf.ws.security.policy.interceptors.WSSecurityPolicyInterceptorProvider;
+import org.apache.ws.security.cache.ReplayCache;
 
 @NoJSR250Annotations
 public final class WSSecurityPolicyLoader implements PolicyInterceptorProviderLoader, AssertionBuilderLoader
{
@@ -93,6 +104,45 @@ public final class WSSecurityPolicyLoade
             //and error out at that point.  If nothing uses ws-securitypolicy
             //no warnings/errors will display
         }
+        ServerLifeCycleManager m = b.getExtension(ServerLifeCycleManager.class);
+        if (m != null) {
+            m.registerListener(new ServerLifeCycleListener() {
+                public void startServer(Server server) {
+                }
+                public void stopServer(Server server) {
+                    shutdownResources(server.getEndpoint().getEndpointInfo());
+                }
+            });
+        }
+        ClientLifeCycleManager cm = b.getExtension(ClientLifeCycleManager.class);
+        if (cm != null) {
+            cm.registerListener(new ClientLifeCycleListener() {
+                public void clientCreated(Client client) {
+                }
+                @Override
+                public void clientDestroyed(Client client) {
+                    shutdownResources(client.getEndpoint().getEndpointInfo());
+                }
+            });
+        }
+    }
+    protected void shutdownResources(EndpointInfo info) {
+        ReplayCache rc = (ReplayCache)info.getProperty(SecurityConstants.NONCE_CACHE_INSTANCE);
+        if (rc instanceof Closeable) {
+            close((Closeable)rc);
+        }
+        rc = (ReplayCache)info.getProperty(SecurityConstants.TIMESTAMP_CACHE_INSTANCE);
+        if (rc instanceof Closeable) {
+            close((Closeable)rc);
+        }
+    }
+    
+    private void close(Closeable ts) {
+        try {
+            ts.close();
+        } catch (IOException ex) {
+            //ignore, we're shutting down and nothing we can do
+        }
     }
     public void registerBuilders() {
         AssertionBuilderRegistry reg = bus.getExtension(AssertionBuilderRegistry.class);

Modified: cxf/branches/2.5.x-fixes/services/sts/systests/basic/src/test/java/org/apache/cxf/systest/sts/asymmetric/AsymmetricBindingTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/services/sts/systests/basic/src/test/java/org/apache/cxf/systest/sts/asymmetric/AsymmetricBindingTest.java?rev=1336257&r1=1336256&r2=1336257&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/services/sts/systests/basic/src/test/java/org/apache/cxf/systest/sts/asymmetric/AsymmetricBindingTest.java
(original)
+++ cxf/branches/2.5.x-fixes/services/sts/systests/basic/src/test/java/org/apache/cxf/systest/sts/asymmetric/AsymmetricBindingTest.java
Wed May  9 16:07:06 2012
@@ -61,7 +61,7 @@ public class AsymmetricBindingTest exten
                 launchServer(Server.class, true)
         );
         String deployment = System.getProperty("sts.deployment");
-        if ("standalone".equals(deployment)) {
+        if ("standalone".equals(deployment) || deployment == null) {
             standalone = true;
             assertTrue(
                     "Server failed to launch",
@@ -98,6 +98,7 @@ public class AsymmetricBindingTest exten
         }
         
         doubleIt(asymmetricSaml1Port, 25);
+        bus.shutdown(true);
     }
 
     @org.junit.Test
@@ -123,6 +124,7 @@ public class AsymmetricBindingTest exten
         doubleIt(asymmetricSaml2Port, 30);
 
         TokenTestUtils.verifyToken(asymmetricSaml2Port);
+        bus.shutdown(true);
     }
 
     @org.junit.Test
@@ -146,6 +148,7 @@ public class AsymmetricBindingTest exten
         }
         
         doubleIt(asymmetricSaml1EncryptedPort, 40);
+        bus.shutdown(true);
     }
 
     private static void doubleIt(DoubleItPortType port, int numToDouble) {

Modified: cxf/branches/2.5.x-fixes/services/sts/systests/basic/src/test/java/org/apache/cxf/systest/sts/username_actas/UsernameActAsTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/services/sts/systests/basic/src/test/java/org/apache/cxf/systest/sts/username_actas/UsernameActAsTest.java?rev=1336257&r1=1336256&r2=1336257&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/services/sts/systests/basic/src/test/java/org/apache/cxf/systest/sts/username_actas/UsernameActAsTest.java
(original)
+++ cxf/branches/2.5.x-fixes/services/sts/systests/basic/src/test/java/org/apache/cxf/systest/sts/username_actas/UsernameActAsTest.java
Wed May  9 16:07:06 2012
@@ -66,7 +66,7 @@ public class UsernameActAsTest extends A
             launchServer(Server.class, true)
         );
         String deployment = System.getProperty("sts.deployment");
-        if ("standalone".equals(deployment)) {
+        if ("standalone".equals(deployment) || deployment == null) {
             standalone = true;
             assertTrue(
                     "Server failed to launch",



Mime
View raw message