Author: coheigea
Date: Wed Jun 20 15:33:57 2012
New Revision: 1352162
URL: http://svn.apache.org/viewvc?rev=1352162&view=rev
Log:
Use configured defaults for cache size etc. for the SAML SSO work.
- Also give the ability to configure caches "per-bus".
Added:
cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/EHCacheUtil.java
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/RequestAssertionConsumerService.java
cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/state/EHCacheSPStateManager.java
cxf/trunk/rt/rs/security/sso/saml/src/main/resources/cxf-samlp-ehcache.xml
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=1352162&r1=1352161&r2=1352162&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
Wed Jun 20 15:33:57 2012
@@ -19,6 +19,7 @@
package org.apache.cxf.rs.security.saml.sso;
+import java.io.File;
import java.io.IOException;
import java.net.URL;
@@ -26,7 +27,11 @@ import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
+import net.sf.ehcache.config.CacheConfiguration;
+import net.sf.ehcache.config.Configuration;
+import net.sf.ehcache.config.ConfigurationFactory;
+import org.apache.cxf.Bus;
import org.apache.ws.security.util.Loader;
/**
@@ -37,29 +42,51 @@ public class EHCacheTokenReplayCache imp
public static final long DEFAULT_TTL = 3600L;
public static final long MAX_TTL = DEFAULT_TTL * 12L;
- private static final String CACHE_KEY = "cxf-samlp-replay-cache";
+ public static final String CACHE_KEY = "cxf-samlp-replay-cache";
+
private Ehcache cache;
private CacheManager cacheManager;
private long ttl = DEFAULT_TTL;
public EHCacheTokenReplayCache() {
+ this((Bus)null);
+ }
+
+ public EHCacheTokenReplayCache(Bus bus) {
String defaultConfigFile = "cxf-samlp-ehcache.xml";
URL configFileURL = Loader.getResource(defaultConfigFile);
- createCache(configFileURL);
+ createCache(configFileURL, bus);
}
public EHCacheTokenReplayCache(URL configFileURL) {
- createCache(configFileURL);
+ createCache(configFileURL, null);
}
- private void createCache(URL configFileURL) {
+ public EHCacheTokenReplayCache(URL configFileURL, Bus bus) {
+ createCache(configFileURL, bus);
+ }
+
+ private void createCache(URL configFileURL, Bus bus) {
if (configFileURL == null) {
cacheManager = CacheManager.create();
} else {
- cacheManager = CacheManager.create(configFileURL);
+ Configuration conf =
ConfigurationFactory.parseConfiguration(configFileURL);
+
+ if (bus != null) {
+ 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);
+ }
+ }
+
+ cacheManager = CacheManager.create(conf);
}
- Ehcache newCache = new Cache(CACHE_KEY, 50000, true, false,
DEFAULT_TTL, DEFAULT_TTL);
+ CacheConfiguration cc = EHCacheUtil.getCacheConfiguration(CACHE_KEY,
cacheManager);
+
+ Ehcache newCache = new Cache(cc);
cache = cacheManager.addCacheIfAbsent(newCache);
}
Added:
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=1352162&view=auto
==============================================================================
---
cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/EHCacheUtil.java
(added)
+++
cxf/trunk/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/EHCacheUtil.java
Wed Jun 20 15:33:57 2012
@@ -0,0 +1,50 @@
+/**
+ * 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.config.CacheConfiguration;
+
+/**
+ */
+public final class EHCacheUtil {
+
+ private EHCacheUtil() {
+ //
+ }
+
+ public static CacheConfiguration getCacheConfiguration(String key,
CacheManager cacheManager) {
+ CacheConfiguration cc =
cacheManager.getConfiguration().getCacheConfigurations().get(key);
+ if (cc == null && key.contains("-")) {
+ cc =
cacheManager.getConfiguration().getCacheConfigurations().get(key.substring(0,
key.indexOf('-')));
+ }
+ if (cc == null) {
+ cc =
cacheManager.getConfiguration().getDefaultCacheConfiguration();
+ }
+ if (cc == null) {
+ cc = new CacheConfiguration();
+ } else {
+ cc = (CacheConfiguration)cc.clone();
+ }
+ cc.setName(key);
+ return cc;
+ }
+
+}
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=1352162&r1=1352161&r2=1352162&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
Wed Jun 20 15:33:57 2012
@@ -45,6 +45,7 @@ import javax.ws.rs.core.Response;
import org.w3c.dom.Document;
+import org.apache.cxf.Bus;
import org.apache.cxf.common.i18n.BundleUtils;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.common.util.Base64Exception;
@@ -93,7 +94,8 @@ public class RequestAssertionConsumerSer
public TokenReplayCache<String> getReplayCache() {
if (replayCache == null) {
- replayCache = new EHCacheTokenReplayCache();
+ Bus bus =
(Bus)messageContext.getContextualProperty(Bus.class.getName());
+ replayCache = new EHCacheTokenReplayCache(bus);
}
return replayCache;
}
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=1352162&r1=1352161&r2=1352162&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
Wed Jun 20 15:33:57 2012
@@ -18,6 +18,7 @@
*/
package org.apache.cxf.rs.security.saml.sso.state;
+import java.io.File;
import java.io.IOException;
import java.net.URL;
@@ -25,7 +26,12 @@ import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
+import net.sf.ehcache.config.CacheConfiguration;
+import net.sf.ehcache.config.Configuration;
+import net.sf.ehcache.config.ConfigurationFactory;
+import org.apache.cxf.Bus;
+import org.apache.cxf.rs.security.saml.sso.EHCacheUtil;
import org.apache.ws.security.util.Loader;
/**
@@ -35,34 +41,58 @@ import org.apache.ws.security.util.Loade
public class EHCacheSPStateManager implements SPStateManager {
public static final long DEFAULT_TTL = 60L * 5L;
- private static final String REQUEST_CACHE_KEY =
"cxf-samlp-request-state-cache";
- private static final String RESPONSE_CACHE_KEY =
"cxf-samlp-response-state-cache";
+ 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 Ehcache requestCache;
private Ehcache responseCache;
private CacheManager cacheManager;
private long ttl = DEFAULT_TTL;
public EHCacheSPStateManager() {
+ this((Bus)null);
+ }
+
+ public EHCacheSPStateManager(Bus bus) {
String defaultConfigFile = "cxf-samlp-ehcache.xml";
URL configFileURL = Loader.getResource(defaultConfigFile);
- createCaches(configFileURL);
+ createCaches(configFileURL, bus);
}
public EHCacheSPStateManager(URL configFileURL) {
- createCaches(configFileURL);
+ this(configFileURL, null);
+ }
+
+ public EHCacheSPStateManager(URL configFileURL, Bus bus) {
+ createCaches(configFileURL, bus);
}
- private void createCaches(URL configFileURL) {
+ private void createCaches(URL configFileURL, Bus bus) {
if (configFileURL == null) {
cacheManager = CacheManager.create();
} else {
- cacheManager = CacheManager.create(configFileURL);
+ Configuration conf =
ConfigurationFactory.parseConfiguration(configFileURL);
+
+ if (bus != null) {
+ 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);
+ }
+ }
+
+ cacheManager = CacheManager.create(conf);
}
- Ehcache newCache = new Cache(REQUEST_CACHE_KEY, 50000, true, false,
DEFAULT_TTL, DEFAULT_TTL);
+ CacheConfiguration requestCC =
EHCacheUtil.getCacheConfiguration(REQUEST_CACHE_KEY, cacheManager);
+
+ Ehcache newCache = new Cache(requestCC);
requestCache = cacheManager.addCacheIfAbsent(newCache);
- newCache = new Cache(RESPONSE_CACHE_KEY, 50000, true, false,
DEFAULT_TTL, DEFAULT_TTL);
+ CacheConfiguration responseCC =
EHCacheUtil.getCacheConfiguration(RESPONSE_CACHE_KEY, cacheManager);
+
+ newCache = new Cache(responseCC);
responseCache = cacheManager.addCacheIfAbsent(newCache);
}
Modified:
cxf/trunk/rt/rs/security/sso/saml/src/main/resources/cxf-samlp-ehcache.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/rs/security/sso/saml/src/main/resources/cxf-samlp-ehcache.xml?rev=1352162&r1=1352161&r2=1352162&view=diff
==============================================================================
--- cxf/trunk/rt/rs/security/sso/saml/src/main/resources/cxf-samlp-ehcache.xml
(original)
+++ cxf/trunk/rt/rs/security/sso/saml/src/main/resources/cxf-samlp-ehcache.xml
Wed Jun 20 15:33:57 2012
@@ -3,7 +3,7 @@
<diskStore path="java.io.tmpdir"/>
<defaultCache
- maxElementsInMemory="50000"
+ maxEntriesLocalHeap="5000"
eternal="false"
timeToIdleSeconds="3600"
timeToLiveSeconds="3600"