Example usage for org.apache.http.conn.ssl TrustStrategy TrustStrategy

List of usage examples for org.apache.http.conn.ssl TrustStrategy TrustStrategy

Introduction

In this page you can find the example usage for org.apache.http.conn.ssl TrustStrategy TrustStrategy.

Prototype

TrustStrategy

Source Link

Usage

From source file:de.tsystems.mms.apm.performancesignature.viewer.rest.model.CustomJenkinsHttpClient.java

private static HttpClientBuilder createHttpClientBuilder(final boolean verifyCertificate,
        final CustomProxy customProxy) {

    HttpClientBuilder httpClientBuilder = HttpClients.custom();
    httpClientBuilder.useSystemProperties();
    if (!verifyCertificate) {
        SSLContextBuilder builder = new SSLContextBuilder();
        try {//www . j  ava 2 s  .c  om
            builder.loadTrustMaterial(null, new TrustStrategy() {
                public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                    return true;
                }
            });
            httpClientBuilder.setSSLSocketFactory(new SSLConnectionSocketFactory(builder.build()));
        } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) {
            LOGGER.severe(ExceptionUtils.getFullStackTrace(e));
        }

    }
    if (customProxy != null) {
        Jenkins jenkins = PerfSigUIUtils.getInstance();
        if (customProxy.isUseJenkinsProxy() && jenkins.proxy != null) {
            final ProxyConfiguration proxyConfiguration = jenkins.proxy;
            if (StringUtils.isNotBlank(proxyConfiguration.name) && proxyConfiguration.port > 0) {
                httpClientBuilder.setProxy(new HttpHost(proxyConfiguration.name, proxyConfiguration.port));
                if (StringUtils.isNotBlank(proxyConfiguration.getUserName())) {
                    CredentialsProvider credsProvider = new BasicCredentialsProvider();
                    UsernamePasswordCredentials usernamePasswordCredentials = new UsernamePasswordCredentials(
                            proxyConfiguration.getUserName(), proxyConfiguration.getUserName());
                    credsProvider.setCredentials(
                            new AuthScope(proxyConfiguration.name, proxyConfiguration.port),
                            usernamePasswordCredentials);
                    httpClientBuilder.setDefaultCredentialsProvider(credsProvider);
                    httpClientBuilder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy());
                }
            }
        } else {
            httpClientBuilder.setProxy(new HttpHost(customProxy.getProxyServer(), customProxy.getProxyPort()));
            if (StringUtils.isNotBlank(customProxy.getProxyUser())
                    && StringUtils.isNotBlank(customProxy.getProxyPassword())) {
                CredentialsProvider credsProvider = new BasicCredentialsProvider();
                UsernamePasswordCredentials usernamePasswordCredentials = new UsernamePasswordCredentials(
                        customProxy.getProxyUser(), customProxy.getProxyPassword());
                credsProvider.setCredentials(
                        new AuthScope(customProxy.getProxyServer(), customProxy.getProxyPort()),
                        usernamePasswordCredentials);
                httpClientBuilder.setDefaultCredentialsProvider(credsProvider);
                httpClientBuilder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy());
            }
        }
    }
    return httpClientBuilder;
}

From source file:org.n52.supervisor.checks.json.JsonServiceCheck.java

protected HttpClient createClient() throws Exception {
    DefaultHttpClient result = new DefaultHttpClient();
    SchemeRegistry sr = result.getConnectionManager().getSchemeRegistry();

    SSLSocketFactory sslsf = new SSLSocketFactory(new TrustStrategy() {

        @Override/*from   ww  w.java  2  s . co  m*/
        public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
            return true;
        }
    }, new AllowAllHostnameVerifier());

    Scheme httpsScheme2 = new Scheme("https", 443, sslsf);
    sr.register(httpsScheme2);

    return result;
}

From source file:org.mobicents.servlet.restcomm.fax.InterfaxService.java

public InterfaxService(final Configuration configuration) {
    super();// w ww  .j a va  2s.  c  om
    user = configuration.getString("user");
    password = configuration.getString("password");
    strategy = new TrustStrategy() {
        @Override
        public boolean isTrusted(final X509Certificate[] chain, final String authType)
                throws CertificateException {
            return true;
        }
    };
}

From source file:org.apache.olingo.samples.client.core.http.SocketFactoryHttpClientFactory.java

