Search in sources :

Example 66 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project camel by apache.

the class SslCxfRsEndpointConfigurer method configureClient.

@Override
public void configureClient(Client client) {
    HTTPConduit httpConduit = (HTTPConduit) WebClient.getConfig(client).getConduit();
    setupHttpConduit(httpConduit);
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit)

Example 67 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project camel by apache.

the class HostnameVerifierCxfEndpointConfigurer method configureClient.

@Override
public void configureClient(Client client) {
    HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
    setupHttpConduit(httpConduit);
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit)

Example 68 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project camel by apache.

the class SslCxfEndpointConfigurer method configureClient.

@Override
public void configureClient(Client client) {
    HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
    setupHttpConduit(httpConduit);
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit)

Example 69 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project ddf by codice.

the class SecureCxfClientFactory method configureTimeouts.

/**
     * Configures the connection and receive timeouts. If any of the parameters are null, the timeouts
     * will be set to the system default.
     *
     * @param clientConfiguration Client configuration used for outgoing requests.
     * @param connectionTimeout   Connection timeout in milliseconds.
     * @param receiveTimeout      Receive timeout in milliseconds.
     */
protected void configureTimeouts(ClientConfiguration clientConfiguration, Integer connectionTimeout, Integer receiveTimeout) {
    HTTPConduit httpConduit = clientConfiguration.getHttpConduit();
    if (httpConduit == null) {
        LOGGER.info("HTTPConduit was null for {}. Unable to configure timeouts", this);
        return;
    }
    HTTPClientPolicy httpClientPolicy = httpConduit.getClient();
    if (httpClientPolicy == null) {
        httpClientPolicy = new HTTPClientPolicy();
    }
    if (connectionTimeout != null) {
        httpClientPolicy.setConnectionTimeout(connectionTimeout);
    } else {
        httpClientPolicy.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
    }
    if (receiveTimeout != null) {
        httpClientPolicy.setReceiveTimeout(receiveTimeout);
    } else {
        httpClientPolicy.setReceiveTimeout(DEFAULT_RECEIVE_TIMEOUT);
    }
    if (httpClientPolicy.isSetConnectionTimeout()) {
        LOGGER.debug("Connection timeout has been set.");
    } else {
        LOGGER.debug("Connection timeout has NOT been set.");
    }
    if (httpClientPolicy.isSetReceiveTimeout()) {
        LOGGER.debug("Receive timeout has been set.");
    } else {
        LOGGER.debug("Receive timeout has NOT been set.");
    }
    httpConduit.setClient(httpClientPolicy);
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy)

Example 70 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project ddf by codice.

the class SecureCxfClientFactory method configureConduit.

