@Test public void shouldWrapX509TrustManagers() { TrustManager[] managers = new TrustManager[] { Mockito.mock(TrustManager.class), Mockito.mock(X509TrustManager.class) }; TrustManager[] wrapped = X509TrustManagerWrapper.wrap(managers); Assert.assertSame(managers[0], wrapped[0]); Assert.assertNotSame(managers[1], wrapped[1]); Assert.assertFalse(wrapped[0] instanceof X509TrustManagerWrapper); Assert.assertTrue(wrapped[1] instanceof X509TrustManagerWrapper); }
public static TrustManager[] wrap(TrustManager[] trustManagers) { TrustManager[] wrappers = new TrustManager[trustManagers.length]; for (int i = 0; i < trustManagers.length; i++) { TrustManager trustManager = trustManagers[i]; if (trustManager instanceof X509TrustManager) { wrappers[i] = new X509TrustManagerWrapper((X509TrustManager) trustManager); } else { wrappers[i] = trustManager; } } return wrappers; }
X509TrustManagerWrapper implements X509TrustManager { public static TrustManager[] wrap(TrustManager[] trustManagers) { TrustManager[] wrappers = new TrustManager[trustManagers.length]; for (int i = 0; i < trustManagers.length; i++) { TrustManager trustManager = trustManagers[i]; if (trustManager instanceof X509TrustManager) { wrappers[i] = new X509TrustManagerWrapper((X509TrustManager) trustManager); } else { wrappers[i] = trustManager; } } return wrappers; } }
X509TrustManagerWrapper implements X509TrustManager { public static TrustManager[] wrap(TrustManager[] trustManagers) { TrustManager[] wrappers = new TrustManager[trustManagers.length]; for (int i = 0; i < trustManagers.length; i++) { TrustManager trustManager = trustManagers[i]; if (trustManager instanceof X509TrustManager) { wrappers[i] = new X509TrustManagerWrapper((X509TrustManager) trustManager); } else { wrappers[i] = trustManager; } } return wrappers; } X509TrustManagerWrapper(final X509TrustManager trustManager); }
X509TrustManagerWrapper implements X509TrustManager { public static TrustManager[] wrap(TrustManager[] trustManagers) { TrustManager[] wrappers = new TrustManager[trustManagers.length]; for (int i = 0; i < trustManagers.length; i++) { TrustManager trustManager = trustManagers[i]; if (trustManager instanceof X509TrustManager) { wrappers[i] = new X509TrustManagerWrapper((X509TrustManager) trustManager); } else { wrappers[i] = trustManager; } } return wrappers; } X509TrustManagerWrapper(final X509TrustManager trustManager); static TrustManager[] wrap(TrustManager[] trustManagers); @Override void checkClientTrusted(X509Certificate[] chain, String authType); @Override void checkServerTrusted(X509Certificate[] chain, String authType); @Override X509Certificate[] getAcceptedIssuers(); }
X509TrustManagerWrapper implements X509TrustManager { public static TrustManager[] wrap(TrustManager[] trustManagers) { TrustManager[] wrappers = new TrustManager[trustManagers.length]; for (int i = 0; i < trustManagers.length; i++) { TrustManager trustManager = trustManagers[i]; if (trustManager instanceof X509TrustManager) { wrappers[i] = new X509TrustManagerWrapper((X509TrustManager) trustManager); } else { wrappers[i] = trustManager; } } return wrappers; } X509TrustManagerWrapper(final X509TrustManager trustManager); static TrustManager[] wrap(TrustManager[] trustManagers); @Override void checkClientTrusted(X509Certificate[] chain, String authType); @Override void checkServerTrusted(X509Certificate[] chain, String authType); @Override X509Certificate[] getAcceptedIssuers();  }