Author: dkulp
Date: Thu Jun 7 17:33:28 2012
New Revision: 1347723
URL: http://svn.apache.org/viewvc?rev=1347723&view=rev
Log:
[CXF-4366] Make sure the token/replay stores are cleaned up when
endpoints and bus's are stopped.
Added:
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/CacheCleanupListener.java
(with props)
Modified:
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheManagerHolder.java
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheReplayCache.java
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheReplayCacheFactory.java
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/WSSecurityPolicyLoader.java
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStore.java
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStoreFactory.java
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/TokenStoreFactory.java
cxf/trunk/rt/ws/security/src/main/resources/META-INF/cxf/bus-extensions.txt
cxf/trunk/rt/ws/security/src/test/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStoreTest.java
cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/DefaultInMemoryTokenStore.java
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/fault/FaultTest.java
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/security/SecurityPolicyTest.java
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/security/WSSecurityClientTest.java
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssc/WSSCTest.java
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssc/server/Server.java
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssec10/server/Server.java
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssec11/server/AbstractServer.java
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssec11/server/Server11.java
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssec11/server/Server12.java
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/x509/server/Server.java
Added:
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/CacheCleanupListener.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/CacheCleanupListener.java?rev=1347723&view=auto
==============================================================================
---
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/CacheCleanupListener.java
(added)
+++
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/CacheCleanupListener.java
Thu Jun 7 17:33:28 2012
@@ -0,0 +1,87 @@
+/**
+ * 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.io.Closeable;
+import java.io.IOException;
+
+import org.apache.cxf.Bus;
+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.security.SecurityConstants;
+import org.apache.cxf.ws.security.tokenstore.TokenStore;
+import org.apache.ws.security.cache.ReplayCache;
+
+/**
+ *
+ */
+public class CacheCleanupListener implements ServerLifeCycleListener,
ClientLifeCycleListener {
+
+ public CacheCleanupListener(Bus b) {
+ ServerLifeCycleManager m =
b.getExtension(ServerLifeCycleManager.class);
+ if (m != null) {
+ m.registerListener(this);
+ }
+ ClientLifeCycleManager cm =
b.getExtension(ClientLifeCycleManager.class);
+ if (cm != null) {
+ cm.registerListener(this);
+ }
+ }
+ public void clientCreated(Client client) {
+ }
+ public void startServer(Server server) {
+ }
+
+ public void clientDestroyed(Client client) {
+ shutdownResources(client.getEndpoint().getEndpointInfo());
+ }
+ public void stopServer(Server server) {
+ shutdownResources(server.getEndpoint().getEndpointInfo());
+ }
+
+
+ protected void shutdownResources(EndpointInfo info) {
+ TokenStore ts =
(TokenStore)info.getProperty(SecurityConstants.TOKEN_STORE_CACHE_INSTANCE);
+ if (ts instanceof Closeable) {
+ close((Closeable)ts);
+ }
+ 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
+ }
+ }
+}
Propchange:
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/CacheCleanupListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/CacheCleanupListener.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheManagerHolder.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheManagerHolder.java?rev=1347723&r1=1347722&r2=1347723&view=diff
==============================================================================
---
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheManagerHolder.java
(original)
+++
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheManagerHolder.java
Thu Jun 7 17:33:28 2012
@@ -19,11 +19,18 @@
package org.apache.cxf.ws.security.cache;
+import java.io.IOException;
import java.net.URL;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.config.Configuration;
+import net.sf.ehcache.config.ConfigurationFactory;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import org.apache.cxf.resource.ResourceManager;
/**
* We need to reference count the EHCacheManager things
@@ -36,27 +43,81 @@ public final class EHCacheManagerHolder
//utility
}
- public static CacheManager getCacheManager(URL configFileURL) {
- CacheManager cacheManager;
+
+ public static CacheManager getCacheManager(Bus bus, URL configFileURL) {
+ CacheManager cacheManager = null;
if (configFileURL == null) {
- cacheManager = CacheManager.create();
- } else {
- cacheManager = CacheManager.create(configFileURL);
+ //using the default
+ cacheManager = findDefaultCacheManager(bus);
+ }
+ if (cacheManager == null) {
+ 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());
}
- if (a != null) {
- a.incrementAndGet();
+ if (a.incrementAndGet() == 1) {
+ //System.out.println("Create!! " + cacheManager.getName());
}
return cacheManager;
}
+ private static CacheManager findDefaultCacheManager(Bus bus) {
+
+ String defaultConfigFile = "cxf-ehcache.xml";
+ URL configFileURL = null;
+ if (bus != null) {
+ ResourceManager rm = bus.getExtension(ResourceManager.class);
+ configFileURL = rm.resolveResource(defaultConfigFile, URL.class);
+ }
+ try {
+ if (configFileURL == null) {
+ configFileURL =
+ ClassLoaderUtils.getResource(defaultConfigFile,
EHCacheReplayCacheFactory.class);
+ }
+ if (configFileURL == null) {
+ configFileURL = new URL(defaultConfigFile);
+ }
+ } catch (IOException e) {
+ // Do nothing
+ }
+ try {
+ Configuration conf =
ConfigurationFactory.parseConfiguration(configFileURL);
+ /*
+ String perBus =
(String)bus.getProperty("ws-security.cachemanager.per.bus");
+ if (perBus == null) {
+ perBus = "true";
+ }
+ if (Boolean.parseBoolean(perBus)) {
+ conf.setName(bus.getId());
+ if
("java.io.tmpdir".equals(conf.getDiskStoreConfiguration().getOriginalPath())) {
+
+ String path = conf.getDiskStoreConfiguration().getPath() +
File.separator
+ + bus.getId();
+ conf.getDiskStoreConfiguration().setPath(path);
+ }
+ }
+ */
+ return CacheManager.create(conf);
+ } catch (Throwable t) {
+ return null;
+ }
+ }
+
+
public static void releaseCacheManger(CacheManager cacheManager) {
AtomicInteger a = COUNTS.get(cacheManager.getName());
- if (a != null && a.decrementAndGet() == 0) {
+ if (a == null) {
+ return;
+ }
+ if (a.decrementAndGet() == 0) {
+ //System.out.println("Shutdown!! " + cacheManager.getName());
cacheManager.shutdown();
}
}
Modified:
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheReplayCache.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheReplayCache.java?rev=1347723&r1=1347722&r2=1347723&view=diff
==============================================================================
---
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheReplayCache.java
(original)
+++
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheReplayCache.java
Thu Jun 7 17:33:28 2012
@@ -20,7 +20,6 @@
package org.apache.cxf.ws.security.cache;
import java.io.Closeable;
-import java.io.IOException;
import java.net.URL;
import net.sf.ehcache.Cache;
@@ -28,22 +27,30 @@ import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
+import org.apache.cxf.Bus;
+import org.apache.cxf.buslifecycle.BusLifeCycleListener;
+import org.apache.cxf.buslifecycle.BusLifeCycleManager;
import org.apache.ws.security.cache.ReplayCache;
/**
* 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, Closeable {
+public class EHCacheReplayCache implements ReplayCache, Closeable,
BusLifeCycleListener {
public static final long DEFAULT_TTL = 3600L;
public static final long MAX_TTL = DEFAULT_TTL * 12L;
private Ehcache cache;
private CacheManager cacheManager;
+ private Bus bus;
private long ttl = DEFAULT_TTL;
- public EHCacheReplayCache(String key, URL configFileURL) {
- cacheManager = EHCacheManagerHolder.getCacheManager(configFileURL);
+ public EHCacheReplayCache(String key, Bus b, URL configFileURL) {
+ bus = b;
+ if (bus != null) {
+
bus.getExtension(BusLifeCycleManager.class).registerLifeCycleListener(this);
+ }
+ cacheManager = EHCacheManagerHolder.getCacheManager(bus,
configFileURL);
Ehcache newCache = new Cache(key, 50000, true, false, DEFAULT_TTL,
DEFAULT_TTL);
cache = cacheManager.addCacheIfAbsent(newCache);
@@ -112,12 +119,25 @@ public class EHCacheReplayCache implemen
return false;
}
- public void close() throws IOException {
+ public synchronized void close() {
if (cacheManager != null) {
EHCacheManagerHolder.releaseCacheManger(cacheManager);
cacheManager = null;
cache = null;
+ if (bus != null) {
+
bus.getExtension(BusLifeCycleManager.class).unregisterLifeCycleListener(this);
+ }
}
+
+ }
+
+ public void initComplete() {
+ }
+ public void preShutdown() {
+ close();
+ }
+ public void postShutdown() {
+ close();
}
}
Modified:
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheReplayCacheFactory.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheReplayCacheFactory.java?rev=1347723&r1=1347722&r2=1347723&view=diff
==============================================================================
---
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheReplayCacheFactory.java
(original)
+++
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheReplayCacheFactory.java
Thu Jun 7 17:33:28 2012
@@ -19,14 +19,9 @@
package org.apache.cxf.ws.security.cache;
-import java.io.IOException;
import java.net.URL;
-import org.apache.cxf.Bus;
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
import org.apache.cxf.message.Message;
-import org.apache.cxf.resource.ResourceManager;
-import org.apache.cxf.ws.security.SecurityConstants;
import org.apache.ws.security.cache.ReplayCache;
/**
@@ -36,26 +31,7 @@ public class EHCacheReplayCacheFactory e
public ReplayCache newReplayCache(String key, Message message) {
URL configFileURL = getConfigFileURL(message);
- if (configFileURL == null) {
- String defaultConfigFile = "cxf-ehcache.xml";
- ResourceManager rm =
message.getExchange().get(Bus.class).getExtension(ResourceManager.class);
- configFileURL = rm.resolveResource(defaultConfigFile, URL.class);
- try {
- if (configFileURL == null) {
- configFileURL =
- ClassLoaderUtils.getResource(defaultConfigFile,
EHCacheReplayCacheFactory.class);
- }
- if (configFileURL == null) {
- configFileURL = new URL(defaultConfigFile);
- }
- } catch (IOException e) {
- // Do nothing
- }
- }
- if (configFileURL != null) {
- message.setContextualProperty(SecurityConstants.CACHE_CONFIG_FILE,
configFileURL);
- }
- return new EHCacheReplayCache(key, configFileURL);
+ return new EHCacheReplayCache(key, message.getExchange().getBus(),
configFileURL);
}
}
Modified:
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/WSSecurityPolicyLoader.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/WSSecurityPolicyLoader.java?rev=1347723&r1=1347722&r2=1347723&view=diff
==============================================================================
---
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/WSSecurityPolicyLoader.java
(original)
+++
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/WSSecurityPolicyLoader.java
Thu Jun 7 17:33:28 2012
@@ -19,8 +19,6 @@
package org.apache.cxf.ws.security.policy;
-import java.io.Closeable;
-import java.io.IOException;
import java.util.Arrays;
import java.util.List;
@@ -28,20 +26,12 @@ 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;
@@ -87,8 +77,6 @@ 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.cxf.ws.security.tokenstore.TokenStore;
-import org.apache.ws.security.cache.ReplayCache;
@NoJSR250Annotations
public final class WSSecurityPolicyLoader implements
PolicyInterceptorProviderLoader, AssertionBuilderLoader {
@@ -105,49 +93,8 @@ 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) {
- }
- public void clientDestroyed(Client client) {
- shutdownResources(client.getEndpoint().getEndpointInfo());
- }
- });
- }
- }
- protected void shutdownResources(EndpointInfo info) {
- TokenStore ts =
(TokenStore)info.getProperty(SecurityConstants.TOKEN_STORE_CACHE_INSTANCE);
- if (ts instanceof Closeable) {
- close((Closeable)ts);
- }
- 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);
if (reg == null) {
Modified:
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStore.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStore.java?rev=1347723&r1=1347722&r2=1347723&view=diff
==============================================================================
---
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStore.java
(original)
+++
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStore.java
Thu Jun 7 17:33:28 2012
@@ -32,6 +32,9 @@ import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
+import org.apache.cxf.Bus;
+import org.apache.cxf.buslifecycle.BusLifeCycleListener;
+import org.apache.cxf.buslifecycle.BusLifeCycleManager;
import org.apache.cxf.common.util.StringUtils;
import org.apache.cxf.ws.security.cache.EHCacheManagerHolder;
@@ -39,18 +42,24 @@ import org.apache.cxf.ws.security.cache.
* An in-memory EHCache implementation of the TokenStore interface. The
default TTL is 60 minutes
* and the max TTL is 12 hours.
*/
-public class EHCacheTokenStore implements TokenStore, Closeable {
+public class EHCacheTokenStore implements TokenStore, Closeable,
BusLifeCycleListener {
public static final long DEFAULT_TTL = 3600L;
public static final long MAX_TTL = DEFAULT_TTL * 12L;
public static final int MAX_ELEMENTS = 1000000;
private Ehcache cache;
+ private Bus bus;
private CacheManager cacheManager;
private long ttl = DEFAULT_TTL;
- public EHCacheTokenStore(String key, URL configFileURL) {
- cacheManager = EHCacheManagerHolder.getCacheManager(configFileURL);
+ public EHCacheTokenStore(String key, Bus b, URL configFileURL) {
+ bus = b;
+ if (bus != null) {
+
b.getExtension(BusLifeCycleManager.class).registerLifeCycleListener(this);
+ }
+
+ cacheManager = EHCacheManagerHolder.getCacheManager(bus,
configFileURL);
// Cannot overflow to disk as SecurityToken Elements can't be
serialized
Ehcache newCache = new Cache(key, MAX_ELEMENTS, false, false,
DEFAULT_TTL, DEFAULT_TTL);
@@ -158,7 +167,20 @@ public class EHCacheTokenStore implement
EHCacheManagerHolder.releaseCacheManger(cacheManager);
cacheManager = null;
cache = null;
+ if (bus != null) {
+
bus.getExtension(BusLifeCycleManager.class).unregisterLifeCycleListener(this);
+ }
}
}
-
+
+ public void initComplete() {
+ }
+
+ public void preShutdown() {
+ close();
+ }
+
+ public void postShutdown() {
+ close();
+ }
}
Modified:
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStoreFactory.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStoreFactory.java?rev=1347723&r1=1347722&r2=1347723&view=diff
==============================================================================
---
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStoreFactory.java
(original)
+++
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStoreFactory.java
Thu Jun 7 17:33:28 2012
@@ -19,15 +19,9 @@
package org.apache.cxf.ws.security.tokenstore;
-import java.io.IOException;
import java.net.URL;
-import org.apache.cxf.Bus;
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
import org.apache.cxf.message.Message;
-import org.apache.cxf.resource.ResourceManager;
-import org.apache.cxf.ws.security.SecurityConstants;
-import org.apache.cxf.ws.security.cache.EHCacheReplayCacheFactory;
/**
@@ -37,26 +31,7 @@ public class EHCacheTokenStoreFactory ex
public TokenStore newTokenStore(String key, Message message) {
URL configFileURL = getConfigFileURL(message);
- if (configFileURL == null) {
- String defaultConfigFile = "cxf-ehcache.xml";
- ResourceManager rm =
message.getExchange().get(Bus.class).getExtension(ResourceManager.class);
- configFileURL = rm.resolveResource(defaultConfigFile, URL.class);
- try {
- if (configFileURL == null) {
- configFileURL =
- ClassLoaderUtils.getResource(defaultConfigFile,
EHCacheReplayCacheFactory.class);
- }
- if (configFileURL == null) {
- configFileURL = new URL(defaultConfigFile);
- }
- } catch (IOException e) {
- // Do nothing
- }
- }
- if (configFileURL != null) {
- message.setContextualProperty(SecurityConstants.CACHE_CONFIG_FILE,
configFileURL);
- }
- return new EHCacheTokenStore(key, configFileURL);
+ return new EHCacheTokenStore(key, message.getExchange().getBus(),
configFileURL);
}
}
Modified:
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/TokenStoreFactory.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/TokenStoreFactory.java?rev=1347723&r1=1347722&r2=1347723&view=diff
==============================================================================
---
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/TokenStoreFactory.java
(original)
+++
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/TokenStoreFactory.java
Thu Jun 7 17:33:28 2012
@@ -67,7 +67,7 @@ public abstract class TokenStoreFactory
Object o =
message.getContextualProperty(SecurityConstants.CACHE_CONFIG_FILE);
if (o instanceof String) {
URL url = null;
- ResourceManager rm =
message.getExchange().get(Bus.class).getExtension(ResourceManager.class);
+ ResourceManager rm =
message.getExchange().getBus().getExtension(ResourceManager.class);
url = rm.resolveResource((String)o, URL.class);
try {
if (url == null) {
Modified:
cxf/trunk/rt/ws/security/src/main/resources/META-INF/cxf/bus-extensions.txt
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/resources/META-INF/cxf/bus-extensions.txt?rev=1347723&r1=1347722&r2=1347723&view=diff
==============================================================================
--- cxf/trunk/rt/ws/security/src/main/resources/META-INF/cxf/bus-extensions.txt
(original)
+++ cxf/trunk/rt/ws/security/src/main/resources/META-INF/cxf/bus-extensions.txt
Thu Jun 7 17:33:28 2012
@@ -1 +1,2 @@
org.apache.cxf.ws.security.policy.WSSecurityPolicyLoader::true:true
+org.apache.cxf.ws.security.cache.CacheCleanupListener::true:true
Modified:
cxf/trunk/rt/ws/security/src/test/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStoreTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/test/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStoreTest.java?rev=1347723&r1=1347722&r2=1347723&view=diff
==============================================================================
---
cxf/trunk/rt/ws/security/src/test/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStoreTest.java
(original)
+++
cxf/trunk/rt/ws/security/src/test/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStoreTest.java
Thu Jun 7 17:33:28 2012
@@ -21,6 +21,7 @@ package org.apache.cxf.ws.security.token
import java.util.Date;
import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import org.apache.cxf.message.ExchangeImpl;
import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageImpl;
import org.apache.cxf.ws.security.SecurityConstants;
@@ -38,6 +39,7 @@ public class EHCacheTokenStoreTest exten
SecurityConstants.CACHE_CONFIG_FILE,
ClassLoaderUtils.getResource("cxf-ehcache.xml",
EHCacheTokenStoreTest.class)
);
+ message.setExchange(new ExchangeImpl());
store =
tokenStoreFactory.newTokenStore(SecurityConstants.TOKEN_STORE_CACHE_INSTANCE,
message);
}
Modified:
cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/DefaultInMemoryTokenStore.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/DefaultInMemoryTokenStore.java?rev=1347723&r1=1347722&r2=1347723&view=diff
==============================================================================
---
cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/DefaultInMemoryTokenStore.java
(original)
+++
cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/DefaultInMemoryTokenStore.java
Thu Jun 7 17:33:28 2012
@@ -19,13 +19,19 @@
package org.apache.cxf.sts.cache;
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
import org.apache.cxf.common.classloader.ClassLoaderUtils;
import org.apache.cxf.ws.security.tokenstore.EHCacheTokenStore;
public class DefaultInMemoryTokenStore extends EHCacheTokenStore {
+ public DefaultInMemoryTokenStore(Bus b) {
+ super("STS", b, ClassLoaderUtils.getResource("cxf-ehcache.xml",
DefaultInMemoryTokenStore.class));
+ }
public DefaultInMemoryTokenStore() {
- super("STS", ClassLoaderUtils.getResource("cxf-ehcache.xml",
DefaultInMemoryTokenStore.class));
+ super("STS", BusFactory.getDefaultBus(),
+ ClassLoaderUtils.getResource("cxf-ehcache.xml",
DefaultInMemoryTokenStore.class));
}
}
Modified:
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/fault/FaultTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/fault/FaultTest.java?rev=1347723&r1=1347722&r2=1347723&view=diff
==============================================================================
---
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/fault/FaultTest.java
(original)
+++
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/fault/FaultTest.java
Thu Jun 7 17:33:28 2012
@@ -33,6 +33,7 @@ import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
import org.apache.cxf.bus.spring.SpringBusFactory;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.DispatchImpl;
@@ -98,13 +99,12 @@ public class FaultTest extends AbstractB
} catch (Exception ex) {
assertTrue(ex.getMessage().contains("This is a fault"));
}
-
+ ((java.io.Closeable)utPort).close();
bus.shutdown(true);
}
@org.junit.Test
public void testSoap12() throws Exception {
-
SpringBusFactory bf = new SpringBusFactory();
URL busFile = FaultTest.class.getResource("client/client.xml");
@@ -132,13 +132,14 @@ public class FaultTest extends AbstractB
} catch (Exception ex) {
assertTrue(ex.getMessage().contains("This is a fault"));
}
-
+ ((java.io.Closeable)utPort).close();
bus.shutdown(true);
}
@org.junit.Test
public void testSoap12Dispatch() throws Exception {
-
+ createBus();
+ BusFactory.setDefaultBus(getBus());
URL wsdl = FaultTest.class.getResource("DoubleItFault.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItSoap12DispatchPort");
@@ -186,6 +187,8 @@ public class FaultTest extends AbstractB
} catch (Exception ex) {
assertTrue(ex.getMessage().contains("This is a fault"));
}
+
+ client.destroy();
}
Modified:
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/security/SecurityPolicyTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/security/SecurityPolicyTest.java?rev=1347723&r1=1347722&r2=1347723&view=diff
==============================================================================
---
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/security/SecurityPolicyTest.java
(original)
+++
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/security/SecurityPolicyTest.java
Thu Jun 7 17:33:28 2012
@@ -45,6 +45,7 @@ import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
import org.apache.cxf.bus.spring.SpringBusFactory;
import org.apache.cxf.helpers.XMLUtils;
import org.apache.cxf.helpers.XPathUtils;
@@ -200,7 +201,6 @@ public class SecurityPolicyTest extends
@org.junit.AfterClass
public static void cleanup() throws Exception {
SecurityTestUtil.cleanup();
- getStaticBus().shutdown(true);
stopAllServers();
}
@@ -449,6 +449,8 @@ public class SecurityPolicyTest extends
getClass().getResource("bob.properties"));
assertEquals(10, pt.doubleIt(5));
+
+ ((java.io.Closeable)pt).close();
bus.shutdown(true);
}
@@ -476,7 +478,7 @@ public class SecurityPolicyTest extends
((BindingProvider)pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,
getClass().getResource("alice.properties"));
assertEquals(10, pt.doubleIt(5));
-
+ ((java.io.Closeable)pt).close();
bus.shutdown(true);
}
@@ -507,7 +509,7 @@ public class SecurityPolicyTest extends
DoubleIt di = new DoubleIt();
di.setNumberToDouble(5);
assertEquals(10, pt.doubleIt(di, 1).getDoubledNumber());
-
+ ((java.io.Closeable)pt).close();
bus.shutdown(true);
}
@@ -549,12 +551,14 @@ public class SecurityPolicyTest extends
|| errorMessage.contains("Certificate revocation")
|| errorMessage.contains("Error during certificate path
validation"));
}
-
+ ((java.io.Closeable)pt).close();
bus.shutdown(true);
}
@Test
public void testCXF4122() throws Exception {
+ Bus epBus = BusFactory.newInstance().createBus();
+ BusFactory.setDefaultBus(epBus);
URL wsdl = SecurityPolicyTest.class.getResource("DoubleIt.wsdl");
EndpointImpl ep = (EndpointImpl)Endpoint.create(new DoubleItImpl());
ep.setEndpointName(
@@ -598,7 +602,9 @@ public class SecurityPolicyTest extends
|| errorMessage.contains("Certificate revocation")
|| errorMessage.contains("Error during certificate path
validation"));
}
-
+ ((java.io.Closeable)pt).close();
+ ep.stop();
+ epBus.shutdown(true);
bus.shutdown(true);
}
}
Modified:
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/security/WSSecurityClientTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/security/WSSecurityClientTest.java?rev=1347723&r1=1347722&r2=1347723&view=diff
==============================================================================
---
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/security/WSSecurityClientTest.java
(original)
+++
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/security/WSSecurityClientTest.java
Thu Jun 7 17:33:28 2012
@@ -42,6 +42,7 @@ import javax.xml.ws.soap.AddressingFeatu
import javax.xml.ws.soap.SOAPBinding;
import javax.xml.ws.soap.SOAPFaultException;
+import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
import org.apache.cxf.bus.spring.SpringBusFactory;
import org.apache.cxf.endpoint.Client;
@@ -102,6 +103,7 @@ public class WSSecurityClientTest extend
// set this to false to fork
launchServer(Server.class, true)
);
+ createStaticBus();
}
@org.junit.AfterClass
@@ -144,15 +146,15 @@ public class WSSecurityClientTest extend
} catch (Exception ex) {
//expected
}
+
+ ((java.io.Closeable)greeter).close();
}
@Test
public void testTimestampSignEncrypt() throws Exception {
- BusFactory.setDefaultBus(
- new SpringBusFactory().createBus(
- "org/apache/cxf/systest/ws/security/client.xml"
- )
- );
+ Bus b = new SpringBusFactory()
+ .createBus("org/apache/cxf/systest/ws/security/client.xml");
+ BusFactory.setDefaultBus(b);
final javax.xml.ws.Service svc = javax.xml.ws.Service.create(
WSDL_LOC,
GREETER_SERVICE_QNAME
@@ -179,7 +181,10 @@ public class WSSecurityClientTest extend
assertTrue("expected Handler.handleMessage() to be called",
handler.handleMessageCalledOutbound);
assertFalse("expected Handler.handleFault() not to be called",
- handler.handleFaultCalledOutbound);
+ handler.handleFaultCalledOutbound);
+ ((java.io.Closeable)greeter).close();
+ b.shutdown(true);
+ BusFactory.setDefaultBus(getStaticBus());
}
@Test
Modified:
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssc/WSSCTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssc/WSSCTest.java?rev=1347723&r1=1347722&r2=1347723&view=diff
==============================================================================
---
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssc/WSSCTest.java
(original)
+++
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssc/WSSCTest.java
Thu Jun 7 17:33:28 2012
@@ -216,6 +216,7 @@ public class WSSCTest extends AbstractBu
} catch (Exception ex) {
throw new Exception("Error doing " + portPrefix, ex);
}
+ ((java.io.Closeable)port).close();
}
}
Modified:
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssc/server/Server.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssc/server/Server.java?rev=1347723&r1=1347722&r2=1347723&view=diff
==============================================================================
---
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssc/server/Server.java
(original)
+++
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssc/server/Server.java
Thu Jun 7 17:33:28 2012
@@ -85,11 +85,11 @@ public class Server extends AbstractBusT
protected void run() {
try {
- new Server("http://localhost:" + PORT + "/");
Bus busLocal = new SpringBusFactory().createBus(
- "org/apache/cxf/systest/ws/wssc/server/server.xml");
+ "org/apache/cxf/systest/ws/wssc/server/server.xml");
BusFactory.setDefaultBus(busLocal);
setBus(busLocal);
+ new Server("http://localhost:" + PORT + "/");
} catch (Exception e) {
e.printStackTrace();
}
Modified:
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssec10/server/Server.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssec10/server/Server.java?rev=1347723&r1=1347722&r2=1347723&view=diff
==============================================================================
---
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssec10/server/Server.java
(original)
+++
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssec10/server/Server.java
Thu Jun 7 17:33:28 2012
@@ -51,8 +51,7 @@ public class Server extends AbstractBusT
}
public static void main(String args[]) throws Exception {
- new Server();
- new SpringBusFactory().createBus(configFileName);
+ new Server().run();
System.out.println("Server ready...");
Thread.sleep(60 * 60 * 1000);
Modified:
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssec11/server/AbstractServer.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssec11/server/AbstractServer.java?rev=1347723&r1=1347722&r2=1347723&view=diff
==============================================================================
---
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssec11/server/AbstractServer.java
(original)
+++
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssec11/server/AbstractServer.java
Thu Jun 7 17:33:28 2012
@@ -25,10 +25,11 @@ import org.apache.cxf.testutil.common.Ab
import org.apache.cxf.ws.security.SecurityConstants;
abstract class AbstractServer extends AbstractBusTestServerBase {
-
+ String baseUrl;
protected AbstractServer(String baseUrl) throws Exception {
-
-
+ this.baseUrl = baseUrl;
+ }
+ protected void run() {
doPublish(baseUrl + "/APingService", new APingService());
doPublish(baseUrl + "/A-NoTimestampPingService", new
ANoTimestampPingService());
doPublish(baseUrl + "/ADPingService", new ADPingService());
Modified:
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssec11/server/Server11.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssec11/server/Server11.java?rev=1347723&r1=1347722&r2=1347723&view=diff
==============================================================================
---
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssec11/server/Server11.java
(original)
+++
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssec11/server/Server11.java
Thu Jun 7 17:33:28 2012
@@ -38,17 +38,11 @@ public class Server11 extends AbstractSe
"org/apache/cxf/systest/ws/wssec11/server/server.xml");
BusFactory.setDefaultBus(busLocal);
setBus(busLocal);
-
- try {
- new Server11("http://localhost:" + PORT);
- } catch (Exception e) {
- e.printStackTrace();
- }
+ super.run();
}
public static void main(String args[]) throws Exception {
- new
SpringBusFactory().createBus("org/apache/cxf/systest/ws/wssec11/server/server.xml");
- new Server11("http://localhost:" + PORT);
+ new Server11("http://localhost:" + PORT).run();
System.out.println("Server ready...");
Thread.sleep(60 * 60 * 10000);
Modified:
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssec11/server/Server12.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssec11/server/Server12.java?rev=1347723&r1=1347722&r2=1347723&view=diff
==============================================================================
---
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssec11/server/Server12.java
(original)
+++
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssec11/server/Server12.java
Thu Jun 7 17:33:28 2012
@@ -38,17 +38,11 @@ public class Server12 extends AbstractSe
"org/apache/cxf/systest/ws/wssec11/server/server.xml");
BusFactory.setDefaultBus(busLocal);
setBus(busLocal);
-
- try {
- new Server12("http://localhost:" + PORT);
- } catch (Exception e) {
- e.printStackTrace();
- }
+ super.run();
}
public static void main(String args[]) throws Exception {
- new
SpringBusFactory().createBus("org/apache/cxf/systest/ws/wssec11/server/server.xml");
- new Server12("http://localhost:" + PORT);
+ new Server12("http://localhost:" + PORT).run();
System.out.println("Server ready...");
Thread.sleep(60 * 60 * 10000);
Modified:
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/x509/server/Server.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/x509/server/Server.java?rev=1347723&r1=1347722&r2=1347723&view=diff
==============================================================================
---
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/x509/server/Server.java
(original)
+++
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/x509/server/Server.java
Thu Jun 7 17:33:28 2012
@@ -37,11 +37,5 @@ public class Server extends AbstractBusT
Bus busLocal = new SpringBusFactory().createBus(busFile);
BusFactory.setDefaultBus(busLocal);
setBus(busLocal);
-
- try {
- new Server();
- } catch (Exception e) {
- e.printStackTrace();
- }
}
}