use of org.apache.cxf.configuration.security.AuthorizationPolicy in project jbpm by kiegroup.
the class WebServiceCommandTest method testExecuteCommandWithBasicAuth.
@Test
public void testExecuteCommandWithBasicAuth() throws Exception {
Object[] clientObject = Arrays.asList("testResults").toArray();
when(clients.containsKey(any())).thenReturn(true);
when(clients.get(any())).thenReturn(client);
when(client.invoke(Mockito.<String>any(), any())).thenReturn(clientObject);
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Interface", "someInterface");
workItem.setParameter("Operation", "someOperation");
workItem.setParameter("Username", "testUserName");
workItem.setParameter("Password", "testPassword");
when(commandContext.getData(anyString())).thenReturn(workItem);
HTTPConduit http = Mockito.mock(HTTPConduit.class, Mockito.CALLS_REAL_METHODS);
when(client.getConduit()).thenReturn(http);
WebServiceCommand command = new WebServiceCommand();
command.setClients(clients);
ExecutionResults results = command.execute(commandContext);
assertNotNull(results);
assertEquals("testResults", results.getData("Result"));
assertNotNull(http.getAuthorization());
AuthorizationPolicy authorizationPolicy = http.getAuthorization();
assertEquals("Basic", authorizationPolicy.getAuthorizationType());
assertEquals("testUserName", authorizationPolicy.getUserName());
assertEquals("testPassword", authorizationPolicy.getPassword());
}
use of org.apache.cxf.configuration.security.AuthorizationPolicy in project jbpm by kiegroup.
the class WebServiceWorkItemHandlerTest method testExecuteSyncOperationWithBasicAuth.
@Test
public void testExecuteSyncOperationWithBasicAuth() throws Exception {
HTTPConduit http = Mockito.mock(HTTPConduit.class, Mockito.CALLS_REAL_METHODS);
when(client.getConduit()).thenReturn(http);
TestWorkItemManager manager = new TestWorkItemManager();
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Interface", "someInterface");
workItem.setParameter("Operation", "someOperation");
workItem.setParameter("Parameter", "myParam");
workItem.setParameter("Mode", "SYNC");
WebServiceWorkItemHandler handler = new WebServiceWorkItemHandler(kieSession, "testusername", "testpassword");
handler.setClients(clients);
handler.executeWorkItem(workItem, manager);
assertNotNull(manager.getResults());
assertEquals(1, manager.getResults().size());
assertTrue(manager.getResults().containsKey(workItem.getId()));
assertNotNull(http.getAuthorization());
AuthorizationPolicy authorizationPolicy = http.getAuthorization();
assertEquals("Basic", authorizationPolicy.getAuthorizationType());
assertEquals("testusername", authorizationPolicy.getUserName());
assertEquals("testpassword", authorizationPolicy.getPassword());
}
use of org.apache.cxf.configuration.security.AuthorizationPolicy in project jbossws-cxf by jbossws.
the class ClientConfigConduitSelector method setAuthorizationPolicyCredentials.
private void setAuthorizationPolicyCredentials(Message message, HTTPConduit c) {
if (message.getContextualProperty(CLIENT_USERNAME) != null && ((message.getContextualProperty(CLIENT_HTTP_MECHANISM) == null && message.getContextualProperty(CLIENT_WS_SECURITY_TYPE) == null) || message.getContextualProperty(CLIENT_HTTP_MECHANISM) != null && message.getContextualProperty(CLIENT_HTTP_MECHANISM).toString().equalsIgnoreCase("basic"))) {
String defaultUsername = (String) message.get(BindingProvider.USERNAME_PROPERTY);
String defaultPassword = (String) message.get(BindingProvider.PASSWORD_PROPERTY);
AuthorizationPolicy authorizationPolicy = new AuthorizationPolicy();
authorizationPolicy.setUserName(defaultUsername == null ? message.getContextualProperty(CLIENT_USERNAME).toString() : defaultUsername);
authorizationPolicy.setPassword(defaultPassword == null ? message.getContextualProperty(CLIENT_PASSWORD).toString() : defaultPassword);
c.setAuthorization(authorizationPolicy);
}
}
use of org.apache.cxf.configuration.security.AuthorizationPolicy in project ipf by oehf.
the class WsSecurityInformation method configureHttpConduit.
protected void configureHttpConduit(HTTPConduit httpConduit) {
if (isSecure()) {
var tlsClientParameters = httpConduit.getTlsClientParameters();
// otherwise we overwrite TLSClientParameters if a custom SslContext is configured
if (tlsClientParameters == null) {
tlsClientParameters = new TLSClientParameters();
maybeUpdateSslContext(tlsClientParameters, true);
} else {
maybeUpdateSslContext(tlsClientParameters, false);
}
if (getHostnameVerifier() != null) {
tlsClientParameters.setHostnameVerifier(getHostnameVerifier());
}
httpConduit.setTlsClientParameters(tlsClientParameters);
}
if (getUsername() != null) {
var authorizationPolicy = new AuthorizationPolicy();
authorizationPolicy.setUserName(getUsername());
authorizationPolicy.setPassword(getPassword());
httpConduit.setAuthorization(authorizationPolicy);
}
}
use of org.apache.cxf.configuration.security.AuthorizationPolicy in project fh by assecopl.
the class WebServiceClientUtil method createBasicPort.
protected <E> E createBasicPort(Class<E> serviceCalzz, String address, String user, String password, AuthorizationTypeEnum authType, boolean logOn, Map<String, List<String>> headers, String proxyHost, Integer proxyPort, String proxyUser, String proxyPassword) {
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(serviceCalzz);
factory.setAddress(address);
List features = new ArrayList<>(factory.getFeatures());
WSPolicyFeature wsPolicyFeature = new WSPolicyFeature();
wsPolicyFeature.setEnabled(true);
wsPolicyFeature.setIgnoreUnknownAssertions(true);
features.add(wsPolicyFeature);
factory.setFeatures(features);
E port = (E) factory.create();
Client client = ClientProxy.getClient(port);
HTTPConduit http = (HTTPConduit) client.getConduit();
if (authType != null) {
AuthorizationPolicy authPolicy = new AuthorizationPolicy();
authPolicy.setAuthorizationType(authType.name());
authPolicy.setUserName(user);
authPolicy.setPassword(password);
http.setAuthorization(authPolicy);
}
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(conectTimeout);
httpClientPolicy.setReceiveTimeout(requestTimeout);
if (StringUtils.isNotBlank(proxyHost) && proxyPort != null) {
httpClientPolicy.setProxyServerType(ProxyServerType.HTTP);
httpClientPolicy.setProxyServer(proxyHost);
httpClientPolicy.setProxyServerPort(proxyPort);
}
http.setClient(httpClientPolicy);
Map<String, Object> requestContext = client.getRequestContext();
requestContext.put(CONNECT_TIMEOUT, httpClientPolicy.getConnectionTimeout());
// Timeout in millis
requestContext.put(REQUEST_TIMEOUT, httpClientPolicy.getReceiveTimeout());
// Add HTTP headers to the web service request
if (headers != null) {
requestContext.put(Message.PROTOCOL_HEADERS, headers);
}
if (address.startsWith("https") || customSSLSocketFactory != null) {
HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
if (customSSLSocketFactory == null) {
customSSLSocketFactory = new BlindSSLSocketFactory();
}
TLSClientParameters tlsCP = new TLSClientParameters();
// you can set up the SSLSocketFactory on the TLSClientParameter
tlsCP.setSSLSocketFactory(customSSLSocketFactory);
tlsCP.setDisableCNCheck(true);
// setup the TLSClientParameters on the HttpConduit
httpConduit.setTlsClientParameters(tlsCP);
}
if (configInterceptors != null) {
configInterceptors.addInterceptor(client);
}
if (!logOn) {
removeLoggingInterceptors(client);
}
if (configWebServiceClient != null) {
configWebServiceClient.configPort(port);
}
return port;
}
Aggregations