class SpiffeTrustManagerFactory extends TrustManagerFactorySpi {

    @Override
    public TrustManager[] engineGetTrustManagers() {

        final X509Source x509Source;
        try {
            x509Source = X509SourceManager.getX509Source();
        } catch (X509SourceException e) {
            throw new SpiffeProviderException("The X.509 source could not be created", e);
        } catch (SocketEndpointAddressException e) {
            throw new SpiffeProviderException("The Workload API Socket endpoint address configured is not valid", e);
        }

        final SpiffeTrustManager spiffeTrustManager;
        if (ACCEPT_ANY_SPIFFE_ID) {
            spiffeTrustManager = new SpiffeTrustManager(x509Source);
        } else {
            spiffeTrustManager = new SpiffeTrustManager(x509Source, DEFAULT_SPIFFE_ID_SET_SUPPLIER);
        }
        return new TrustManager[]{spiffeTrustManager};
    }

}