Search in sources :

Example 1 with PlainSocketFactory

use of org.apache.http.conn.scheme.PlainSocketFactory in project oxAuth by GluuFederation.

the class HttpService method getHttpsClientTrustAll.

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();
    }
}
Also used : TrustStrategy(org.apache.http.conn.ssl.TrustStrategy) PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) Scheme(org.apache.http.conn.scheme.Scheme) AllowAllHostnameVerifier(org.apache.http.conn.ssl.AllowAllHostnameVerifier) CertificateException(java.security.cert.CertificateException) PlainSocketFactory(org.apache.http.conn.scheme.PlainSocketFactory) PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) X509Certificate(java.security.cert.X509Certificate) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) SslDefaultHttpClient(org.xdi.net.SslDefaultHttpClient) ClientProtocolException(org.apache.http.client.ClientProtocolException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SchemeRegistry(org.apache.http.conn.scheme.SchemeRegistry) SSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory)

Example 2 with PlainSocketFactory

use of org.apache.http.conn.scheme.PlainSocketFactory in project oxAuth by GluuFederation.

the class HttpService method getHttpsClientTrustAll.

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();
    }
}
Also used : TrustStrategy(org.apache.http.conn.ssl.TrustStrategy) PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) Scheme(org.apache.http.conn.scheme.Scheme) AllowAllHostnameVerifier(org.apache.http.conn.ssl.AllowAllHostnameVerifier) CertificateException(java.security.cert.CertificateException) PlainSocketFactory(org.apache.http.conn.scheme.PlainSocketFactory) PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) X509Certificate(java.security.cert.X509Certificate) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) SslDefaultHttpClient(org.gluu.net.SslDefaultHttpClient) ClientProtocolException(org.apache.http.client.ClientProtocolException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SchemeRegistry(org.apache.http.conn.scheme.SchemeRegistry) SSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory)

Example 3 with PlainSocketFactory

use of org.apache.http.conn.scheme.PlainSocketFactory in project oxAuth by GluuFederation.

the class HttpService method getHttpsClientDefaulTrustStore.

@Deprecated
public HttpClient getHttpsClientDefaulTrustStore() {
    try {
        PlainSocketFactory psf = PlainSocketFactory.getSocketFactory();
        SSLContext ctx = SSLContext.getInstance("TLS");
        SSLSocketFactory ssf = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", 80, psf));
        registry.register(new Scheme("https", 443, ssf));
        ClientConnectionManager ccm = new PoolingClientConnectionManager(registry);
        return new DefaultHttpClient(ccm);
    } catch (Exception ex) {
        log.error("Failed to create https client", ex);
        return new DefaultHttpClient();
    }
}
Also used : PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) Scheme(org.apache.http.conn.scheme.Scheme) SchemeRegistry(org.apache.http.conn.scheme.SchemeRegistry) SSLContext(javax.net.ssl.SSLContext) PlainSocketFactory(org.apache.http.conn.scheme.PlainSocketFactory) SSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory) PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) SslDefaultHttpClient(org.xdi.net.SslDefaultHttpClient) ClientProtocolException(org.apache.http.client.ClientProtocolException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

IOException (java.io.IOException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 CertificateException (java.security.cert.CertificateException)3 ClientProtocolException (org.apache.http.client.ClientProtocolException)3 ClientConnectionManager (org.apache.http.conn.ClientConnectionManager)3 PlainSocketFactory (org.apache.http.conn.scheme.PlainSocketFactory)3 Scheme (org.apache.http.conn.scheme.Scheme)3 SchemeRegistry (org.apache.http.conn.scheme.SchemeRegistry)3 SSLSocketFactory (org.apache.http.conn.ssl.SSLSocketFactory)3 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)3 PoolingClientConnectionManager (org.apache.http.impl.conn.PoolingClientConnectionManager)3 X509Certificate (java.security.cert.X509Certificate)2 AllowAllHostnameVerifier (org.apache.http.conn.ssl.AllowAllHostnameVerifier)2 TrustStrategy (org.apache.http.conn.ssl.TrustStrategy)2 SslDefaultHttpClient (org.xdi.net.SslDefaultHttpClient)2 SSLContext (javax.net.ssl.SSLContext)1 SslDefaultHttpClient (org.gluu.net.SslDefaultHttpClient)1