【问题标题】:Axis 2 and Rampart- why does service return wsse:Security header in request?Axis 2 和 Rampart - 为什么服务在请求中返回 wsse:Security 标头?
【发布时间】:2012-06-01 18:21:35
【问题描述】:

我正在连接到安全服务。

我有一个配置为使用 jks 文件提供证书的 SOAP UI 项目,以及允许我获得有效响应的适当安全设置。

我已经使用 AXIS 2 和 Rampart 从 JAVA 项目创建 SOAP 请求。 使用 TCPMon,我设法获取了 SOAP 请求。

当请求在 JAVA 项目中运行时,我只是得到响应:

org.apache.axis2.AxisFault:请求中缺少 wsse:Security 标头

但如果我接受相同的请求,在 TCPMon 中捕获并将其放入 SOAP UI 项目,我会成功获得响应。

有人有什么想法吗?

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">  <soapenv:Header>  
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"  
soapenv:mustUnderstand="1">  
  <wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"  
  wsu:Id="Timestamp-1">  
    <wsu:Created>2012-06-01T15:09:12.520Z</wsu:Created>  
    <wsu:Expires>2012-06-01T15:14:12.520Z</wsu:Expires>  
  </wsu:Timestamp>  
  <wsse:BinarySecurityToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"  
  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#X509v3"  
  wsu:Id="CertId-ECDB0E....01">  
  MIID4DCCA0mgAwIBAgIBFjAN....</wsse:BinarySecurityToken>  
  <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"  
  Id="Signature-2">  
    <ds:SignedInfo>  
      <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />  
      <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />  
      <ds:Reference URI="#Id-15..93">  
        <ds:Transforms>  
          <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />  
        </ds:Transforms>  
        <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />  
        <ds:DigestValue>  
        3wgvhJ8SI2soC..IA=</ds:DigestValue>  
      </ds:Reference>  
      <ds:Reference URI="#Timestamp-1">  
        <ds:Transforms>  
          <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />  
        </ds:Transforms>  
        <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />  
        <ds:DigestValue>  
        VlzDT69YEl..qTlbj0=</ds:DigestValue>  
      </ds:Reference>  
    </ds:SignedInfo>  
    <ds:SignatureValue>  
    ZCRypw/..=</ds:SignatureValue>  
    <ds:KeyInfo Id="KeyId-ECD..2">  
      <wsse:SecurityTokenReference xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"  
      wsu:Id="STRId-ECDB0E6..6193">  
        <wsse:Reference URI="#CertId-ECDB0E..01"  
        ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" />  
      </wsse:SecurityTokenReference>  
    </ds:KeyInfo>  
  </ds:Signature>  
</wsse:Security></soapenv:Header><soapenv:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Id-15..3"><ns2:ProductSearchV2Request xmlns:ns2="http://product.webservice.sxc.com">   
  <ns2:Strength>900</ns2:Strength>  
  <ns2:MaximumResultSetInd>true</ns2:MaximumResultSetInd>  
  <ns2:MaximumResultSet>100</ns2:MaximumResultSet>  
</ns2:ProductSearchV2Request>  


这是我正在使用的 WS-POLICY 文档:

<?xml version="1.0" encoding="UTF-8"?>  
<!--  
 !  
 ! Copyright 2006 The Apache Software Foundation.  
 !  
 ! Licensed under the Apache License, Version 2.0 (the "License");  
 ! you may not use this file except in compliance with the License.  
 ! You may obtain a copy of the License at  
 !  
 !      http://www.apache.org/licenses/LICENSE-2.0  
 !  
 ! Unless required by applicable law or agreed to in writing, software  
 ! distributed under the License is distributed on an "AS IS" BASIS,  
 ! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
 ! See the License for the specific language governing permissions and  
 ! limitations under the License.  
 !-->  
