当TrustManagerFactory不是TrustManagerFactory(Java)时

时间:2013-02-01 20:41:46

标签: java security ssl junit pkix

我正在尝试向现有的App-Server(TomCat)产品添加一些额外的JUnit测试。我遇到了(现有的和已部署的)自定义TrustManager的问题。这个东西在生产中工作正常,但在JUnit期间,给出异常。

自定义TrustManager仅从路径加载密钥库,并隐式信任我们自己的公共证书。出于某种原因,在JUnits中使用它会导致以下行出现异常:

TrustManagerFactory tmFactory = TrustManagerFactory.getInstance("PKIX");    

例外:

java.security.NoSuchAlgorithmException:  class configured for TrustManagerFactory: com.sun.net.ssl.internal.ssl.TrustManagerFactoryImpl$PKIXFactory not a TrustManagerFactory

无论使用哪种提供者/算法组合(“SunX509”,。getDefaultAlgorithm()等),都会发生此异常。

非常感谢任何见解。

1 个答案:

答案 0 :(得分:38)

好吧,看起来PowerMock会因为SSL问题而混乱,因此,您会遇到错误的工厂加载。解决方案是在测试类上使用注释:

@PowerMockIgnore("javax.net.ssl.*")

取自https://groups.google.com/forum/#!topic/powermock/v4nreP2AnOQ