summaryrefslogtreecommitdiffstats
path: root/security-utils/src/main/java/com/yahoo/security/tls/authz/PeerAuthorizerTrustManagersFactory.java
blob: c0a3b4e41a536ccac7fb62cf6a49a10264987418 (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
26
27
28
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.security.tls.authz;

import com.yahoo.security.SslContextBuilder;
import com.yahoo.security.tls.AuthorizationMode;
import com.yahoo.security.tls.policy.AuthorizedPeers;

import javax.net.ssl.TrustManager;
import java.security.GeneralSecurityException;
import java.security.KeyStore;

/**
 * @author bjorncs
 */
public class PeerAuthorizerTrustManagersFactory implements SslContextBuilder.TrustManagersFactory {
    private final AuthorizedPeers authorizedPeers;
    private AuthorizationMode mode;

    public PeerAuthorizerTrustManagersFactory(AuthorizedPeers authorizedPeers, AuthorizationMode mode) {
        this.authorizedPeers = authorizedPeers;
        this.mode = mode;
    }

    @Override
    public TrustManager[] createTrustManagers(KeyStore truststore) throws GeneralSecurityException {
        return PeerAuthorizerTrustManager.wrapTrustManagersFromKeystore(authorizedPeers, mode, truststore);
    }
}