@Override
public DefaultHttpClient create(final HttpMethod method, final URI uri) {
    final TrustStrategy acceptTrustStrategy = new TrustStrategy() {
        @Override//from w w w  .  java 2 s .  c  o  m
        public boolean isTrusted(final X509Certificate[] certificate, final String authType) {
            return true;
        }
    };

    final SchemeRegistry registry = new SchemeRegistry();
    try {
        final SSLSocketFactory ssf = new SSLSocketFactory(acceptTrustStrategy,
                SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        registry.register(new Scheme(uri.getScheme(), uri.getPort(), ssf));
    } catch (Exception e) {
        throw new ODataRuntimeException(e);
    }

    final DefaultHttpClient httpClient = new DefaultHttpClient(new BasicClientConnectionManager(registry));
    httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT);

    return httpClient;
}

From source file:org.syncany.connection.plugins.webdav.WebdavConnection.java

private void initSsl() throws Exception {
    this.secure = true;

    /*/*from   w  w  w  .  j ava 2 s .c  om*/
     * String keyStoreFilename = "/tmp/mystore"; 
     * File keystoreFile = new File(keyStoreFilename); 
     * FileInputStream fis = new
     * FileInputStream(keystoreFile); 
     * KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); // JKS keyStore.load(fis, null);
     */

    TrustStrategy trustStrategy = new TrustStrategy() {
        @Override
        public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
            for (X509Certificate cert : chain) {
                System.out.println(cert);
            }

            // TODO [high] WebDAV SSL: This should query the CLI/GUI (and store the cert. locally); right now, MITMs are easily possible
            return true;
        }
    };

    this.sslSocketFactory = new SSLSocketFactory(trustStrategy);
}

From source file:com.github.tomakehurst.wiremock.http.HttpClientFactory.java

private static SSLContext buildAllowAnythingSSLContext() {
    try {//w  w  w .  j a  va2 s .c  o  m
        return SSLContexts.custom().loadTrustMaterial(null, new TrustStrategy() {
            @Override
            public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                return true;
            }
        }).build();
    } catch (Exception e) {
        return throwUnchecked(e, SSLContext.class);
    }
}

From source file:org.xdi.oxauth.service.net.HttpService.java

public HttpClient getHttpsClientTrustAll() {
    try {//from w w w  . j a  v  a2s.  c o  m
        SSLSocketFactory sf = new SSLSocketFactory(new TrustStrategy() {
            @Override
            public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                return true;
            }
        }, new AllowAllHostnameVerifier());

        PlainSocketFactory psf = PlainSocketFactory.getSocketFactory();

        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", 80, psf));
        registry.register(new Scheme("https", 443, sf));
        ClientConnectionManager ccm = new PoolingClientConnectionManager(registry);
        return new DefaultHttpClient(ccm);
    } catch (Exception ex) {
        log.error("Failed to create TrustAll https client", ex);
        return new DefaultHttpClient();
    }
}

From source file:ac.uk.diamond.sample.HttpClientTest.Utils.java

/**
 * Create a connection manager that trusts any certificate.
 */// w  ww. j ava2s.co  m
static SSLSocketFactory getAnyCertManager() {
    try {
        SSLSocketFactory sf = new SSLSocketFactory(new TrustStrategy() {
            @Override
            public boolean isTrusted(X509Certificate[] aChain, String aAuthType) throws CertificateException {
                return true;
            }
        });
        return sf;
    } catch (GeneralSecurityException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.github.matthesrieke.simplebroker.AbstractConsumer.java

protected HttpClient createClient() throws Exception {
    DefaultHttpClient result = new DefaultHttpClient();
    SchemeRegistry sr = result.getConnectionManager().getSchemeRegistry();

    SSLSocketFactory sslsf = new SSLSocketFactory(new TrustStrategy() {

        @Override/*from w  w  w.jav  a2  s.co m*/
        public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
            return true;
        }
    }, new AllowTrustedHostNamesVerifier());

    Scheme httpsScheme2 = new Scheme("https", 443, sslsf);
    sr.register(httpsScheme2);

    return result;
}

From source file:org.envirocar.harvest.TrackPublisher.java

protected HttpClient createClient() throws IOException {
    SSLSocketFactory sslsf;/*  w  w w .  j ava2  s .com*/
    try {
        sslsf = new SSLSocketFactory(new TrustStrategy() {

            public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                // XXX !!!
                return true;
            }

        }, new LoggingHostnameVerifier());
    } catch (KeyManagementException e) {
        throw new IOException(e);
    } catch (UnrecoverableKeyException e) {
        throw new IOException(e);
    } catch (NoSuchAlgorithmException e) {
        throw new IOException(e);
    } catch (KeyStoreException e) {
        throw new IOException(e);
    }
    Scheme httpsScheme2 = new Scheme("https", 443, sslsf);

    DefaultHttpClient client = new DefaultHttpClient();
    client.getConnectionManager().getSchemeRegistry().register(httpsScheme2);

    return client;
}