cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1358095 - in /cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso: AbstractSSOSpHandler.java EHCacheTokenReplayCache.java RequestAssertionConsumerService.java state/EHCacheSPStateManager.java
Date Fri, 06 Jul 2012 09:44:26 GMT
Author: sergeyb
Date: Fri Jul  6 09:44:25 2012
New Revision: 1358095

URL: http://svn.apache.org/viewvc?rev=1358095&view=rev
Log:
Minor updates to Ehcache providers, adding a close handler to filters too for cases they are
not collocated with Racs

Modified:
    cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/AbstractSSOSpHandler.java
    cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/EHCacheTokenReplayCache.java
    cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/RequestAssertionConsumerService.java
    cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/state/EHCacheSPStateManager.java

Modified: cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/AbstractSSOSpHandler.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/AbstractSSOSpHandler.java?rev=1358095&r1=1358094&r2=1358095&view=diff
==============================================================================
--- cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/AbstractSSOSpHandler.java
(original)
+++ cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/AbstractSSOSpHandler.java
Fri Jul  6 09:44:25 2012
@@ -25,6 +25,7 @@ import java.util.Date;
 import java.util.Properties;
 import java.util.logging.Logger;
 
+import javax.annotation.PreDestroy;
 import javax.security.auth.callback.CallbackHandler;
 
 import org.apache.cxf.Bus;
@@ -54,6 +55,14 @@ public class AbstractSSOSpHandler {
         OpenSAMLUtil.initSamlEngine();
     }
     
+    @PreDestroy
+    public void close() throws IOException {
+        if (stateProvider != null) {
+            stateProvider.close();
+            stateProvider = null;
+        }
+    }
+    
     public void setSignatureCrypto(Crypto crypto) {
         signatureCrypto = crypto;
     }

Modified: cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/EHCacheTokenReplayCache.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/EHCacheTokenReplayCache.java?rev=1358095&r1=1358094&r2=1358095&view=diff
==============================================================================
--- cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/EHCacheTokenReplayCache.java
(original)
+++ cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/EHCacheTokenReplayCache.java
Fri Jul  6 09:44:25 2012
@@ -30,9 +30,11 @@ import net.sf.ehcache.Element;
 import net.sf.ehcache.config.CacheConfiguration;
 import net.sf.ehcache.config.Configuration;
 import net.sf.ehcache.config.ConfigurationFactory;
+import net.sf.ehcache.config.DiskStoreConfiguration;
 
 import org.apache.cxf.Bus;
