【问题标题】:How to add MessageID in SOAP request using Axis2 and Rampart如何使用 Axis2 和 Rampart 在 SOAP 请求中添加 MessageID
【发布时间】:2015-11-18 20:35:20
【问题描述】:

我正在尝试使用Axis2rampat 1.6 构建一个使用外部服务器应用程序的客户端应用程序。

检查 SOAP 请求时似乎一切正常,因为 SOAP 已按预期进行加密和签名。以下是用于该目的的 policy.xml 文件:

<wsp:Policy wsu:Id="MyPolicy"
    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"
    xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"
    xmlns:wsam="http://schemas.xmlsoap.org/ws/2004/08/addressing" 
    xmlns:wst="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.0#SAMLAssertionID">
<wsp:ExactlyOne>
    <wsp:All>
        <sp:SignedSupportingTokens xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702">
            <wsp:Policy>
                <sp:UsernameToken sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient" />
            </wsp:Policy>
        </sp:SignedSupportingTokens>
        <sp:SymmetricBinding>
            <wsp:Policy>
                <sp:ProtectionToken>
                    <wsp:Policy>
                        <sp:X509Token sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Never">
                            <wsp:Policy>
                                <sp:RequireIssuerSerialReference/>
                                <sp:WssX509V3Token10/>
                            </wsp:Policy>
                        </sp:X509Token>
                    </wsp:Policy>
                </sp:ProtectionToken>

                <sp:AlgorithmSuite>
                    <wsp:Policy>
                        <sp:Basic128/>
                    </wsp:Policy>
                </sp:AlgorithmSuite>
                <sp:IncludeTimestamp/>
                <sp:Layout>
                    <wsp:Policy>
                        <sp:Strict/>
                    </wsp:Policy>
                </sp:Layout>
                <sp:OnlySignEntireHeadersAndBody/>
            </wsp:Policy>
        </sp:SymmetricBinding>
        <sp:EncryptedParts>
            <sp:Body />
        </sp:EncryptedParts>
        <sp:SignedParts>
            <sp:Body/>
            <sp:Header Namespace="http://www.w3.org/2005/08/addressing" Name="ReplyTo"/>
            <sp:Header Namespace="http://www.w3.org/2005/08/addressing" Name="To"/>
            <sp:Header Namespace="http://www.w3.org/2005/08/addressing" Name="From"/>
            <sp:Header Namespace="http://docs.oasis-open.org/ws-rx/wsrm/200702" Name="AckRequested"/>
            <sp:Header Namespace="http://docs.oasis-open.org/ws-rx/wsrm/200702" Name="CreateSequence"/>
            <sp:Header Namespace="http://docs.oasis-open.org/ws-rx/wsrm/200702" Name="Sequence"/>
            <sp:Header Namespace="http://www.w3.org/2005/08/addressing" Name="MessageID"/>
            <sp:Header Namespace="http://www.w3.org/2005/08/addressing" Name="FaultTo"/>
            <sp:Header Namespace="http://docs.oasis-open.org/ws-rx/wsrm/200702" Name="SequenceAcknowledgement"/>
            <sp:Header Namespace="http://www.w3.org/2005/08/addressing" Name="Action"/>
            <sp:Header Namespace="http://www.w3.org/2005/08/addressing" Name="RelatesTo"/>
        </sp:SignedParts>
        <sp:Wss11>
            <wsp:Policy>
                <sp:MustSupportRefEncryptedKey/>
                <sp:MustSupportRefIssuerSerial/>
                <sp:MustSupportRefThumbprint/>
            </wsp:Policy>
        </sp:Wss11>
        <ramp:RampartConfig xmlns:ramp="http://ws.apache.org/rampart/policy">
            <ramp:userCertAlias>mySignAlias</ramp:userCertAlias>
            <ramp:encryptionUser>myEncryptAlias</ramp:encryptionUser>
            <ramp:user>myUser</ramp:user>
            <ramp:passwordCallbackClass>myPackage.PasswordCallBackHandler</ramp:passwordCallbackClass>
            <ramp:encryptionCypto>
                <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">[path goes here]/clientTrustStore.jks</ramp:property>
                    <ramp:property name="org.apache.ws.security.crypto.merlin.keystore.password">changeit</ramp:property>
                </ramp:crypto>
            </ramp:encryptionCypto>

            <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">[path goes here]/clientKeyStore.jks</ramp:property>
                    <ramp:property name="org.apache.ws.security.crypto.merlin.keystore.password">changeit</ramp:property>
                </ramp:crypto>
            </ramp:signatureCrypto>
        </ramp:RampartConfig>

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

但在调用外部服务器应用程序时出现以下轴故障:

SEVERE: org.apache.axis2.AxisFault: com.sun.xml.wss.XWSSecurityException: Policy verification error:Missing target MessageID for Signature
at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:531)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:375)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)

错误是自我描述的,SOAP 请求在 SOAP 标头中缺少 MessageID 标记。我很想知道如何添加提到的标签,但没有运气;我发现了如何在这个链接adding authentication header to client stub axis2

中添加自定义 SOAP 标头

但我想避免这种情况,因为我使用PasswordCallBackHandler 添加身份验证属性。

有没有办法在 SOAP 标头中自动添加 MessageID ?此外,还有ActionReplyToToFrom 等类似标签,如何将它们添加到 SOAP 标头?

-- 更新:

从使用 Axis2 工具自动生成的 java 文件 - 请参阅 Apache Axis2 User's Guide - Creating Clients 以了解如何生成存根文件 - 我去了自动生成的 Java 类 ServiceStub 中的 API 方法.创建了一个消息 contxet 来发送 SOAP 请求,如下所示:

 // create a message context
_messageContext = new org.apache.axis2.context.MessageContext();

我使用对象_messageContext来设置消息ID如下:

_messageContext.setMessageID("TEST_123456");

此外,我在调试模式下运行应用程序,我可以看到 TEST_123456 已作为 MessageID 添加到 SOAP 请求中,并且服务器在其响应中使用相同的 MessageID。但我仍然收到此有线错误Policy verification error:Missing target MessageID for Signature

我很困惑服务器如何说他失踪MessageID 尽管它出现在仅来自服务器的 SOAP 请求和响应中!

这与自动签名过程有什么关系吗?但即便如此,MessageID 已经添加到来自策略文件的SignedParts 中,还有什么办法可以解决这个问题?

【问题讨论】:

    标签: xml web-services soap axis2 rampart


    【解决方案1】:

    您可以在Stub::ServiceClient::Options 中添加所有属性,例如 Message、Action、To 和其他属性。

    ServiceClient client = serviceStub._getServiceClient();
    Options options = client.getOptions();
    options.setAction(action);
    options.setTo(new EndpointReference(referenceURL));
    options.setMessageId(UUID.randomUUID().toString());
        
    

    Sample Reference

    【讨论】:

      猜你喜欢
      • 2011-06-04
      • 1970-01-01
      • 2011-07-02
      • 2014-01-03
      • 2011-09-15
      • 2015-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多