private void configureConduit(ClientConfiguration clientConfig) {
    HTTPConduit httpConduit = clientConfig.getHttpConduit();
    if (httpConduit == null) {
        LOGGER.info("HTTPConduit was null for {}. Unable to configure security.", this);
        return;
    }
    if (allowRedirects) {
        HTTPClientPolicy clientPolicy = httpConduit.getClient();
        if (clientPolicy != null) {
            clientPolicy.setAutoRedirect(true);
            Bus bus = clientConfig.getBus();
            if (bus != null) {
                bus.getProperties().put("http.redirect.relative.uri", true);
            }
        }
    }
    TLSClientParameters tlsParams = httpConduit.getTlsClientParameters();
    if (tlsParams == null) {
        tlsParams = new TLSClientParameters();
    }
    tlsParams.setDisableCNCheck(disableCnCheck);
    tlsParams.setUseHttpsURLConnectionDefaultHostnameVerifier(true);
    tlsParams.setUseHttpsURLConnectionDefaultSslSocketFactory(true);
    String cipherSuites = System.getProperty("https.cipherSuites");
    if (cipherSuites != null) {
        tlsParams.setCipherSuites(Arrays.asList(cipherSuites.split(",")));
    }
    KeyStore keyStore = null;
    KeyStore trustStore = null;
    try {
        keyStore = SecurityConstants.newKeystore();
        trustStore = SecurityConstants.newTruststore();
    } catch (KeyStoreException e) {
        LOGGER.debug("Unable to create keystore instance of type {}", System.getProperty(SecurityConstants.KEYSTORE_TYPE), e);
    }
    Path keyStoreFile = Paths.get(SecurityConstants.getKeystorePath());
    Path trustStoreFile = Paths.get(SecurityConstants.getTruststorePath());
    String ddfHome = System.getProperty("ddf.home");
    if (ddfHome != null) {
        Path ddfHomePath = Paths.get(ddfHome);
        if (!keyStoreFile.isAbsolute()) {
            keyStoreFile = Paths.get(ddfHomePath.toString(), keyStoreFile.toString());
        }
        if (!trustStoreFile.isAbsolute()) {
            trustStoreFile = Paths.get(ddfHomePath.toString(), trustStoreFile.toString());
        }
    }
    String keyStorePassword = SecurityConstants.getKeystorePassword();
    String trustStorePassword = SecurityConstants.getTruststorePassword();
    if (!Files.isReadable(keyStoreFile) || !Files.isReadable(trustStoreFile)) {
        LOGGER.debug("Unable to read system key/trust store files: [ {} ] [ {} ]", keyStoreFile, trustStoreFile);
        return;
    }
    try (InputStream kfis = Files.newInputStream(keyStoreFile)) {
        if (keyStore != null) {
            keyStore.load(kfis, keyStorePassword.toCharArray());
        }
    } catch (NoSuchAlgorithmException | CertificateException | IOException e) {
        LOGGER.debug("Unable to load system key file.", e);
    }
    try (InputStream tfis = Files.newInputStream(trustStoreFile)) {
        if (trustStore != null) {
            trustStore.load(tfis, trustStorePassword.toCharArray());
        }
    } catch (NoSuchAlgorithmException | CertificateException | IOException e) {
        LOGGER.debug("Unable to load system trust file.", e);
    }
    try {
        KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        keyManagerFactory.init(keyStore, keyStorePassword.toCharArray());
        tlsParams.setKeyManagers(keyManagerFactory.getKeyManagers());
    } catch (NoSuchAlgorithmException | KeyStoreException | UnrecoverableKeyException e) {
        LOGGER.debug("Unable to initialize KeyManagerFactory.", e);
    }
    try {
        TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        trustManagerFactory.init(trustStore);
        tlsParams.setTrustManagers(trustManagerFactory.getTrustManagers());
    } catch (NoSuchAlgorithmException | KeyStoreException e) {
        LOGGER.debug("Unable to initialize TrustManagerFactory.", e);
    }
    tlsParams.setCertAlias(SystemBaseUrl.getHost());
    httpConduit.setTlsClientParameters(tlsParams);
}
Also used : Path(java.nio.file.Path) Bus(org.apache.cxf.Bus) TLSClientParameters(org.apache.cxf.configuration.jsse.TLSClientParameters) InputStream(java.io.InputStream) CertificateException(java.security.cert.CertificateException) KeyStoreException(java.security.KeyStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) KeyStore(java.security.KeyStore) KeyManagerFactory(javax.net.ssl.KeyManagerFactory) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) UnrecoverableKeyException(java.security.UnrecoverableKeyException) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy)

Aggregations

HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)125 Client (org.apache.cxf.endpoint.Client)52 HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)47 Test (org.junit.Test)42 URL (java.net.URL)35 Bus (org.apache.cxf.Bus)32 TLSClientParameters (org.apache.cxf.configuration.jsse.TLSClientParameters)32 QName (javax.xml.namespace.QName)22 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)20 Service (javax.xml.ws.Service)16 KeyStore (java.security.KeyStore)15 AuthorizationPolicy (org.apache.cxf.configuration.security.AuthorizationPolicy)15 Greeter (org.apache.hello_world.Greeter)14 SOAPService (org.apache.hello_world.services.SOAPService)14 TrustManager (javax.net.ssl.TrustManager)13 IOException (java.io.IOException)12 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)11 InputStream (java.io.InputStream)8 X509TrustManager (javax.net.ssl.X509TrustManager)8 BindingProvider (javax.xml.ws.BindingProvider)8