aboutsummaryrefslogtreecommitdiffstats
path: root/zookeeper-client-common/src/main/java/com/yahoo/vespa/zookeeper/client/VespaSslContextProvider.java
blob: 9cc71eab96eb39d98315938b5e9722952c8577f8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.zookeeper.client;

import com.yahoo.security.tls.TransportSecurityUtils;

import javax.net.ssl.SSLContext;
import java.util.function.Supplier;

/**
 * Provider for Vespa {@link SSLContext} instance to Zookeeper + misc utility methods for providing Vespa TLS specific ZK configuration.
 *
 * @author bjorncs
 */
public class VespaSslContextProvider implements Supplier<SSLContext> {

    private static final SSLContext sslContext = TransportSecurityUtils.getSystemTlsContext()
            .map(tc -> tc.sslContext().context()).orElse(null);

    @Override
    public SSLContext get() {
        if (sslContext == null) throw new IllegalStateException("Vespa TLS is not enabled");
        return sslContext;
    }

}