1

我为需要 WS 安全标头的 Web 服务编写了一个客户端 (Java)。我使用 cxf 从 WSDL 生成我的源代码。当我在 Tomcat 上运行我的客户端时,它工作正常,但是,当我将它移动到 Websphere 时,我从服务返回一个错误,说签名无效。我比较了生成的肥皂信封,两者之间的所有标签都匹配,并且键值相同。唯一的区别是WAS 为soapenc、xsi 和xsd 添加了名称空间。然后将这些前缀添加到规范化方法的 IncludedNamespaces 中。从我读过的内容来看,可以得到签名的混合。我不知道 Websphere 是否正在添加这些,或者它是否可能是正在选择的课程的不同版本。无论哪种方式,Web 服务都不会接受带有这些命名空间的它。这些可以去掉吗?

WebSphere 名称空间包含

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Header xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

Websphere 规范化标签

         <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
            <ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="soapenc xsd xsi" />
         </ds:Transform>
      </ds:Transforms>

Tomcat 命名空间包含

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">

Tomcat 规范化标签

          <ds:Transforms>
             <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
                <ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="wsse soap" />
             </ds:Transform>
          </ds:Transforms>

这是我的 WSS4jOutInterceptor Spring Config(删除了一些数据)

<bean class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor"
        id="outbound-security">     
        <constructor-arg>
            <map>
                <entry key="action" value="Timestamp Signature" />
                <entry key="user" value=--REMOVED-- />
                <entry key="signaturePropFile" value=--REMOVED-- />
                <entry key="encryptionPropFile" value=--REMOVED-- />
                <entry key="encryptionUser" value=--REMOVED--/>
                <entry key="useSingleCertificate" value="true"/>
                <entry key="signatureKeyIdentifier" value="DirectReference" />
                <entry key="passwordCallbackClass" value=--REMOVED-- />
                <entry key="signatureParts"
                    value="{Element}{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd}Timestamp;{Element}{http://schemas.xmlsoap.org/soap/envelope/}Body" />              
                <entry key="signatureAlgorithm" value="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" />
                <entry key="sigCanonicalization" value="http://www.w3.org/2001/10/xml-exc-c14n#" />
                <entry key="signatureDigestAlgorithm" value="http://www.w3.org/2001/04/xmlenc#sha256" />
            </map>
        </constructor-arg>
    </bean> 

编辑:这看起来是由运行时中的一些存档引起的。有谁知道在 jre 和 websphere 8 运行时中构建肥皂信封的包是什么?这可能就是存在差异的地方。任何帮助是极大的赞赏!

4

1 回答 1

1

事实证明,这与不正确的名称空间或规范化方法无关。默认情况下,Websphere 进行此调用“BSP_compliant”,它为键添加了一些值。

这些行解决了这个问题。

Map<String, Object> ctx = ((BindingProvider)port).getRequestContext();
ctx.put(WSHandlerConstants.IS_BSP_COMPLIANT, "false");
于 2015-03-10T23:52:30.570 回答