You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何移除WSO2 ESB代理服务策略生成的SOAP头中的Timestamp标签?

嘿,我刚好处理过类似的需求,要移除WSO2 ESB代理服务里WS-Security头的<Timestamp>标签,有两种靠谱的方法,看你哪种更适合:

方法一:直接修改WS-Security策略文件

这是最直接的方式——如果你有权限修改对应的策略配置,直接删掉策略里和Timestamp相关的配置段就行。

比如你原来的策略可能包含这样的代码:

sp:SupportingTokens
wsp:Policy
<sp:UsernameToken sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient"/>
<sp:Timestamp sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient"/>
</wsp:Policy>
</sp:SupportingTokens>

把里面的<sp:Timestamp>...</sp:Timestamp>整个段删掉,保存策略后重新部署代理服务。这样策略生成的WS-Security头就只会包含UsernameToken,不会再带Timestamp了。

方法二:用中介器(Mediator)动态移除标签

如果你的策略是共享的不能修改,或者想在消息流里灵活控制,就用XSLT或PayloadFactory中介器来移除SOAP头里的Timestamp。

推荐用XSLT中介器,写个简单的转换脚本就行:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
                xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    <xsl:output method="xml" indent="yes"/>
    <!-- 默认复制所有节点 -->
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
    <!-- 匹配并移除Security头下的Timestamp节点 -->
    <xsl:template match="wsse:Security/wsu:Timestamp"/>
</xsl:stylesheet>

把这个XSLT脚本保存成文件(比如remove-timestamp.xsl),上传到ESB的注册表或者本地目录,然后在代理服务的outSequence(如果是出站消息)或者inSequence(如果是入站消息)里添加XSLT中介器,指定这个脚本的路径。注意要确保这个中介器在WS-Security策略执行之后运行,这样才能删掉已经生成的Timestamp标签。

另外要确认命名空间:Timestamp的默认命名空间是wsu,如果你的策略里用了其他命名空间,记得修改XSLT里的对应前缀。

内容的提问来源于stack exchange,提问作者Daniil Khromov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 04:35:03