Search in sources :

Example 81 with AuthorizationPolicy

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());
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) ExecutionResults(org.kie.api.executor.ExecutionResults) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) Test(org.junit.Test)

Example 82 with AuthorizationPolicy

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());
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) TestWorkItemManager(org.jbpm.process.workitem.core.TestWorkItemManager) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) Test(org.junit.Test)

Example 83 with AuthorizationPolicy

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);
    }
}
Also used : AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy)

Example 84 with 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);
    }
}
Also used : TLSClientParameters(org.apache.cxf.configuration.jsse.TLSClientParameters) AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy)

Example 85 with 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;
}
Also used : TLSClientParameters(org.apache.cxf.configuration.jsse.TLSClientParameters) WSPolicyFeature(org.apache.cxf.ws.policy.WSPolicyFeature) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) ArrayList(java.util.ArrayList) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) BlindSSLSocketFactory(pl.fhframework.dp.commons.utils.net.BlindSSLSocketFactory) ArrayList(java.util.ArrayList) List(java.util.List) Client(org.apache.cxf.endpoint.Client)

Aggregations

AuthorizationPolicy (org.apache.cxf.configuration.security.AuthorizationPolicy)86 Message (org.apache.cxf.message.Message)25 Test (org.junit.Test)22 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)16 IOException (java.io.IOException)15 ArrayList (java.util.ArrayList)11 Client (org.apache.cxf.endpoint.Client)11 List (java.util.List)9 HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)9 URL (java.net.URL)7 HashMap (java.util.HashMap)7 ProxyAuthorizationPolicy (org.apache.cxf.configuration.security.ProxyAuthorizationPolicy)7 Map (java.util.Map)6 SecurityContext (org.apache.cxf.security.SecurityContext)6 Bus (org.apache.cxf.Bus)5 TLSClientParameters (org.apache.cxf.configuration.jsse.TLSClientParameters)5 WebClient (org.apache.cxf.jaxrs.client.WebClient)5 MessageImpl (org.apache.cxf.message.MessageImpl)5 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)5 Principal (java.security.Principal)4