You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2020/04/14 15:31:56 UTC

[cxf] branch master updated: Make sure we can load any EhCache config in an OSGi container

This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/master by this push:
     new 08a30d9  Make sure we can load any EhCache config in an OSGi container
08a30d9 is described below

commit 08a30d9d7ff690149e9a998be7b2140a53755862
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Tue Apr 14 16:31:30 2020 +0100

    Make sure we can load any EhCache config in an OSGi container
---
 .../org/apache/cxf/ws/security/cache/CXFEHCacheReplayCache.java  | 2 +-
 .../cxf/ws/security/tokenstore/EHCacheTokenStoreFactory.java     | 9 ++++++++-
 .../main/java/org/apache/cxf/ws/security/wss4j/WSS4JUtils.java   | 8 +++++++-
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/CXFEHCacheReplayCache.java b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/CXFEHCacheReplayCache.java
index 1337a1d..6783b52 100644
--- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/CXFEHCacheReplayCache.java
+++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/CXFEHCacheReplayCache.java
@@ -31,7 +31,7 @@ import org.apache.wss4j.common.cache.EHCacheReplayCache;
  * the cache is shutdown correctly.
  */
 public class CXFEHCacheReplayCache extends EHCacheReplayCache implements BusLifeCycleListener {
-    private Bus bus;
+    private final Bus bus;
 
     public CXFEHCacheReplayCache(String key, Bus bus, URL configFileURL) {
         super(key, EHCacheUtils.getCacheManager(bus, configFileURL));
diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStoreFactory.java b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStoreFactory.java
index 161cb2b..774ce3f 100644
--- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStoreFactory.java
+++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStoreFactory.java
@@ -24,6 +24,7 @@ import java.net.URL;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.rt.security.utils.SecurityUtils;
 import org.apache.cxf.ws.security.SecurityConstants;
+import org.apache.wss4j.common.util.Loader;
 
 
 /**
@@ -31,9 +32,15 @@ import org.apache.cxf.ws.security.SecurityConstants;
  */
 public class EHCacheTokenStoreFactory extends TokenStoreFactory {
 
+    private static final String DEFAULT_CONFIG_FILE = "cxf-ehcache.xml";
+
     public TokenStore newTokenStore(String key, Message message) {
         URL configFileURL = SecurityUtils.getConfigFileURL(message, SecurityConstants.CACHE_CONFIG_FILE,
-                                                           "cxf-ehcache.xml");
+                DEFAULT_CONFIG_FILE);
+        if (configFileURL == null) {
+            configFileURL = Loader.getResource(this.getClass().getClassLoader(),
+                    DEFAULT_CONFIG_FILE);
+        }
         return new EHCacheTokenStore(key, message.getExchange().getBus(), configFileURL);
     }
 
diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JUtils.java b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JUtils.java
index 1ffa1ed..cbd08df 100644
--- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JUtils.java
+++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JUtils.java
@@ -70,6 +70,8 @@ public final class WSS4JUtils {
 
     private static final Logger LOG = LogUtils.getL7dLogger(WSS4JUtils.class);
 
+    private static final String DEFAULT_CONFIG_FILE = "cxf-ehcache.xml";
+
     private WSS4JUtils() {
         // complete
     }
@@ -135,7 +137,11 @@ public final class WSS4JUtils {
                         }
                     }
                     URL configFile = SecurityUtils.getConfigFileURL(message, SecurityConstants.CACHE_CONFIG_FILE,
-                                                                    "cxf-ehcache.xml");
+                            DEFAULT_CONFIG_FILE);
+                    if (configFile == null) {
+                        configFile = Loader.getResource(WSS4JUtils.class.getClassLoader(),
+                                DEFAULT_CONFIG_FILE);
+                    }
 
                     if (ReplayCacheFactory.isEhCacheInstalled()) {
                         Bus bus = message.getExchange().getBus();