<wsp:Policy wsu:Id="SigOnly"  
            xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"  
            xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">  
    <wsp:ExactlyOne>  
        <wsp:All>  
            <sp:AsymmetricBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">  
                <wsp:Policy>  
                    <sp:InitiatorToken>  
                        <wsp:Policy>  
                            <sp:X509Token  
                                    sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">  
                                <wsp:Policy>  
                                    <sp:RequireThumbprintReference/>  
                                    <sp:WssX509V3Token10/>  
                                </wsp:Policy>  
                            </sp:X509Token>  
                        </wsp:Policy>  
                    </sp:InitiatorToken>  
                    <sp:RecipientToken>  
                        <wsp:Policy>  
                            <sp:X509Token  
                                    sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Never">  
                                <wsp:Policy>  
                                    <sp:RequireThumbprintReference/>  
                                    <sp:WssX509V3Token10/>  
                                </wsp:Policy>  
                            </sp:X509Token>  
                        </wsp:Policy>  
                    </sp:RecipientToken>  
                    <sp:AlgorithmSuite>  
                        <wsp:Policy>  
                            <sp:TripleDesRsa15/>  
                        </wsp:Policy>  
                    </sp:AlgorithmSuite>  
                    <sp:Layout>  
                        <wsp:Policy>  
                            <sp:Strict/>  
                        </wsp:Policy>  
                    </sp:Layout>  
                    <sp:IncludeTimestamp/>  
                    <sp:OnlySignEntireHeadersAndBody/>  
                </wsp:Policy>  
            </sp:AsymmetricBinding>  
            <sp:Wss10 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">  
                <wsp:Policy>  
                    <sp:MustSupportRefKeyIdentifier/>  
                    <sp:MustSupportRefIssuerSerial/>  
                </wsp:Policy>  
            </sp:Wss10>  
            <sp:SignedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">  
                <sp:Body/>  
            </sp:SignedParts>  
            <ramp:RampartConfig xmlns:ramp="http://ws.apache.org/rampart/policy">  
                <ramp:user>ctr</ramp:user>  
                <ramp:encryptionUser>ctr</ramp:encryptionUser>  
                <ramp:passwordCallbackClass>com.gtnet.rampart.PWCBHandler  
                </ramp:passwordCallbackClass>  

                <ramp:signatureCrypto>  
                    <ramp:crypto provider="org.apache.ws.security.components.crypto.Merlin">  
                        <ramp:property name="org.apache.ws.security.crypto.merlin.keystore.type">JKS</ramp:property>  
                        <ramp:property name="org.apache.ws.security.crypto.merlin.file">build\resources\qa.jks</ramp:property>  
                        <ramp:property name="org.apache.ws.security.crypto.merlin.keystore.password">123123</ramp:property>  
                    </ramp:crypto>  
                </ramp:signatureCrypto>  
            </ramp:RampartConfig>  

        </wsp:All>  
    </wsp:ExactlyOne>  
</wsp:Policy>  

谢谢 艾伦

【问题讨论】:

  • 我开始怀疑这可能与响应有关。我尝试使用wireshark 来检查HTTP 请求,但是由于它是加密的并且我没有私钥,我无法找到一种方法来确认从Java 应用程序发送和接收的内容。上面的请求是使用 TCPMon 捕获并转到本地 http 端口

标签: web-services soap https axis2 rampart


【解决方案1】:

看起来好像错误不是出站请求,而是处理响应。 响应没有安全标头,当我们尝试对其进行解密时,会发生异常。

我需要以某种方式将我的 Rampart 配置更改为只执行出站安全,而不是入站

我会回来报告的:)


好的,问题是一旦 Rampart 被启用,它期望响应具有相同的安全标头。 我解决问题的方法是删除 Rampart.mar 文件中流入安全性的处理程序。

我不确定这是否是最好的解决方法,但它对我们有用。

要删除流入处理程序: 解压rampart.mar文件

注释掉流入部分

压缩 META_INF 文件夹。然后将.zip文件重命名为.mar

现在当您使用它时,因为没有为流入定义处理程序,它只会使用标准的 Axis2 响应处理程序。

