1

I need to call a web service with a java client. This service authenticates clients through certificates at the message level (Ws-Security, not SSL).

It should be possible since, I can generate web services with JAX-WS with mutual certificate security in this dialog.

But I don't manage to create a client. Does anyone has an idea ?

4

1 回答 1

1

我自己没有尝试过,但是来自http://download.oracle.com/docs/cd/E17802_01/webservices/webservices/docs/2.0/tutorial/doc/

使用 XWSS 配置消息安全性

Application Server 包含使用 XWS-Security 保护 JAX-WS 应用程序所需的所有 JAR 文件,但是,为了查看示例应用程序,您必须下载并安装独立的 Java WSDP 包。您可以从http://java.sun.com/webservices/downloads/webservicespack.html下载 Java WSDP 。

要使用 XWSS 向现有 JAX-WS 应用程序添加消息安全性,请在客户端执行以下步骤:

  • 创建客户端安全配置。客户端安全配置文件指定将用于客户端应用程序的消息安全操作的顺序和类型。例如,执行数字签名操作的简单安全配置如下所示:

            <xwss:Sign id="s" includeTimestamp="true">
                <xwss:X509Token encodingType="http://docs.oasis-
                  open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"
                                valueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-
                  x509-token-profile-1.0#X509SubjectKeyIdentifier"
                                certificateAlias="xws-security-client"
                                keyReferenceType="Identifier"/>
            </xwss:Sign>
    
        </xwss:SecurityConfiguration>
    </xwss:Service>
    <xwss:SecurityEnvironmentHandler>
        simple.client.SecurityEnvironmentHandler
    </xwss:SecurityEnvironmentHandler>
    

    有关编写和理解安全配置以及设置 SecurityEnvironmentHandlers 的更多信息,请参阅位于http://java.sun.com/webservices/docs/1.6/tutorial/doc/index.html的 Java Web Services Developer Pack 1.6 教程。

  • 在您的客户端代码中,创建一个使用生成的安全配置初始化的 XWSSecurityConfiguration 对象。这是您将在客户端文件中使用的代码示例。有关使用此代码的完整文件的示例,请查看 \jaxws2.0\simple-doclit\src\simple\client\ 目录中的示例客户端。

    FileInputStream f = new FileInputStream("./etc/client_security_config.xml"); 
    XWSSecurityConfiguration config = SecurityConfigurationFactory.newXWSSecurityConfiguration(f);  
    
  • RequestContext使用该XWSSecurityConfiguration.MESSAGE_SECURITY_CONFIGURATION属性设置安全配置信息。有关使用此代码的完整文件的示例,请查看 \jaxws2.0\simple-doclit\src\simple\client\ 目录中的示例客户端。

    // put the security config info
    ((BindingProvider)stub).getRequestContext().put(
        XWSSecurityConfiguration.MESSAGE_SECURITY_CONFIGURATION,
        config); 
    
  • 如果您正在编写客户端而不考虑添加 XWS-Security,则调用存根上的方法。\jaxws2.0\simple-doclit\src\simple\client\ 目录下的应用程序示例如下所示:

    Holder<String> hold = new Holder("Hello !");
    stub.ping(ticket, hold); 
    
于 2011-05-11T00:59:51.420 回答