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 2013/01/10 17:33:46 UTC
svn commit: r1431487 - in /cxf/fediz/branches/1.0.x-fixes: ./
plugins/core/src/main/java/org/apache/cxf/fediz/core/InMemoryTokenReplayCache.java
plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationTest.java
Author: coheigea
Date: Thu Jan 10 16:33:45 2013
New Revision: 1431487
URL: http://svn.apache.org/viewvc?rev=1431487&view=rev
Log:
[FEDIZ-14] - Make the TokenReplayCache implementation configurable in the Fediz configuration
Modified:
cxf/fediz/branches/1.0.x-fixes/ (props changed)
cxf/fediz/branches/1.0.x-fixes/plugins/core/src/main/java/org/apache/cxf/fediz/core/InMemoryTokenReplayCache.java
cxf/fediz/branches/1.0.x-fixes/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationTest.java
Propchange: cxf/fediz/branches/1.0.x-fixes/
------------------------------------------------------------------------------
Merged /cxf/fediz/trunk:r1431484
Modified: cxf/fediz/branches/1.0.x-fixes/plugins/core/src/main/java/org/apache/cxf/fediz/core/InMemoryTokenReplayCache.java
URL: http://svn.apache.org/viewvc/cxf/fediz/branches/1.0.x-fixes/plugins/core/src/main/java/org/apache/cxf/fediz/core/InMemoryTokenReplayCache.java?rev=1431487&r1=1431486&r2=1431487&view=diff
==============================================================================
--- cxf/fediz/branches/1.0.x-fixes/plugins/core/src/main/java/org/apache/cxf/fediz/core/InMemoryTokenReplayCache.java (original)
+++ cxf/fediz/branches/1.0.x-fixes/plugins/core/src/main/java/org/apache/cxf/fediz/core/InMemoryTokenReplayCache.java Thu Jan 10 16:33:45 2013
@@ -27,27 +27,12 @@ import java.util.List;
//[TODO] add properties TokenReplayCacheExpirationPeriod
public final class InMemoryTokenReplayCache<T> implements TokenReplayCache<T> {
- /**
- *
- */
- private static final long serialVersionUID = 7269477566842444549L;
-
- private static TokenReplayCache<String> instance;
-
private List<T> cache;
- private InMemoryTokenReplayCache() {
+ public InMemoryTokenReplayCache() {
cache = Collections.synchronizedList(new ArrayList<T>());
}
- public static synchronized TokenReplayCache<String> getInstance() {
- if (instance != null) {
- return instance;
- }
- instance = new InMemoryTokenReplayCache<String>();
- return instance;
- }
-
@Override
public T getId(T id) {
int index = cache.indexOf(id);
@@ -74,7 +59,6 @@ public final class InMemoryTokenReplayCa
cache.clear();
cache = null;
}
- instance = null;
}
Modified: cxf/fediz/branches/1.0.x-fixes/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationTest.java
URL: http://svn.apache.org/viewvc/cxf/fediz/branches/1.0.x-fixes/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationTest.java?rev=1431487&r1=1431486&r2=1431487&view=diff
==============================================================================
--- cxf/fediz/branches/1.0.x-fixes/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationTest.java (original)
+++ cxf/fediz/branches/1.0.x-fixes/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationTest.java Thu Jan 10 16:33:45 2013
@@ -29,6 +29,9 @@ import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import org.apache.cxf.fediz.common.SecurityTestUtil;
+import org.apache.cxf.fediz.core.EHCacheTokenReplayCache;
+import org.apache.cxf.fediz.core.InMemoryTokenReplayCache;
+import org.apache.cxf.fediz.core.TokenReplayCache;
import org.apache.cxf.fediz.core.config.jaxb.ArgumentType;
import org.apache.cxf.fediz.core.config.jaxb.AudienceUris;
import org.apache.cxf.fediz.core.config.jaxb.CallbackType;
@@ -266,5 +269,47 @@ public class FedizConfigurationTest {
Assert.assertEquals(HOME_REALM_CLASS, fp.getHomeRealm().getValue());
}
+
+ @org.junit.Test
+ public void testTokenReplayCache() throws JAXBException, IOException {
+ FedizConfig config = createConfiguration();
+
+ // Test the default TokenReplayCache
+ TokenReplayCache<String> defaultReplayCache = parseConfigAndReturnTokenReplayCache(config);
+ Assert.assertNotNull(defaultReplayCache);
+ Assert.assertTrue(defaultReplayCache instanceof EHCacheTokenReplayCache);
+
+ // Now test setting another TokenReplayCache
+ ContextConfig contextConfig = config.getContextConfig().get(0);
+ contextConfig.setTokenReplayCache("org.apache.cxf.fediz.core.InMemoryTokenReplayCache");
+
+ TokenReplayCache<String> newReplayCache = parseConfigAndReturnTokenReplayCache(config);
+ Assert.assertNotNull(newReplayCache);
+ Assert.assertTrue(newReplayCache instanceof InMemoryTokenReplayCache);
+
+ // Now test setting another TokenReplayCache
+ contextConfig.setTokenReplayCache("org.apache.cxf.fediz.core.EHCacheTokenReplayCache");
+
+ newReplayCache = parseConfigAndReturnTokenReplayCache(config);
+ Assert.assertNotNull(newReplayCache);
+ Assert.assertTrue(newReplayCache instanceof EHCacheTokenReplayCache);
+ }
+
+ private TokenReplayCache<String> parseConfigAndReturnTokenReplayCache(FedizConfig config)
+ throws JAXBException {
+ final JAXBContext jaxbContext = JAXBContext.newInstance(FedizConfig.class);
+
+ StringWriter writer = new StringWriter();
+ jaxbContext.createMarshaller().marshal(config, writer);
+ StringReader reader = new StringReader(writer.toString());
+
+ FederationConfigurator configurator = new FederationConfigurator();
+ configurator.loadConfig(reader);
+
+ FederationContext fedContext = configurator.getFederationContext(CONFIG_NAME);
+ Assert.assertNotNull(fedContext);
+
+ return fedContext.getTokenReplayCache();
+ }
}
\ No newline at end of file