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

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

Introduction

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

Prototype

AllowAllHostnameVerifier

Source Link

Usage

From source file:org.trustedanalytics.servicebroker.hdfs.config.hgm.HgmHttpsConfiguration.java

@Bean
@Qualifier("hgmRestTemplate")
public RestTemplate getHgmHttpsRestTemplate()
        throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
    SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).useTLS()
            .build();/* w  w  w .j av  a2  s  .c  o  m*/
    SSLConnectionSocketFactory connectionFactory = new SSLConnectionSocketFactory(sslContext,
            new AllowAllHostnameVerifier());
    BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY,
            new UsernamePasswordCredentials(configuration.getUsername(), configuration.getPassword()));

    HttpClient httpClient = HttpClientBuilder.create().setSSLSocketFactory(connectionFactory)
            .setDefaultCredentialsProvider(credentialsProvider).build();

    ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
    return new RestTemplate(requestFactory);
}

From source file:org.apache.falcon.resource.channel.SecureHTTPChannel.java

@Override
protected Client getClient() throws Exception {
    Properties properties = StartupProperties.get();
    String keyStoreFile = properties.getProperty("keystore.file", "conf/prism.keystore");
    String password = properties.getProperty("keystore.password", "falcon-prism-passwd");
    SSLContext sslContext = SSLContext.getInstance("SSL");
    sslContext.init(/*from   w w w.j ava 2 s . c  o m*/
            new KeyManager[] { KeyManagerUtils.createClientKeyManager(new File(keyStoreFile), password) },
            new TrustManager[] { TrustManagerUtils.getValidateServerCertificateTrustManager() },
            new SecureRandom());
    DefaultClientConfig config = new DefaultClientConfig();
    config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES,
            new HTTPSProperties(new AllowAllHostnameVerifier(), sslContext));
    LOG.info("Configuring client with " + new File(keyStoreFile).getAbsolutePath());
    return Client.create(config);
}

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/*  w w w  .j  a v  a 2  s.  c om*/
        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:com.tremolosecurity.scale.user.ScaleSession.java

@PostConstruct
public void init() {
    try {/*from ww w  . j a  v  a  2 s .  co  m*/
        HttpClientInfo httpci = this.commonConfig.createHttpClientInfo();

        http = HttpClients.custom().setConnectionManager(httpci.getCm())
                .setDefaultRequestConfig(httpci.getGlobalConfig())
                .setHostnameVerifier(new AllowAllHostnameVerifier()).build();

        URL uurl = new URL(commonConfig.getScaleConfig().getServiceConfiguration().getUnisonURL());
        int port = uurl.getPort();

        HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext()
                .getRequest();
        this.login = request.getRemoteUser();
    } catch (Exception e) {
        logger.error("Could not initialize ScaleSession", e);
    }

}

From source file:com.wiyun.engine.network.TrustAllSSLSocketFactory.java

public TrustAllSSLSocketFactory()
        throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException {
    super(null);//from w ww . ja va 2  s. c  o  m
    try {
        SSLContext sslcontext = SSLContext.getInstance("TLS");
        sslcontext.init(null, new TrustManager[] { new TrustAllManager() }, null);
        factory = sslcontext.getSocketFactory();
        setHostnameVerifier(new AllowAllHostnameVerifier());
    } catch (Exception ex) {
    }
}

From source file:android.net.http.AbstractProxyTest.java

public void testConnectToHttps() throws Exception {
    TestSSLContext testSSLContext = TestSSLContext.create();

    server.useHttps(testSSLContext.serverContext.getSocketFactory(), false);
    server.enqueue(new MockResponse().setResponseCode(200).setBody("this response comes via HTTPS"));
    server.play();/*from   w ww  . j  a  v a2s  . c om*/

    HttpClient httpClient = newHttpClient();

    SSLSocketFactory sslSocketFactory = newSslSocketFactory(testSSLContext);
    sslSocketFactory.setHostnameVerifier(new AllowAllHostnameVerifier());
    httpClient.getConnectionManager().getSchemeRegistry()
            .register(new Scheme("https", sslSocketFactory, server.getPort()));

    HttpResponse response = httpClient.execute(new HttpGet("https://localhost:" + server.getPort() + "/foo"));
    assertEquals("this response comes via HTTPS", contentToString(response));

    RecordedRequest request = server.takeRequest();
    assertEquals("GET /foo HTTP/1.1", request.getRequestLine());
}

From source file:org.ksoap2.transport.ServiceConnectionSE.java

public ServiceConnectionSE(String url) throws IOException {
    // /*from  w ww . java 2s  .  c  om*/
    try {
        SSLContext sContext = SSLContext.getInstance("SSL");
        sContext.init(null, trustAllCerts, new java.security.SecureRandom());

        HttpsURLConnection.setDefaultSSLSocketFactory(sContext.getSocketFactory());
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (KeyManagementException e) {
        e.printStackTrace();
    }

    connection = (HttpsURLConnection) new URL(url).openConnection();
    ((HttpsURLConnection) connection).setHostnameVerifier(new AllowAllHostnameVerifier());
    connection.setUseCaches(false);
    connection.setDoOutput(true);
    connection.setDoInput(true);
}

From source file:org.qi4j.library.http.AbstractSecureJettyTest.java

@Before
public void beforeSecure() throws GeneralSecurityException, IOException {
    // Trust HTTP Client
    KeyStore truststore = KeyStore.getInstance("JCEKS");
    truststore.load(new FileInputStream(TRUSTSTORE_FILE), KS_PASSWORD.toCharArray());

    AllowAllHostnameVerifier verifier = new AllowAllHostnameVerifier();

    DefaultHttpClient trustClient = new DefaultHttpClient();
    SSLSocketFactory trustSslFactory = new SSLSocketFactory(truststore);
    trustSslFactory.setHostnameVerifier(verifier);
    SchemeRegistry trustSchemeRegistry = trustClient.getConnectionManager().getSchemeRegistry();
    trustSchemeRegistry.unregister(HTTPS);
    trustSchemeRegistry.register(new Scheme(HTTPS, HTTPS_PORT, trustSslFactory));
    trustHttpClient = trustClient;//from  ww  w . java 2s .  co m

    // Mutual HTTP Client
    KeyStore keystore = KeyStore.getInstance("JCEKS");
    keystore.load(new FileInputStream(CLIENT_KEYSTORE_FILE), KS_PASSWORD.toCharArray());

    DefaultHttpClient mutualClient = new DefaultHttpClient();
    SSLSocketFactory mutualSslFactory = new SSLSocketFactory(keystore, KS_PASSWORD, truststore);
    mutualSslFactory.setHostnameVerifier(verifier);
    SchemeRegistry mutualSchemeRegistry = mutualClient.getConnectionManager().getSchemeRegistry();
    mutualSchemeRegistry.unregister(HTTPS);
    mutualSchemeRegistry.register(new Scheme(HTTPS, HTTPS_PORT, mutualSslFactory));
    mutualHttpClient = mutualClient;
}

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

public HttpClient getHttpsClientTrustAll() {
    try {/*from  www . j a  v  a  2s .c  om*/
        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:org.hyperic.hq.plugin.appha.VSphereUtil.java

private static void configureSSLKeystore() {
    AgentKeystoreConfig keystoreConfig = new AgentKeystoreConfig();
    SSLProvider sslProvider = new DefaultSSLProviderImpl(keystoreConfig,
            keystoreConfig.isAcceptUnverifiedCert());
    SSLContext sslContext = sslProvider.getSSLContext();
    HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
    HttpsURLConnection.setDefaultHostnameVerifier(new AllowAllHostnameVerifier());
}