cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject svn commit: r1503658 - in /cxf/trunk/rt/rs/security/sso/saml/src: main/java/org/apache/cxf/rs/security/saml/sso/ main/java/org/apache/cxf/rs/security/saml/sso/state/ test/java/org/apache/cxf/rs/security/saml/sso/ test/resources/
Date Tue, 16 Jul 2013 11:09:05 GMT
Author: ay
Date: Tue Jul 16 11:09:04 2013
New Revision: 1503658

URL: http://svn.apache.org/r1503658
Log:
part of CXF-4577 for trunk

Added:
    cxf/trunk/rt/rs/security/sso/saml/src/test/java/org/apache/cxf/rs/security/saml/sso/EHCacheUtilTest.java
    cxf/trunk/rt/rs/security/sso/saml/src/test/resources/cxf-test-ehcache.xml   (with props)
Modified:
    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/EHCacheUtil.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/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=1503658&r1=1503657&r2=1503658&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
Tue Jul 16 11:09:04 2013
@@ -79,7 +79,7 @@ public class EHCacheTokenReplayCache imp
             // ignore
         }
         if (configFileURL == null) {
-            cacheManager = CacheManager.create();
+            cacheManager = EHCacheUtil.createCacheManager();
         } else {
             Configuration conf = ConfigurationFactory.parseConfiguration(configFileURL);
             
@@ -93,7 +93,7 @@ public class EHCacheTokenReplayCache imp
                 }
             }
             
-            cacheManager = CacheManager.create(conf);
+            cacheManager = EHCacheUtil.createCacheManager(conf);
         }
         
         CacheConfiguration cc = EHCacheUtil.getCacheConfiguration(CACHE_KEY, cacheManager);

Modified: cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/EHCacheUtil.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/EHCacheUtil.java?rev=1503658&r1=1503657&r2=1503658&view=diff
==============================================================================
--- cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/EHCacheUtil.java
(original)
+++ cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/EHCacheUtil.java
Tue Jul 16 11:09:04 2013
@@ -19,12 +19,34 @@
 
 package org.apache.cxf.rs.security.saml.sso;
 
+import java.lang.reflect.Method;
+
+import net.sf.ehcache.CacheException;
 import net.sf.ehcache.CacheManager;
 import net.sf.ehcache.config.CacheConfiguration;
+import net.sf.ehcache.config.Configuration;
 
 /**
  */
 public final class EHCacheUtil {
+    private static Method cacheManagerCreateMethodNoArg;
+    private static Method cacheManagerCreateMethodConfigurationArg;
+    static {
+        // these methods are either completely available or absent (valid assumption from
2.5.0 to 2.7.2 so far)
+        try {
+            // from 2.5.2
+            cacheManagerCreateMethodNoArg = CacheManager.class.getMethod("newInstance", (Class<?>[])null);
+            cacheManagerCreateMethodConfigurationArg = CacheManager.class.getMethod("newInstance",
Configuration.class);
+        } catch (NoSuchMethodException e) {
+            try {
+                // before 2.5.2
+                cacheManagerCreateMethodNoArg = CacheManager.class.getMethod("create", (Class<?>[])null);
+                cacheManagerCreateMethodConfigurationArg = CacheManager.class.getMethod("create",
Configuration.class);
+            } catch (Throwable t) {
+                // ignore
+            }
+        }
+    }
     
     private EHCacheUtil() {
         // 
@@ -48,4 +70,19 @@ public final class EHCacheUtil {
         return cc;
     }
     
+    public static CacheManager createCacheManager() throws CacheException {
+        try {
+            return (CacheManager)cacheManagerCreateMethodNoArg.invoke(null, (Object[])null);
+        } catch (Exception e) {
+            throw new CacheException(e);
+        }
+    }
+
+    public static CacheManager createCacheManager(Configuration conf) throws CacheException
{
+        try {
+            return (CacheManager)cacheManagerCreateMethodConfigurationArg.invoke(null, new
Object[]{conf});
+        } catch (Exception e) {
+            throw new CacheException(e);
+        }
+    }
 }

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=1503658&r1=1503657&r2=1503658&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
Tue Jul 16 11:09:04 2013
@@ -81,7 +81,7 @@ public class EHCacheSPStateManager imple
             // ignore
         }
         if (configFileURL == null) {
-            cacheManager = CacheManager.create();
+            cacheManager = EHCacheUtil.createCacheManager();
         } else {
             Configuration conf = ConfigurationFactory.parseConfiguration(configFileURL);
             
@@ -95,7 +95,7 @@ public class EHCacheSPStateManager imple
                 }
             }
             
