Search in sources :

Example 1 with EHCacheTokenStore

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;
}
Also used : EHCacheTokenStore(org.apache.cxf.ws.security.tokenstore.EHCacheTokenStore) URL(java.net.URL)

Example 2 with EHCacheTokenStore

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);
}
Also used : Bus(org.apache.cxf.Bus) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) EHCacheTokenStore(org.apache.cxf.ws.security.tokenstore.EHCacheTokenStore) URL(java.net.URL) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) Random(java.util.Random) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) Client(org.apache.cxf.endpoint.Client) TokenStore(org.apache.cxf.ws.security.tokenstore.TokenStore) EHCacheTokenStore(org.apache.cxf.ws.security.tokenstore.EHCacheTokenStore)

Aggregations

URL (java.net.URL)2 EHCacheTokenStore (org.apache.cxf.ws.security.tokenstore.EHCacheTokenStore)2 Random (java.util.Random)1 QName (javax.xml.namespace.QName)1 Service (javax.xml.ws.Service)1 Bus (org.apache.cxf.Bus)1 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)1 Client (org.apache.cxf.endpoint.Client)1 TokenStore (org.apache.cxf.ws.security.tokenstore.TokenStore)1 DoubleItPortType (org.example.contract.doubleit.DoubleItPortType)1