use of org.apache.cxf.ws.security.tokenstore.TokenStore in project cxf by apache.
the class CachingTest method testCachePerProxySymmetric.
@org.junit.Test
public void testCachePerProxySymmetric() 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, "DoubleItCachePerProxySymmetricPort");
// First invocation
DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
updateAddressPort(port, test.getPort());
((BindingProvider) port).getRequestContext().put(SecurityConstants.CACHE_IDENTIFIER, "proxy1");
((BindingProvider) port).getRequestContext().put(SecurityConstants.CACHE_CONFIG_FILE, "per-proxy-cache.xml");
if (test.isStreaming()) {
SecurityTestUtil.enableStreaming(port);
}
assertEquals(50, port.doubleIt(25));
Client client = ClientProxy.getClient(port);
TokenStore tokenStore = (TokenStore) client.getEndpoint().getEndpointInfo().getProperty(SecurityConstants.TOKEN_STORE_CACHE_INSTANCE);
assertNotNull(tokenStore);
// 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());
((BindingProvider) port2).getRequestContext().put(SecurityConstants.CACHE_IDENTIFIER, "proxy2");
((BindingProvider) port2).getRequestContext().put(SecurityConstants.CACHE_CONFIG_FILE, "per-proxy-cache.xml");
if (test.isStreaming()) {
SecurityTestUtil.enableStreaming(port2);
}
assertEquals(70, port2.doubleIt(35));
client = ClientProxy.getClient(port2);
tokenStore = (TokenStore) client.getEndpoint().getEndpointInfo().getProperty(SecurityConstants.TOKEN_STORE_CACHE_INSTANCE);
assertNotNull(tokenStore);
// We expect two tokens as the identifier + SHA-1 are cached
assertEquals(2, tokenStore.getTokenIdentifiers().size());
((java.io.Closeable) port).close();
((java.io.Closeable) port2).close();
bus.shutdown(true);
}
use of org.apache.cxf.ws.security.tokenstore.TokenStore in project cxf by apache.
the class CachingTest method testSymmetric.
// By default, we have one cache per-proxy
@org.junit.Test
public void testSymmetric() 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());
if (test.isStreaming()) {
SecurityTestUtil.enableStreaming(port);
}
assertEquals(50, port.doubleIt(25));
Client client = ClientProxy.getClient(port);
TokenStore tokenStore = (TokenStore) client.getEndpoint().getEndpointInfo().getProperty(SecurityConstants.TOKEN_STORE_CACHE_INSTANCE);
assertNotNull(tokenStore);
// 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());
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 two tokens as the identifier + SHA-1 are cached
assertEquals(2, tokenStore.getTokenIdentifiers().size());
((java.io.Closeable) port).close();
// port2 is still holding onto the cache, thus, this should still be 2
assertEquals(2, tokenStore.getTokenIdentifiers().size());
((java.io.Closeable) port2).close();
bus.shutdown(true);
}
use of org.apache.cxf.ws.security.tokenstore.TokenStore in project cxf by apache.
the class CacheCleanupListener method shutdownResources.
protected void shutdownResources(EndpointInfo info) {
TokenStore ts = (TokenStore) info.getProperty(SecurityConstants.TOKEN_STORE_CACHE_INSTANCE);
if (ts instanceof Closeable) {
close((Closeable) ts);
}
ReplayCache rc = (ReplayCache) info.getProperty(SecurityConstants.NONCE_CACHE_INSTANCE);
if (rc != null) {
close(rc);
}
rc = (ReplayCache) info.getProperty(SecurityConstants.TIMESTAMP_CACHE_INSTANCE);
if (rc != null) {
close(rc);
}
rc = (ReplayCache) info.getProperty(SecurityConstants.SAML_ONE_TIME_USE_CACHE_INSTANCE);
if (rc != null) {
close(rc);
}
}
use of org.apache.cxf.ws.security.tokenstore.TokenStore in project cxf by apache.
the class DefaultSTSTokenCacher method storeToken.
public void storeToken(Message message, Element delegationToken, String secTokenId, String cacheKey) throws TokenStoreException {
if (secTokenId == null || delegationToken == null) {
return;
}
TokenStore tokenStore = TokenStoreUtils.getTokenStore(message);
String id = getIdFromToken(delegationToken);
SecurityToken cachedToken = tokenStore.getToken(id);
if (cachedToken == null) {
cachedToken = new SecurityToken(id);
cachedToken.setToken(delegationToken);
}
Map<String, Object> properties = cachedToken.getProperties();
if (properties == null) {
properties = new HashMap<>();
cachedToken.setProperties(properties);
}
properties.put(cacheKey, secTokenId);
tokenStore.add(cachedToken);
}
use of org.apache.cxf.ws.security.tokenstore.TokenStore in project cxf by apache.
the class NegotiationUtils method recalcEffectivePolicy.
static void recalcEffectivePolicy(SoapMessage message, String namespace, Policy policy, Invoker invoker, boolean secConv) {
Exchange ex = message.getExchange();
Bus bus = ex.getBus();
PolicyEngine pe = bus.getExtension(PolicyEngine.class);
if (null == pe) {
return;
}
Destination destination = ex.getDestination();
try {
Endpoint endpoint = message.getExchange().getEndpoint();
TokenStore store = TokenStoreUtils.getTokenStore(message);
if (secConv) {
endpoint = STSUtils.createSCEndpoint(bus, namespace, endpoint.getEndpointInfo().getTransportId(), destination.getAddress().getAddress().getValue(), message.getVersion().getBindingId(), policy);
} else {
endpoint = STSUtils.createSTSEndpoint(bus, namespace, endpoint.getEndpointInfo().getTransportId(), destination.getAddress().getAddress().getValue(), message.getVersion().getBindingId(), policy, null);
}
endpoint.getEndpointInfo().setProperty(TokenStore.class.getName(), store);
message.getExchange().put(TokenStore.class.getName(), store);
EndpointPolicy ep = pe.getServerEndpointPolicy(endpoint.getEndpointInfo(), destination, message);
List<Interceptor<? extends Message>> interceptors = ep.getInterceptors(message);
message.getInterceptorChain().add(interceptors);
Collection<Assertion> assertions = ep.getVocabulary(message);
if (null != assertions) {
message.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
}
endpoint.getService().setInvoker(invoker);
ex.put(Endpoint.class, endpoint);
ex.put(Service.class, endpoint.getService());
ex.put(org.apache.cxf.binding.Binding.class, endpoint.getBinding());
ex.remove(BindingOperationInfo.class);
message.put(MAPAggregator.ACTION_VERIFIED, Boolean.TRUE);
} catch (Exception exc) {
throw new Fault(exc);
}
}
Aggregations