-            cacheManager = CacheManager.create(conf);
+            cacheManager = EHCacheUtil.createCacheManager(conf);
         }
         
         CacheConfiguration requestCC = EHCacheUtil.getCacheConfiguration(REQUEST_CACHE_KEY,
cacheManager);

Added: cxf/trunk/rt/rs/security/sso/saml/src/test/java/org/apache/cxf/rs/security/saml/sso/EHCacheUtilTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/security/sso/saml/src/test/java/org/apache/cxf/rs/security/saml/sso/EHCacheUtilTest.java?rev=1503658&view=auto
==============================================================================
--- cxf/trunk/rt/rs/security/sso/saml/src/test/java/org/apache/cxf/rs/security/saml/sso/EHCacheUtilTest.java
(added)
+++ cxf/trunk/rt/rs/security/sso/saml/src/test/java/org/apache/cxf/rs/security/saml/sso/EHCacheUtilTest.java
Tue Jul 16 11:09:04 2013
@@ -0,0 +1,58 @@
+/**
+ * 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.rs.security.saml.sso;
+
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Status;
+
+import net.sf.ehcache.config.Configuration;
+import net.sf.ehcache.config.ConfigurationFactory;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * 
+ */
+public class EHCacheUtilTest extends Assert {
+
+    @Test
+    public void testCreateCacheManager() {
+        Configuration conf = 
+            ConfigurationFactory.parseConfiguration(EHCacheUtil.class.getResource("/cxf-test-ehcache.xml"));
+            
+        assertNotNull(conf);
+        conf.setName("testCache");
+        
+        CacheManager manager1 = EHCacheUtil.createCacheManager(conf);
+        assertNotNull(manager1);
+        CacheManager manager2 = EHCacheUtil.createCacheManager();
+        assertNotNull(manager2);
+        
+        manager1.shutdown();
+        assertEquals(Status.STATUS_SHUTDOWN, manager1.getStatus());
+        
+        assertEquals(Status.STATUS_ALIVE, manager2.getStatus());
+        
+        manager2.shutdown();
+        assertEquals(Status.STATUS_SHUTDOWN, manager2.getStatus());
+        
+    }
+}

Added: cxf/trunk/rt/rs/security/sso/saml/src/test/resources/cxf-test-ehcache.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/security/sso/saml/src/test/resources/cxf-test-ehcache.xml?rev=1503658&view=auto
==============================================================================
--- cxf/trunk/rt/rs/security/sso/saml/src/test/resources/cxf-test-ehcache.xml (added)
+++ cxf/trunk/rt/rs/security/sso/saml/src/test/resources/cxf-test-ehcache.xml Tue Jul 16 11:09:04
2013
@@ -0,0 +1,16 @@
+<ehcache xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="false" monitoring="autodetect"
dynamicConfig="true">
+
+    <diskStore path="java.io.tmpdir"/>
+
+    <defaultCache
+            maxEntriesLocalHeap="5000"
+            eternal="false"
+            timeToIdleSeconds="3600"
+            timeToLiveSeconds="3600"
+            overflowToDisk="true"
+            maxElementsOnDisk="10000000"
+            diskPersistent="false"
+            diskExpiryThreadIntervalSeconds="120"
+            memoryStoreEvictionPolicy="LRU"
+            />
+</ehcache>

Propchange: cxf/trunk/rt/rs/security/sso/saml/src/test/resources/cxf-test-ehcache.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message