如何使用 Wss4jSecurityInterceptor 将 SAML 断言添加到 Spring 中的 SOAP 安全标头

发布于 2025-01-10 11:33:47 字数 2342 浏览 0 评论 0原文

我需要将 SAML 断言作为 SOAP 安全标头内的令牌传递。我使用 Spring-WS 作为框架。

我想要创建的 XML 如下所示:

我需要将 SAML 断言作为 SOAP 安全标头内的令牌传递。

我想要创建的 XML 如下所示。可以看出,XML 包含带有 wsse:Security 块的断言。

有没有办法使用 Wss4jSecurityInterceptor 类来做到这一点?

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header>
        <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">

            <Assertion MinorVersion="1" MajorVersion="1" Issuer="http://www.bea.com/saml"
                       IssueInstant="2005-11-10T11:27:36.233Z" AssertionID="HRMC-SM172.26.5.143.1106860829320"
                       xmlns="urn:oasis:names:tc:SAML:1.0:assertion">
                <Conditions NotOnOrAfter="2005-11-10T15:27:36.233Z" NotBefore="2005-11-10T11:22:36.233Z"/>
                <AuthenticationStatement AuthenticationMethod="urn:oasis:names:tc:SAML:1.0:am:unspecified"
                                         AuthenticationInstant="2005-11-10T11:27:36.233Z">
                    <Subject>
                        <NameIdentifier Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified">ANYAGENT
                        </NameIdentifier>
                        <SubjectConfirmation>
                            <ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:sender-vouches</ConfirmationMethod>
                        </SubjectConfirmation>
                    </Subject>
                </AuthenticationStatement>
            </Assertion>

        </wsse:Security>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
        <m:DPSretrieve xmlns:m="https://tpvs.hmrc.gov.uk/dps">
            <m:version>1</m:version>
            <m:vendorID>your 4 digit vendorID</m:vendorID>
            <m:service>PAYE</m:service>
            <m:entityType>EmpRef</m:entityType>
            <m:entity>as advised by SDS Team</m:entity>
            <m:dataType>P6</m:dataType>
            <m:got>0</m:got>
            <m:nItems>0</m:nItems>
        </m:DPSretrieve>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I have a requirement to pass a SAML assertion as a token inside a SOAP security header. I am using Spring-WS as the framework.

The XML that I want to create looks like this:

I have a requirement to pass a SAML assertion as a token inside a SOAP security header.

The XML that I want to create looks as below. As can be seen, the XML contains the assertion with the wsse:Security block.

Is there a way to do this with the Wss4jSecurityInterceptor class ?

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header>
        <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">

            <Assertion MinorVersion="1" MajorVersion="1" Issuer="http://www.bea.com/saml"
                       IssueInstant="2005-11-10T11:27:36.233Z" AssertionID="HRMC-SM172.26.5.143.1106860829320"
                       xmlns="urn:oasis:names:tc:SAML:1.0:assertion">
                <Conditions NotOnOrAfter="2005-11-10T15:27:36.233Z" NotBefore="2005-11-10T11:22:36.233Z"/>
                <AuthenticationStatement AuthenticationMethod="urn:oasis:names:tc:SAML:1.0:am:unspecified"
                                         AuthenticationInstant="2005-11-10T11:27:36.233Z">
                    <Subject>
                        <NameIdentifier Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified">ANYAGENT
                        </NameIdentifier>
                        <SubjectConfirmation>
                            <ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:sender-vouches</ConfirmationMethod>
                        </SubjectConfirmation>
                    </Subject>
                </AuthenticationStatement>
            </Assertion>

        </wsse:Security>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
        <m:DPSretrieve xmlns:m="https://tpvs.hmrc.gov.uk/dps">
            <m:version>1</m:version>
            <m:vendorID>your 4 digit vendorID</m:vendorID>
            <m:service>PAYE</m:service>
            <m:entityType>EmpRef</m:entityType>
            <m:entity>as advised by SDS Team</m:entity>
            <m:dataType>P6</m:dataType>
            <m:got>0</m:got>
            <m:nItems>0</m:nItems>
        </m:DPSretrieve>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜是你 2025-01-17 11:33:47

我最终通过这个答案修复了它,效果非常好:

https://stackoverflow.com/a/59666667/3094805

I ended up fixing it via this answer, which worked perfectly:

https://stackoverflow.com/a/59666667/3094805

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文