Java 如何通过Axis客户端传递自定义SSLContext来调用SOAP服务?

Java 如何通过Axis客户端传递自定义SSLContext来调用SOAP服务?,java,soap,jboss,axis,soap-client,Java,Soap,Jboss,Axis,Soap Client,我使用Axis-1.4调用SOAP服务。它一直工作到wsdl托管在http上。作为安全实现的一部分,现在SOAP服务器已经启用了使用客户端证书身份验证的https访问 我创建了一个JKS类型的自定义密钥库,并使用别名“myalias”将证书链导入其中。为了测试客户机证书,我使用HttpsURLConnection实现进行了如下测试,SOAP服务器能够接收客户机证书- HttpsURLConnection conn=(HttpsURLConnection)url.openConnection();

我使用Axis-1.4调用SOAP服务。它一直工作到wsdl托管在http上。作为安全实现的一部分,现在SOAP服务器已经启用了使用客户端证书身份验证的https访问

我创建了一个JKS类型的自定义密钥库,并使用别名“myalias”将证书链导入其中。为了测试客户机证书,我使用HttpsURLConnection实现进行了如下测试,SOAP服务器能够接收客户机证书-

HttpsURLConnection conn=(HttpsURLConnection)url.openConnection(); conn.setsslssocketfactory(sslContext.getSocketFactory())

但当与Axis客户端一起使用时,我无法发送客户端证书。Soap服务器返回身份验证错误7104未收到客户端证书

解决方案: 创建一个SocketFactory,如下所示:

public class MySocketFactory extends JSSESocketFactory implements SecureSocketFactory {
    public MySocketFactory(Hashtable attr){
        super(attr);
    }

    protected void initFactory() throws IOException {

        try {
            SSLContext context = getContext();
            this.sslFactory = context.getSocketFactory();
        } catch (Exception e) {
            if (e instanceof IOException) {
                throw (IOException) e;
            }
            System.out.print(e.getMessage());
            throw new IOException(e.getMessage());
        }
    }
 protected SSLContext getContext() throws Exception
    {
        try
        {
                    String  CERT_P = "changeit";

        KeyManagerFactory keyManagerFactory =KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        KeyStore identityKeyStore = KeyStore.getInstance("jks");
        FileInputStream identityKeyStoreFile = new FileInputStream(new File("Path to your jks"));
        identityKeyStore.load(identityKeyStoreFile, CERT_P.toCharArray());
        keyManagerFactory.init(identityKeyStore,CERT_P.toCharArray());
        log.debug("MySocketFactory -- Keystore loaded-");

        SSLContext sslContext = null;
        sslContext = SSLContext.getInstance("TLS");
        sslContext.init(keyManagerFactory.getKeyManagers(),null, new SecureRandom());

            return sslContext;
        }
        catch (Exception e)
        { e.printStackTrace();
            throw new Exception("Error creating context for SSLSocket.", e);
        }
    }
}

然后在调用绑定端口方法之前,添加以下代码: ´´´ setProperty(“axis.socketSecureFactory”,MySocketFactory.class.getCanonicalName())

'
这对我很有用。

你解决了吗?是的。.创建你的SocketFactory类,如下所示:我正在尝试附加一个文件,但我无法。。所以我会更新我的问题,谢谢。我想这正是我想要的。你解决了吗?是的..创建你的SocketFactory类,如下所示:我正在尝试附加一个文件,但我无法。。所以我会更新我的问题,谢谢。我想这正是我想要的。