我猜如果您有多个使用 Rampart 的项目,其中一些在响应中有安全标头,而另一些没有,您将需要不同的方法。


这里详细介绍了另一种方法。 这可能是一个更好的方法:

http://blog.rampartfaq.com/2009/11/how-to-generate-non-secure-response-to.html

例外:

org.apache.axis2.AxisFault:请求中缺少 wsse:Security 标头 在 org.apache.rampart.handler.RampartReceiver.setFaultCodeAndThrowAxisFault(RampartReceiver.java:180) 在 org.apache.rampart.handler.RampartReceiver.invoke(RampartReceiver.java:99) 在 org.apache.axis2.engine.Phase.invoke(Phase.java:318) 在 org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:251) 在 org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:160) 在 org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:364) 在 org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:417) 在 org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)

【讨论】:

    【解决方案2】:

    浏览了很多遍,并且多次阅读相同的页面,我终于得到了一个令我满意的解决方案。

    从上一篇文章中我引用:“好吧,问题是一旦 Rampart 参与,它期望响应具有相同的安全标头。” (根据要求) 这绝对是真的!

    我觉得最好的办法在下面的链接里:http://xacmlinfo.org/2012/11/09/disabling-ws-security-for-in-or-out-messages-in-axis2/

    但是,就我而言,我不想制作新模块,因此我决定在我的代码中模拟该模块。我试着分三步来解释。

    1. (首先)我在代码中使用了默认策略(取自上一个链接)作为方法。 (它适用于 Axis 1.6.2 和 Rampart 的兼容版本)

    私有字符串 getPolicy() { 返回“用于策略的 xml” }

    重要该方法必须将以下xml作为字符串返回(更好阅读)

    <wsp:Policy wsu:Id="emptryPolicy" 
    xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
    xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    <wsp:ExactlyOne>
    <wsp:All>
    <sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"> 
    <wsp:Policy>
    </wsp:Policy>
    </sp:TransportBinding>
    </wsp:All>
    </wsp:ExactlyOne>
    </wsp:Policy>
    
    1. (二)我根据之前的方法创建了一个Policy(对象)。

    InputStream 流 = new ByteArrayInputStream(getPolicy().getBytes());

    策略 p = PolicyEngine.getPolicy(stream);

    1. (第三)我使用了KEY_RAMPART_IN_POLICY和KEY_RAMPART_OUT_POLICY的属性。

    Stub._getServiceClient().getOptions().setProperty(RampartMessageData.KEY_RAMPART_OUT_POLICY,网络服务的安全策略);

    Stub._getServiceClient().getOptions().setProperty(RampartMessageData.KEY_RAMPART_IN_POLICY, p);

    重要 Web 服务的安全策略取决于 Web 服务使用的安全性...如果您的提供商在 wsdl 中提供了策略,您就不必为此纠结...但在其他情况下,您只需使用壁垒政策。在壁垒站点中,对每种类型的安全策略都有非常清晰的示例描述。 (UsernameToken认证、AsymmetricBinding等)

    这个例子塑造了一个有安全性的请求和没有安全性的响应。 它对我有用!

    【讨论】:

    • 为我工作,我的配置正在应用 RampartMessageData.KEY_RAMPART_POLICY (另一个属性,没有适用于它们的 IN 或 OUT)。对带有 RampartMessageData.KEY_RAMPART_IN_POLICY 的传入响应使用空策略是这种情况的最佳解决方案。
    【解决方案3】:

    在我的情况下,同样的问题,但我通过更改存根中的肥皂请求版本名称空间 uri 获得了成功响应。我已将名称空间 uri 从“http://www.w3.org/2003/05/soap-envelope”更改为“http://schemas.xmlsoap.org/soap/envelope/”。

    【讨论】:

    • OP 正在使用的规范。
    猜你喜欢
    • 2011-06-04
    • 1970-01-01
    • 2017-04-15
    • 2016-06-10
    • 1970-01-01
    • 2016-03-21
    • 2022-10-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多