-import org.apache.ws.security.util.Loader;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.jaxrs.utils.ResourceUtils;
 
 /**
  * An in-memory EHCache implementation of the TokenReplayCache interface. 
@@ -43,30 +45,39 @@ public class EHCacheTokenReplayCache imp
     public static final long DEFAULT_TTL = 3600L;
     public static final long MAX_TTL = DEFAULT_TTL * 12L;
     public static final String CACHE_KEY = "cxf.samlp.replay.cache";
+    private static final String DEFAULT_CONFIG_URL = "cxf-samlp-ehcache.xml";
     
     private Ehcache cache;
     private CacheManager cacheManager;
     private long ttl = DEFAULT_TTL;
     
     public EHCacheTokenReplayCache() {
-        this((Bus)null);
+        this(DEFAULT_CONFIG_URL, null);
     }
     
     public EHCacheTokenReplayCache(Bus bus) {
-        String defaultConfigFile = "cxf-samlp-ehcache.xml";
-        URL configFileURL = Loader.getResource(defaultConfigFile);
-        createCache(configFileURL, bus);
+        this(DEFAULT_CONFIG_URL, bus);
     }
     
-    public EHCacheTokenReplayCache(URL configFileURL) {
-        createCache(configFileURL, null);
+    public EHCacheTokenReplayCache(String configFileURL) {
+        this(configFileURL, null);
     }
     
-    public EHCacheTokenReplayCache(URL configFileURL, Bus bus) {
+    public EHCacheTokenReplayCache(String configFileURL, Bus bus) {
         createCache(configFileURL, bus);
     }
     
-    private void createCache(URL configFileURL, Bus bus) {
+    private void createCache(String configFile, Bus bus) {
+        URL configFileURL = null;
+        try {
+            configFileURL = 
+                ResourceUtils.getClasspathResourceURL(configFile, EHCacheTokenReplayCache.class,
bus);
+        } catch (Exception ex) {
+            // ignore
+        }
+        if (bus == null) {
+            bus = BusFactory.getThreadDefaultBus(true);
+        }
         if (configFileURL == null) {
             cacheManager = CacheManager.create();
         } else {
@@ -74,7 +85,8 @@ public class EHCacheTokenReplayCache imp
             
             if (bus != null) {
                 conf.setName(bus.getId());
-                if ("java.io.tmpdir".equals(conf.getDiskStoreConfiguration().getOriginalPath()))
{
+                DiskStoreConfiguration dsc = conf.getDiskStoreConfiguration();
+                if (dsc != null && "java.io.tmpdir".equals(dsc.getOriginalPath()))
{
                     String path = conf.getDiskStoreConfiguration().getPath() + File.separator
                         + bus.getId();
                     conf.getDiskStoreConfiguration().setPath(path);

Modified: cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/RequestAssertionConsumerService.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/RequestAssertionConsumerService.java?rev=1358095&r1=1358094&r2=1358095&view=diff
==============================================================================
--- cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/RequestAssertionConsumerService.java
(original)
+++ cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/RequestAssertionConsumerService.java
Fri Jul  6 09:44:25 2012
@@ -137,13 +137,12 @@ public class RequestAssertionConsumerSer
     }
     
     @PreDestroy
+    @Override
     public void close() throws IOException {
         if (replayCache != null) {
             replayCache.close();
         }
-        if (getStateProvider() != null) {
-            getStateProvider().close();
-        }
+        super.close();
     }
     
     protected Response doProcessSamlResponse(String encodedSamlResponse,

Modified: cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/state/EHCacheSPStateManager.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/state/EHCacheSPStateManager.java?rev=1358095&r1=1358094&r2=1358095&view=diff
==============================================================================
--- cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/state/EHCacheSPStateManager.java
(original)
+++ cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/state/EHCacheSPStateManager.java
Fri Jul  6 09:44:25 2012
@@ -29,10 +29,12 @@ import net.sf.ehcache.Element;
 import net.sf.ehcache.config.CacheConfiguration;
 import net.sf.ehcache.config.Configuration;
 import net.sf.ehcache.config.ConfigurationFactory;
+import net.sf.ehcache.config.DiskStoreConfiguration;
 
 import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.jaxrs.utils.ResourceUtils;
 import org.apache.cxf.rs.security.saml.sso.EHCacheUtil;
-import org.apache.ws.security.util.Loader;
 
 /**
  * An in-memory EHCache implementation of the SPStateManager interface. 
@@ -43,6 +45,7 @@ public class EHCacheSPStateManager imple
     public static final long DEFAULT_TTL = 60L * 5L;
     public static final String REQUEST_CACHE_KEY = "cxf.samlp.request.state.cache";
     public static final String RESPONSE_CACHE_KEY = "cxf.samlp.response.state.cache";
+    private static final String DEFAULT_CONFIG_URL = "cxf-samlp-ehcache.xml";
     
     private Ehcache requestCache;
     private Ehcache responseCache;
@@ -50,24 +53,32 @@ public class EHCacheSPStateManager imple
     private long ttl = DEFAULT_TTL;
     
     public EHCacheSPStateManager() {
-        this((Bus)null);
+        this(DEFAULT_CONFIG_URL, null);
     }
     
     public EHCacheSPStateManager(Bus bus) {
-        String defaultConfigFile = "cxf-samlp-ehcache.xml";
-        URL configFileURL = Loader.getResource(defaultConfigFile);
-        createCaches(configFileURL, bus);
+        this(DEFAULT_CONFIG_URL, bus);
     }
     
-    public EHCacheSPStateManager(URL configFileURL) {
+    public EHCacheSPStateManager(String configFileURL) {
         this(configFileURL, null);
     }
     
-    public EHCacheSPStateManager(URL configFileURL, Bus bus) {
+    public EHCacheSPStateManager(String configFileURL, Bus bus) {
         createCaches(configFileURL, bus);
     }
     
-    private void createCaches(URL configFileURL, Bus bus) {
+    private void createCaches(String configFile, Bus bus) {
+        URL configFileURL = null;
+        try {
+            configFileURL = 
+                ResourceUtils.getClasspathResourceURL(configFile, EHCacheSPStateManager.class,
bus);
+        } catch (Exception ex) {
+            // ignore
+        }
+        if (bus == null) {
+            bus = BusFactory.getThreadDefaultBus(true);
+        }
         if (configFileURL == null) {
             cacheManager = CacheManager.create();
         } else {
@@ -75,7 +86,8 @@ public class EHCacheSPStateManager imple
             
             if (bus != null) {
                 conf.setName(bus.getId());
-                if ("java.io.tmpdir".equals(conf.getDiskStoreConfiguration().getOriginalPath()))
{
+                DiskStoreConfiguration dsc = conf.getDiskStoreConfiguration();
+                if (dsc != null && "java.io.tmpdir".equals(dsc.getOriginalPath()))
{
                     String path = conf.getDiskStoreConfiguration().getPath() + File.separator
                         + bus.getId();
                     conf.getDiskStoreConfiguration().setPath(path);



Mime
View raw message