Example usage for org.apache.http.conn.ssl NoopHostnameVerifier INSTANCE

List of usage examples for org.apache.http.conn.ssl NoopHostnameVerifier INSTANCE

Introduction

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

Prototype

NoopHostnameVerifier INSTANCE

To view the source code for org.apache.http.conn.ssl NoopHostnameVerifier INSTANCE.

Click Source Link

Usage

From source file:net.ymate.framework.commons.HttpClientHelper.java

private CloseableHttpClient __doBuildHttpClient() throws KeyManagementException, NoSuchAlgorithmException {
    HttpClientBuilder _builder = HttpClientBuilder.create()
            .setDefaultRequestConfig(RequestConfig.custom().setConnectTimeout(__connectionTimeout)
                    .setSocketTimeout(__socketTimeout).setConnectionRequestTimeout(__requestTimeout).build());
    if (__socketFactory == null) {
        __socketFactory = new SSLConnectionSocketFactory(SSLContexts.createSystemDefault(),
                NoopHostnameVerifier.INSTANCE);
    }//  ww w  . ja v  a2  s  . com
    return _builder.setSSLSocketFactory(__socketFactory).build();
}

From source file:com.ericsson.gerrit.plugins.syncindex.HttpClientProvider.java

private SSLConnectionSocketFactory buildSslSocketFactory() {
    return new SSLConnectionSocketFactory(buildSslContext(), NoopHostnameVerifier.INSTANCE);
}

From source file:com.linecorp.armeria.server.SniServerTest.java

public CloseableHttpClient newHttpClient() throws Exception {
    final SSLContext sslCtx = new SSLContextBuilder().loadTrustMaterial(null, (chain, authType) -> true)
            .build();/*from  w  w w  .  j av a 2 s .c o m*/

    return HttpClients.custom().setDnsResolver(dnsResolver)
            .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).setSSLContext(sslCtx).build();
}

From source file:org.elasticsearch.xpack.core.ssl.SSLService.java

/**
 * Create a new {@link SSLIOSessionStrategy} based on the provided settings. The settings are used to identify the SSL configuration
 * that should be used to create the context.
 *
 * @param settings the settings used to identify the ssl configuration, typically under a *.ssl. prefix. An empty settings will return
 *                 a context created from the default configuration
 * @return Never {@code null}./*from   w ww.j a  v  a 2  s  . c o  m*/
 */
public SSLIOSessionStrategy sslIOSessionStrategy(Settings settings) {
    SSLConfiguration config = sslConfiguration(settings);
    SSLContext sslContext = sslContext(config);
    String[] ciphers = supportedCiphers(sslParameters(sslContext).getCipherSuites(), config.cipherSuites(),
            false);
    String[] supportedProtocols = config.supportedProtocols().toArray(Strings.EMPTY_ARRAY);
    HostnameVerifier verifier;

    if (config.verificationMode().isHostnameVerificationEnabled()) {
        verifier = SSLIOSessionStrategy.getDefaultHostnameVerifier();
    } else {
        verifier = NoopHostnameVerifier.INSTANCE;
    }

    return sslIOSessionStrategy(sslContext, supportedProtocols, ciphers, verifier);
}

From source file:com.bosch.cr.examples.inventorybrowser.server.CustomProxyServlet.java

private synchronized CloseableHttpClient getHttpClient() {
    if (httpClient == null) {
        try {//from  www . j a  v a2  s .c  om
            HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();

            // #### ONLY FOR TEST: Trust ANY certificate (self certified, any chain, ...)
            SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, (chain, authType) -> true)
                    .build();
            httpClientBuilder.setSSLContext(sslContext);

            // #### ONLY FOR TEST: Do NOT verify hostname
            SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext,
                    NoopHostnameVerifier.INSTANCE);

            Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder
                    .<ConnectionSocketFactory>create()
                    .register("http", PlainConnectionSocketFactory.getSocketFactory())
                    .register("https", sslConnectionSocketFactory).build();
            PoolingHttpClientConnectionManager httpClientConnectionManager = new PoolingHttpClientConnectionManager(
                    socketFactoryRegistry);
            httpClientBuilder.setConnectionManager(httpClientConnectionManager);

            if (getConfig().getProperty("http.proxyHost") != null) {
                httpClientBuilder.setProxy(new HttpHost(getConfig().getProperty("http.proxyHost"),
                        Integer.parseInt(getConfig().getProperty("http.proxyPort"))));
            }

            httpClient = httpClientBuilder.build();
        } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException ex) {
            throw new RuntimeException(ex);
        }
    }

    return httpClient;
}

From source file:com.bosch.cr.examples.inventorybrowser.server.ProxyServlet.java

