@Test void testEngineGetTrustManagers_withCustomSource() throws NoSuchFieldException, IllegalAccessException, BundleNotFoundException { System.setProperty(SSL_SPIFFE_ACCEPT_PROPERTY, "spiffe: X509Source source = new X509SourceStub(); TrustManager[] trustManagers = new SpiffeTrustManagerFactory().engineGetTrustManagers(source); SpiffeTrustManager trustManager = (SpiffeTrustManager) trustManagers[0]; BundleSource<X509Bundle> bundleSource = getX509BundleBundleSource(trustManager); Supplier<Set<SpiffeId>> supplier = getSetSupplier(trustManager); boolean acceptAny = isAcceptAny(trustManager); TrustDomain trustDomain = TrustDomain.of("example.org"); assertEquals(source.getBundleForTrustDomain(trustDomain), bundleSource.getBundleForTrustDomain(trustDomain)); assertEquals(2, supplier.get().size()); assertTrue(supplier.get().contains(SpiffeId.parse("spiffe: assertFalse(acceptAny); }
@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}; }
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}; } }
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}; }  }
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}; }  @Override TrustManager[] engineGetTrustManagers(); TrustManager[] engineGetTrustManagers(@NonNull final BundleSource<X509Bundle> x509BundleSource); TrustManager[] engineGetTrustManagersAcceptAnySpiffeId(@NonNull final BundleSource<X509Bundle> x509BundleSource); TrustManager[] engineGetTrustManagers(
            @NonNull final BundleSource<X509Bundle> x509BundleSource,
            @NonNull final Supplier<Set<SpiffeId>> acceptedSpiffeIdsSupplier); }
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}; }  @Override TrustManager[] engineGetTrustManagers(); TrustManager[] engineGetTrustManagers(@NonNull final BundleSource<X509Bundle> x509BundleSource); TrustManager[] engineGetTrustManagersAcceptAnySpiffeId(@NonNull final BundleSource<X509Bundle> x509BundleSource); TrustManager[] engineGetTrustManagers(
            @NonNull final BundleSource<X509Bundle> x509BundleSource,
            @NonNull final Supplier<Set<SpiffeId>> acceptedSpiffeIdsSupplier);  }