【问题标题】:How to extend expiration time of SOAP header message timestamp如何延长 SOAP 标头消息时间戳的过期时间
【发布时间】:2021-08-16 19:29:37
【问题描述】:

有没有办法延长 SOAP 消息头时间戳的生存时间(到期时间)以防止 “WSSecurityException:消息已过期”异常。默认设置为 300 秒(5 分钟)。我们想将它延长到 10 分钟。

我们有一个 java ee(jdk 1.8.0_77) 服务,它使用 SOAP 消息与 android 客户端进行通信。 它在 Jboss Wildfly 10.0.0 上运行。服务器,并使用 Apache CXF(版本 3.1.4)WS 安全性来处理消息。 wss4j 安全策略是 2.1.4 版 我们有 wsdl 文件、自定义 WS-Security Endpoint(server-endpoint-config.xml 文件)和我们的 Schema.xsd 文件。我不知道这些文件的哪些部分是相关的,所以如果有人需要更多信息,我会提供它们。 我尝试使用扩展 WSS4JInInterceptor 的自定义拦截器,但是这部分代码永远不会被执行。

@WebService
        (
                portName = "HelloPort",
                serviceName = "BampayService",
                wsdlLocation = "WEB-INF/BampayService.wsdl",
                targetNamespace = "http://bampay.bamcard.ba/",
                endpointInterface = "ba.bamcard.bampay.Hello"
        )
@EndpointConfig
        (
                configFile = "WEB-INF/server-endpoint-config.xml",
                configName = "Custom WS-Security Endpoint"
        )
@InInterceptors(// I added this part
    interceptors = {"ba.bamcard.helpers.MyInterceptor"}
)

和MyInterceptor的代码

public class MyInterceptor extends WSS4JInInterceptor {

    @Override
    public int decodeTimeToLive(RequestData reqData, boolean timestamp) {
//        return super.decodeTimeToLive(reqData, timestamp);
        return 600;
    }
}

如果需要,我很乐意提供任何其他信息。 如果有人能帮助我,我将不胜感激。

【问题讨论】:

    标签: java soap timestamp cxf ws-security


    【解决方案1】:

    将此属性添加到您想要的服务器端安全设置中。

    ws-security.timestamp.timeToLive
    

    如果您认为客户端和服务器之间的时钟偏差是导致错误的部分原因,您还需要考虑将来发送带有时间戳的消息的客户端。

    ws-security.timestamp.futureTimeToLive
    

    参考:https://cxf.apache.org/docs/ws-securitypolicy.html

    【讨论】:

    • 我将以上几行添加到文件 server-endpoint-config.xml 中,但错误仍然存​​在。这是我添加的:'ws-security.timestamp.timeToLive600' 这个文件在哪里应该是,还是我需要编辑另一个?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-31
    • 1970-01-01
    • 1970-01-01
    • 2018-06-25
    • 1970-01-01
    • 2015-06-26
    相关资源
    最近更新 更多