use of org.apache.cxf.ws.security.tokenstore.EHCacheTokenStore in project cxf by apache.
the class STSLoginModule method configureTokenStore.
private TokenStore configureTokenStore() throws MalformedURLException {
if (TokenStoreFactory.isEhCacheInstalled()) {
String cfg = "cxf-ehcache.xml";
URL url = null;
if (url == null) {
url = ClassLoaderUtils.getResource(cfg, STSLoginModule.class);
}
if (url == null) {
url = new URL(cfg);
}
if (url != null) {
return new EHCacheTokenStore(TOKEN_STORE_KEY, BusFactory.getDefaultBus(), url);
}
}
return null;
}
use of org.apache.cxf.ws.security.tokenstore.EHCacheTokenStore in project cxf by apache.
the class CachingTest method testSymmetricSharedCache.
// Here we manually create a cache and share it for both proxies
@org.junit.Test
public void testSymmetricSharedCache() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = CachingTest.class.getResource("client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
URL wsdl = CachingTest.class.getResource("DoubleItCache.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItCacheSymmetricPort");
// First invocation
DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
updateAddressPort(port, test.getPort());
// Create shared cache
String cacheKey = SecurityConstants.TOKEN_STORE_CACHE_INSTANCE + '-' + Math.abs(new Random().nextInt());
TokenStore tokenStore = new EHCacheTokenStore(cacheKey, bus, ClassLoaderUtils.getResource("cxf-ehcache.xml", this.getClass()));
Client client = ClientProxy.getClient(port);
client.getEndpoint().getEndpointInfo().setProperty(SecurityConstants.TOKEN_STORE_CACHE_INSTANCE, tokenStore);
if (test.isStreaming()) {
SecurityTestUtil.enableStreaming(port);
}
assertEquals(50, port.doubleIt(25));
// We expect two tokens as the identifier + SHA-1 are cached
assertEquals(2, tokenStore.getTokenIdentifiers().size());
// Second invocation
DoubleItPortType port2 = service.getPort(portQName, DoubleItPortType.class);
updateAddressPort(port2, test.getPort());
client = ClientProxy.getClient(port2);
client.getEndpoint().getEndpointInfo().setProperty(SecurityConstants.TOKEN_STORE_CACHE_INSTANCE, tokenStore);
if (test.isStreaming()) {
SecurityTestUtil.enableStreaming(port2);
}
port2.doubleIt(35);
client = ClientProxy.getClient(port2);
tokenStore = (TokenStore) client.getEndpoint().getEndpointInfo().getProperty(SecurityConstants.TOKEN_STORE_CACHE_INSTANCE);
assertNotNull(tokenStore);
// We expect four tokens as the identifier + SHA-1 are cached
assertEquals(4, tokenStore.getTokenIdentifiers().size());
((java.io.Closeable) port).close();
((java.io.Closeable) port2).close();
bus.shutdown(true);
}
Aggregations