org.apache.http.conn.ssl.AllowAllHostnameVerifier Java Examples

The following examples show how to use org.apache.http.conn.ssl.AllowAllHostnameVerifier. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: oxAuth   Author: GluuFederation   File: HttpService.java    License: MIT License 7 votes vote down vote up
public HttpClient getHttpsClientTrustAll() {
    try {
        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();
    }
}
 
Example #2
Source Project: documentum-rest-client-java   Author: Enterprise-Content-Management   File: AbstractRestTemplateClient.java    License: Apache License 2.0 6 votes vote down vote up
public AbstractRestTemplateClient ignoreAuthenticateServer() {
    //backward compatible with android httpclient 4.3.x
    if(restTemplate.getRequestFactory() instanceof HttpComponentsClientHttpRequestFactory) {
        try {
            SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build();
            X509HostnameVerifier verifier = ignoreSslWarning ? new AllowAllHostnameVerifier() : new BrowserCompatHostnameVerifier();
            SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(sslContext, verifier);
            HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();
            ((HttpComponentsClientHttpRequestFactory)restTemplate.getRequestFactory()).setHttpClient(httpClient);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        Debug.error("the request factory " + restTemplate.getRequestFactory().getClass().getName() + " does not support ignoreAuthenticateServer");
    }
    return this;
}
 
Example #3
Source Project: chaos-lemur   Author: strepsirrhini-army   File: StandardDirectorUtils.java    License: Apache License 2.0 6 votes vote down vote up
private static RestTemplate createRestTemplate(String host, String username, String password, Set<ClientHttpRequestInterceptor> interceptors) throws GeneralSecurityException {
    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(new AuthScope(host, 25555),
        new UsernamePasswordCredentials(username, password));

    SSLContext sslContext = SSLContexts.custom()
        .loadTrustMaterial(null, new TrustSelfSignedStrategy())
        .useTLS()
        .build();

    SSLConnectionSocketFactory connectionFactory = new SSLConnectionSocketFactory(sslContext, new AllowAllHostnameVerifier());

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

    RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient));
    restTemplate.getInterceptors().addAll(interceptors);

    return restTemplate;
}
 
Example #4
Source Project: document-management-software   Author: logicaldoc   File: HttpUtil.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public static CloseableHttpClient getNotValidatingClient(int timeout, String proxyServer, Integer proxyPort,
		String proxyUser, String proxyPassword) {
	try {
		HttpClientBuilder clientBuilder = HttpClients.custom();

		RequestConfig.Builder requestBuilder = RequestConfig.custom().setConnectTimeout(timeout * 1000)
				.setSocketTimeout(timeout * 1000).setConnectionRequestTimeout(timeout * 1000)
				.setRedirectsEnabled(true);

		if (StringUtils.isNotEmpty(proxyServer)) {
			HttpHost proxyHost = new HttpHost(proxyServer, proxyPort);
			requestBuilder.setProxy(proxyHost);

			DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxyHost);
			clientBuilder.setRoutePlanner(routePlanner);

			if (StringUtils.isNotEmpty(proxyUser)) {
				CredentialsProvider credentialProvider = new BasicCredentialsProvider();
				credentialProvider.setCredentials(AuthScope.ANY,
						new UsernamePasswordCredentials(proxyUser, proxyPassword));
				clientBuilder.setRoutePlanner(routePlanner);
			}
		}

		RequestConfig requestConfig = requestBuilder.build();

		CloseableHttpClient httpclient = clientBuilder.setHostnameVerifier(new AllowAllHostnameVerifier())
				.setSslcontext(new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
					public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
						return true;
					}
				}).build()).setDefaultRequestConfig(requestConfig).build();
		return httpclient;
	} catch (Throwable t) {
		return null;
	}
}
 
Example #5
Source Project: ais-sdk   Author: huaweicloudsdk   File: AccessServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
private CloseableHttpClient getDefaultHttpClient() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {
	SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).useTLS().build();
	SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext,
			new AllowAllHostnameVerifier());

	return HttpClients.custom().setSSLSocketFactory(sslSocketFactory).build();
}
 
Example #6
Source Project: ais-sdk   Author: huaweicloudsdk   File: AccessServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
private CloseableHttpClient getDefaultHttpClient() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {
	SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).useTLS().build();
	SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext,
			new AllowAllHostnameVerifier());

	return HttpClients.custom().setSSLSocketFactory(sslSocketFactory).build();
}
 
Example #7
Source Project: 07kit   Author: 07kit   File: HttpUtil.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static HttpClient getClient() {
    try {
        SSLContext context = new SSLContextBuilder()
                .loadTrustMaterial(null, (arg0, arg1) -> true)
                .build();

        return HttpClients.custom()
                .setHostnameVerifier(new AllowAllHostnameVerifier())
                .setSslcontext(context)
                .build();
    } catch (Exception e) {
        e.printStackTrace();
        return HttpClients.createDefault();
    }
}
 
Example #8
Source Project: onos   Author: opennetworkinglab   File: HttpSBControllerImpl.java    License: Apache License 2.0 5 votes vote down vote up
private CloseableHttpClient getApacheSslBypassClient() throws NoSuchAlgorithmException,
        KeyManagementException, KeyStoreException {
    return HttpClients.custom().
            setHostnameVerifier(new AllowAllHostnameVerifier()).
            setSslcontext(new SSLContextBuilder()
                                  .loadTrustMaterial(null, (arg0, arg1) -> true)
                                  .build()).build();
}