【问题标题】:How to programmatically set the SSL context of a Axis client?如何以编程方式设置 Axis 客户端的 SSL 上下文?
【发布时间】:2015-06-14 09:48:35
【问题描述】:

在一个非常古老的项目中,我们使用使用 Axis 1.4 开发的客户端来调用 SOAP Web 服务。此 Web 服务使用相互身份验证机制,因此我们在密钥库中安装了一个私有证书,在信任库中安装了一个公钥。

SOAP 客户端用于 BPM 流程的任务中。我们不能也不想使用 JVM 全局信任库和密钥库。那么我们就不能以编程方式配置 JVM 全局 trustore 和 keystore:

// Keystore
System.setProperty("javax.net.ssl.keyStore", fileKeystore);
System.setProperty("javax.net.ssl.keyStorePassword", pwdKeystore);
System.setProperty("javax.net.ssl.keyStoreType", "PKCS12");
// Truststore
System.setProperty("javax.net.ssl.trustStore", fileTruststore);
System.setProperty("javax.net.ssl.trustStorePassword", pwdTruststore);
System.setProperty("javax.net.ssl.trustStoreType", "JKS");

这样的方法将迫使我们在 JVM 属性上同步进程,而我们不想这样做。而且,机器上还运行着其他的java进程。

我的问题是:Axis 1.4 是否提供一些 API 来指定用于特定 Web 服务调用的密钥库和信任库?

【问题讨论】:

    标签: java ssl soap axis


    【解决方案1】:

    好的,谷歌搜索了一下,我找到了我的问题的答案。答案是仅使用 Axis 1.4 不可能为每个服务调用指定不同的密钥库/信任库。我们需要一个外部库,名为axistools

    该库实现了一种特定类型的EngineConfiguration,允许您为每个服务调用指定一个密钥库和/或信任库。

    下面的例子将是解释性的:

    // Setting up the configuration
    SSLClientAxisEngineConfig config = new SSLClientAxisEngineConfig();
    config.setKeystore("path/to/your/keystore");
    config.setKeystoreType("JKS");
    config.setKeystorePassword("password");
    config.setTruststore("path/to/your/truststore");
    config.setTruststoreType("JKS");
    config.setTruststorePassword("password");
    // Very important: without this method invocation 
    // the client won't work at all
    config.initialize();
    
    // Calling the web service
    URL url = new URL("https://localhost:8443/someService");
    WebServiceLocator locator = new WebServiceLocator (config);
    WebServiceSoap port = locator.getWebServiceSoap(url);
    WebServiceSoapStub stub = (WebServiceSoapStub) port;
    stub.serviceMethod();
    

    就是这样,伙计们!!!

    【讨论】:

    • mvnrepository.com/artifact/org.codehaus.mojo/… jar 没有提到的 SSLClientAxisEngineConfig 类。您能否给出正确的 maven 依赖项
    • 天哪,你是对的!尝试从herehere 检索库。告诉我。
    • SSLClientAxisEngineConfig 类在提到的jar 中有所不同。config.initialize();后者不存在。我尝试了后者仍然“无法获得有效的认证路径”
    • 我敢打赌,您正在搜索的是 this 链接。在页面末尾您可以找到axistools.jar
    • 是的,这就是我要找的东西。谢谢。使用它但出现不受信任的证书链错误。
    猜你喜欢
    • 2012-06-15
    • 1970-01-01
    • 2011-01-28
    • 1970-01-01
    • 2011-02-05
    • 1970-01-01
    • 2012-10-05
    • 1970-01-01
    相关资源
    最近更新 更多