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

pl.allegro.tech.hermes.common.ssl.DefaultSslContextFactory Maven / Gradle / Ivy

There is a newer version: 2.7.0
Show newest version
package pl.allegro.tech.hermes.common.ssl;

import javax.net.ssl.SSLContext;

public class DefaultSslContextFactory implements SslContextFactory {

    private final String protocol;
    private final KeyManagersProvider keyManagersProvider;
    private final TrustManagersProvider trustManagersProvider;

    public DefaultSslContextFactory(String protocol, KeyManagersProvider keyManagersProvider, TrustManagersProvider trustManagersProvider) {
        this.protocol = protocol;
        this.keyManagersProvider = keyManagersProvider;
        this.trustManagersProvider = trustManagersProvider;
    }

    @Override
    public SSLContextHolder create() {
        try {
            SSLContext sslContext = SSLContext.getInstance(protocol);
            sslContext.init(keyManagersProvider.getKeyManagers(), trustManagersProvider.getTrustManagers(), null);
            return new SSLContextHolder(sslContext, trustManagersProvider.getTrustManagers());
        } catch (Exception e) {
            throw new SslContextCreationException(e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy