All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hr.com.vgv.verano.http.wire.apache.SslTrusted Maven / Gradle / Ivy

There is a newer version: 0.41
Show newest version
package hr.com.vgv.verano.http.wire.apache;

import java.net.URI;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.ssl.SSLContexts;

public class SslTrusted implements ApacheContext
{
    @Override
    public final HttpClientBuilder apply(URI uri, HttpClientBuilder builder) {
        final SSLContextBuilder ssl = SSLContexts.custom();
        final SSLContext sslContext;
        try
        {
            ssl.loadTrustMaterial((chain, type) -> true);
            sslContext = ssl.build();
        }
        catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e)
        {
            throw new IllegalStateException(e);
        }
        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
            sslContext, new HostnameVerifier() {

            @Override
            public boolean verify(String s, SSLSession sslSession) {
                return true;
            }
        });
        return builder.setSSLSocketFactory(sslsf);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy