@Test public void testCreateAuthTrustManagers() throws Exception { TrustManager[] trustManagers = new TrustManager[3]; X509TrustManager tm = Mockito.mock(X509TrustManager.class); trustManagers[1] = tm; PowerMockito.mockStatic(TrustManagerFactory.class); PowerMockito.doReturn(trustManagerFactoryMock).when(TrustManagerFactory.class, "getInstance", anyObject()); Mockito.doReturn(trustManagers).when(trustManagerFactoryMock).getTrustManagers(); TrustManager[] result = SSLUtils.createAuthTrustManagers(keystoreMock); Assert.assertEquals(trustManagers, result); verify(trustManagerFactoryMock).init(keystoreMock); Assert.assertTrue(result[1] instanceof AuthSSLX509TrustManager); }
public static TrustManager[] createAuthTrustManagers(final KeyStore keystore) throws KeyStoreException, NoSuchAlgorithmException { if (keystore == null) { throw new IllegalArgumentException("Keystore may not be null"); } TrustManagerFactory tmfactory = TrustManagerFactory.getInstance( TrustManagerFactory.getDefaultAlgorithm()); tmfactory.init(keystore); TrustManager[] trustmanagers = tmfactory.getTrustManagers(); for (int i = 0; i < trustmanagers.length; i++) { if (trustmanagers[i] instanceof X509TrustManager) { trustmanagers[i] = new AuthSSLX509TrustManager( (X509TrustManager) trustmanagers[i]); } } return trustmanagers; }
SSLUtils { public static TrustManager[] createAuthTrustManagers(final KeyStore keystore) throws KeyStoreException, NoSuchAlgorithmException { if (keystore == null) { throw new IllegalArgumentException("Keystore may not be null"); } TrustManagerFactory tmfactory = TrustManagerFactory.getInstance( TrustManagerFactory.getDefaultAlgorithm()); tmfactory.init(keystore); TrustManager[] trustmanagers = tmfactory.getTrustManagers(); for (int i = 0; i < trustmanagers.length; i++) { if (trustmanagers[i] instanceof X509TrustManager) { trustmanagers[i] = new AuthSSLX509TrustManager( (X509TrustManager) trustmanagers[i]); } } return trustmanagers; } }
SSLUtils { public static TrustManager[] createAuthTrustManagers(final KeyStore keystore) throws KeyStoreException, NoSuchAlgorithmException { if (keystore == null) { throw new IllegalArgumentException("Keystore may not be null"); } TrustManagerFactory tmfactory = TrustManagerFactory.getInstance( TrustManagerFactory.getDefaultAlgorithm()); tmfactory.init(keystore); TrustManager[] trustmanagers = tmfactory.getTrustManagers(); for (int i = 0; i < trustmanagers.length; i++) { if (trustmanagers[i] instanceof X509TrustManager) { trustmanagers[i] = new AuthSSLX509TrustManager( (X509TrustManager) trustmanagers[i]); } } return trustmanagers; }  }
SSLUtils { public static TrustManager[] createAuthTrustManagers(final KeyStore keystore) throws KeyStoreException, NoSuchAlgorithmException { if (keystore == null) { throw new IllegalArgumentException("Keystore may not be null"); } TrustManagerFactory tmfactory = TrustManagerFactory.getInstance( TrustManagerFactory.getDefaultAlgorithm()); tmfactory.init(keystore); TrustManager[] trustmanagers = tmfactory.getTrustManagers(); for (int i = 0; i < trustmanagers.length; i++) { if (trustmanagers[i] instanceof X509TrustManager) { trustmanagers[i] = new AuthSSLX509TrustManager( (X509TrustManager) trustmanagers[i]); } } return trustmanagers; }  static KeyStore createKeyStore(final URL url, final String password); static KeyManager[] createKeyManagers(final KeyStore keystore, final String password); static TrustManager[] createAuthTrustManagers(final KeyStore keystore); static Store createMessageStore(GetMailInput input); static void addSSLSettings(boolean trustAllRoots, String keystore,
                                      String keystorePassword, String trustKeystore, String trustPassword); static Store configureStoreWithSSL(Properties props, Authenticator auth, MailInput input); static Store tryTLSOtherwiseTrySSL(Authenticator auth, Properties props, GetMailInput input); static Store configureStoreWithTLS(Properties props, Authenticator auth, MailInput input); static void configureWithTLS(Properties props, final MailInput input); static void clearTLSProperties(Properties props, MailInput input); }
SSLUtils { public static TrustManager[] createAuthTrustManagers(final KeyStore keystore) throws KeyStoreException, NoSuchAlgorithmException { if (keystore == null) { throw new IllegalArgumentException("Keystore may not be null"); } TrustManagerFactory tmfactory = TrustManagerFactory.getInstance( TrustManagerFactory.getDefaultAlgorithm()); tmfactory.init(keystore); TrustManager[] trustmanagers = tmfactory.getTrustManagers(); for (int i = 0; i < trustmanagers.length; i++) { if (trustmanagers[i] instanceof X509TrustManager) { trustmanagers[i] = new AuthSSLX509TrustManager( (X509TrustManager) trustmanagers[i]); } } return trustmanagers; }  static KeyStore createKeyStore(final URL url, final String password); static KeyManager[] createKeyManagers(final KeyStore keystore, final String password); static TrustManager[] createAuthTrustManagers(final KeyStore keystore); static Store createMessageStore(GetMailInput input); static void addSSLSettings(boolean trustAllRoots, String keystore,
                                      String keystorePassword, String trustKeystore, String trustPassword); static Store configureStoreWithSSL(Properties props, Authenticator auth, MailInput input); static Store tryTLSOtherwiseTrySSL(Authenticator auth, Properties props, GetMailInput input); static Store configureStoreWithTLS(Properties props, Authenticator auth, MailInput input); static void configureWithTLS(Properties props, final MailInput input); static void clearTLSProperties(Properties props, MailInput input);  }