private synchronized CloseableHttpClient getHttpClient() {
    if (httpClient == null) {
        try {/* w  w  w.  ja  va 2 s .c om*/
            HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();

            // #### ONLY FOR TEST: Trust ANY certificate (self certified, any chain, ...)
            SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, (chain, authType) -> true)
                    .build();
            httpClientBuilder.setSSLContext(sslContext);

            // #### ONLY FOR TEST: Do NOT verify hostname
            SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext,
                    NoopHostnameVerifier.INSTANCE);

            Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder
                    .<ConnectionSocketFactory>create()
                    .register("http", PlainConnectionSocketFactory.getSocketFactory())
                    .register("https", sslConnectionSocketFactory).build();
            PoolingHttpClientConnectionManager httpClientConnectionManager = new PoolingHttpClientConnectionManager(
                    socketFactoryRegistry);
            httpClientBuilder.setConnectionManager(httpClientConnectionManager);

            if (props.getProperty("http.proxyHost") != null) {
                httpClientBuilder.setProxy(new HttpHost(props.getProperty("http.proxyHost"),
                        Integer.parseInt(props.getProperty("http.proxyPort"))));
            }

            httpClient = httpClientBuilder.build();
        } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException ex) {
            throw new RuntimeException(ex);
        }
    }

    return httpClient;
}

From source file:com.bosch.cr.examples.jwt.CustomProxyServlet.java

private synchronized CloseableHttpClient getHttpClient() {
    if (httpClient == null) {
        try {/*ww  w .j  a  v  a  2s  . c  o m*/
            final HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();

            // #### ONLY FOR TEST: Trust ANY certificate (self certified, any chain, ...)
            final SSLContext sslContext = new SSLContextBuilder()
                    .loadTrustMaterial(null, (chain, authType) -> true).build();
            httpClientBuilder.setSSLContext(sslContext);

            // #### ONLY FOR TEST: Do NOT verify hostname
            final SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(
                    sslContext, NoopHostnameVerifier.INSTANCE);

            final Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder
                    .<ConnectionSocketFactory>create()
                    .register("http", PlainConnectionSocketFactory.getSocketFactory())
                    .register("https", sslConnectionSocketFactory).build();
            final PoolingHttpClientConnectionManager httpClientConnectionManager = new PoolingHttpClientConnectionManager(
                    socketFactoryRegistry);
            httpClientBuilder.setConnectionManager(httpClientConnectionManager);

            final boolean proxyEnabled = configurationProperties
                    .getPropertyAsBoolean(ConfigurationProperty.PROXY_ENABLED);
            if (proxyEnabled) {
                final String proxyHost = configurationProperties
                        .getPropertyAsString(ConfigurationProperty.PROXY_HOST);
                final int proxyPort = configurationProperties
                        .getPropertyAsInt(ConfigurationProperty.PROXY_PORT);
                final HttpHost proxy = new HttpHost(proxyHost, proxyPort);
                httpClientBuilder.setProxy(proxy);
            }

            httpClient = httpClientBuilder.build();
        } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException ex) {
            throw new RuntimeException(ex);
        }
    }

    return httpClient;
}

From source file:com.clustercontrol.infra.util.WinRs.java

private WsmanConnection createConnection() {
    // ????//from ww  w .ja v  a2  s  .  com
    WsmanConnection conn = WsmanConnection.createConnection(url);
    conn.setAuthenticationScheme("basic");
    conn.setUsername(username);
    conn.setUserpassword(password);
    conn.setTimeout(90000);

    boolean sslTrustall = HinemosPropertyUtil.getHinemosPropertyBool("infra.winrm.ssl.trustall", true);
    if (sslTrustall) {
        X509TrustManager tm = new X509TrustManager() {
            @Override
            public X509Certificate[] getAcceptedIssuers() {
                return null;
            }

            @Override
            public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
            }

            @Override
            public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
            }
        };

        conn.setTrustManager(tm);
        conn.setHostnameVerifier(NoopHostnameVerifier.INSTANCE);
    } else {
        conn.setHostnameVerifier(SSLConnectionSocketFactory.getDefaultHostnameVerifier());
    }

    return conn;
}

From source file:com.keydap.sparrow.SparrowClient.java

/**
 * Creates an instance of the client// w  w  w.  j  a v a2  s  . co  m
 * 
 * @param baseApiUrl the API URL of the SCIM server
 * @param authenticator authenticator instance, optional
 * @param sslCtx the SSL context, mandatory only when the service is accessible over HTTPS
 */
public SparrowClient(String baseApiUrl, String baseOauthUrl, Authenticator authenticator, SSLContext sslCtx) {
    this.baseApiUrl = baseApiUrl;
    this.baseOauthUrl = baseOauthUrl;

    // if authenticator is not given then use a null authenticator
    if (authenticator == null) {
        authenticator = new Authenticator() {
            public void saveHeaders(HttpResponse resp) {
            }

            public void authenticate(String baseUrl, CloseableHttpClient client) throws Exception {
            }

            public void addHeaders(HttpUriRequest req) {
            }
        };
    }

    this.authenticator = authenticator;

    boolean isHttps = baseApiUrl.toLowerCase().startsWith("https");

    builder = HttpClientBuilder.create().useSystemProperties();

    if (isHttps) {
        if (sslCtx == null) {
            LOG.warn(
                    "********************** No SSLContext instance is provided, creating a cstom SSLContext that trusts all certificates **********************");
            try {
                sslCtx = SSLContext.getInstance("TLS");
                sslCtx.init(null, new X509TrustManager[] { new AllowAllTrustManager() }, null);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }

            builder.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE);
        }

        builder.setSSLContext(sslCtx);
    }

    client = builder.build();

    GsonBuilder gb = new GsonBuilder();

    Type dt = new TypeToken<Date>() {
    }.getType();
    gb.registerTypeAdapter(dt, new DateTimeSerializer());

    serializer = gb.create();
}