use of org.apache.cxf.Bus in project ddf by codice.
the class MetricsOutInterceptorTest method testHandleMessageWithOneWayClientMessage.
/**
* Test method for
* {@link ddf.metrics.interceptor.MetricsOutInterceptor#handleMessage(org.apache.cxf.message.Message)}
* .
*
* @throws InterruptedException
*/
@Test
public void testHandleMessageWithOneWayClientMessage() {
// Setup
MetricsOutInterceptor outInterceptor = new MetricsOutInterceptor();
Message mockMessage = mock(Message.class);
Exchange ex = new ExchangeImpl();
Bus mockBus = mock(Bus.class);
InterceptorChain mockIc = mock(InterceptorChain.class);
ex.put(Bus.class, mockBus);
ex.setOneWay(true);
when(mockBus.getId()).thenReturn("bus_id");
when(mockMessage.getExchange()).thenReturn(ex);
when(mockMessage.get(Message.PARTIAL_RESPONSE_MESSAGE)).thenReturn("false");
when(mockMessage.get(Message.REQUESTOR_ROLE)).thenReturn(true);
when(mockMessage.getInterceptorChain()).thenReturn(mockIc);
// Perform test
outInterceptor.handleMessage(mockMessage);
// validate that LatencyTimeRecorder.beginHandling was called once
verify(mockMessage, times(1)).getInterceptorChain();
}
use of org.apache.cxf.Bus in project ddf by codice.
the class MetricsOutInterceptorTest method testHandleMessageWithTwoWayClientMessageWithoutLatencyTimeRecorder.
/**
* Test method for
* {@link ddf.metrics.interceptor.MetricsOutInterceptor#handleMessage(org.apache.cxf.message.Message)}
* .
*
* @throws InterruptedException
*/
@Test
public void testHandleMessageWithTwoWayClientMessageWithoutLatencyTimeRecorder() {
// Setup
MetricsOutInterceptor outInterceptor = new MetricsOutInterceptor();
Message mockMessage = mock(Message.class);
Exchange ex = new ExchangeImpl();
Bus mockBus = mock(Bus.class);
ex.put(Bus.class, mockBus);
when(mockBus.getId()).thenReturn("bus_id");
when(mockMessage.getExchange()).thenReturn(ex);
when(mockMessage.get(Message.PARTIAL_RESPONSE_MESSAGE)).thenReturn("false");
when(mockMessage.get(Message.REQUESTOR_ROLE)).thenReturn(true);
// Perform test
outInterceptor.handleMessage(mockMessage);
// validate that an instance of LatencyTimeRecorder was put onto the
// exchange
assertThat(ex.get(LatencyTimeRecorder.class), instanceOf(LatencyTimeRecorder.class));
}
use of org.apache.cxf.Bus in project ddf by codice.
the class SecureProxyServiceFactoryImpl method configureProxyFactoryProperties.
/**
* Configures the JaxWsProxyFactoryBean with the properties that have been set for the particular source.
*/
protected void configureProxyFactoryProperties(JaxWsProxyFactoryBean clientFactory, SecurityToken token, WebServiceProperties wsp) {
String signaturePropertiesPath = stsClientConfig.getSignatureProperties();
String encryptionPropertiesPath = stsClientConfig.getEncryptionProperties();
String stsPropertiesPath = stsClientConfig.getTokenProperties();
LOGGER.debug("Configuring proxy factory properties");
if (wsp.endpointAddress != null) {
LOGGER.debug("Configuring JaxWsProxyFactoryBean");
Bus bus = clientFactory.getBus();
if (bus == null) {
LOGGER.debug("Getting CXF thread default bus.");
bus = BusFactory.getThreadDefaultBus();
}
clientFactory.setWsdlURL(wsp.endpointWsdlURL);
clientFactory.setAddress(wsp.endpointAddress);
clientFactory.setServiceName(wsp.serviceName);
clientFactory.setEndpointName(wsp.endpointName);
clientFactory.setServiceClass(wsp.serviceClass);
LOGGER.debug("Configuring STS Client");
HashMap<String, Object> properties = new HashMap<>();
STSClient stsClient = configureSTSClient(bus);
LOGGER.debug("Setting STSClient");
properties.put(SecurityConstants.STS_CLIENT, stsClient);
if (token != null && token.getToken() != null) {
LOGGER.debug("Setting incoming SAML assertion to outgoing federated client");
properties.put(SecurityConstants.TOKEN, token);
}
if (signaturePropertiesPath != null && !signaturePropertiesPath.isEmpty()) {
LOGGER.debug("Setting signature properties: {}", signaturePropertiesPath);
Properties signatureProperties = PropertiesLoader.loadProperties(signaturePropertiesPath);
properties.put(SecurityConstants.SIGNATURE_PROPERTIES, signatureProperties);
}
if (stsPropertiesPath != null && !stsPropertiesPath.isEmpty()) {
LOGGER.debug("Setting sts properties: {}", stsPropertiesPath);
Properties stsProperties = PropertiesLoader.loadProperties(stsPropertiesPath);
properties.put(SecurityConstants.STS_TOKEN_PROPERTIES, stsProperties);
}
if (encryptionPropertiesPath != null && !encryptionPropertiesPath.isEmpty()) {
LOGGER.debug("Setting encryption properties: {}", encryptionPropertiesPath);
Properties encryptionProperties = PropertiesLoader.loadProperties(encryptionPropertiesPath);
properties.put(SecurityConstants.ENCRYPT_PROPERTIES, encryptionProperties);
}
properties.put(SecurityConstants.DISABLE_STS_CLIENT_WSMEX_CALL_USING_EPR_ADDRESS, Boolean.TRUE.toString());
clientFactory.setProperties(properties);
}
LOGGER.debug("Finished configuring proxy factory properties");
}
use of org.apache.cxf.Bus in project cas by apereo.
the class SecurityTokenServiceClientBuilder method buildClientForSecurityTokenRequests.
/**
* Build client for security token requests.
*
* @param service the rp
* @return the security token service client
*/
public SecurityTokenServiceClient buildClientForSecurityTokenRequests(final WSFederationRegisteredService service) {
final Bus cxfBus = BusFactory.getDefaultBus();
final SecurityTokenServiceClient sts = new SecurityTokenServiceClient(cxfBus);
sts.setAddressingNamespace(StringUtils.defaultIfBlank(service.getAddressingNamespace(), WSFederationConstants.HTTP_WWW_W3_ORG_2005_08_ADDRESSING));
sts.setTokenType(StringUtils.defaultIfBlank(service.getTokenType(), WSConstants.WSS_SAML2_TOKEN_TYPE));
sts.setKeyType(WSFederationConstants.HTTP_DOCS_OASIS_OPEN_ORG_WS_SX_WS_TRUST_200512_BEARER);
sts.setWsdlLocation(prepareWsdlLocation(service));
if (StringUtils.isNotBlank(service.getPolicyNamespace())) {
sts.setWspNamespace(service.getPolicyNamespace());
}
final String namespace = StringUtils.defaultIfBlank(service.getNamespace(), WSFederationConstants.HTTP_DOCS_OASIS_OPEN_ORG_WS_SX_WS_TRUST_200512);
sts.setServiceQName(new QName(namespace, StringUtils.defaultIfBlank(service.getWsdlService(), WSFederationConstants.SECURITY_TOKEN_SERVICE)));
sts.setEndpointQName(new QName(namespace, service.getWsdlEndpoint()));
sts.getProperties().putAll(new HashMap<>());
return sts;
}
use of org.apache.cxf.Bus in project camel by apache.
the class WSSecurityRouteTest method testUsernameToken.
@Test
public void testUsernameToken() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = WSSecurityRouteTest.class.getResource("../client/wssec.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
GreeterService gs = new GreeterService();
Greeter greeter = gs.getGreeterUsernameTokenPort();
((BindingProvider) greeter).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + CXFTestSupport.getPort2() + "/WSSecurityRouteTest/GreeterUsernameTokenPort");
assertEquals("Get a wrong response", "Hello Security", greeter.greetMe("Security"));
}
Aggregations