首页 > 解决方案 > 如何延长 SOAP 标头消息时间戳的过期时间

问题描述

有没有办法延长 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;
    }
}

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

标签: javasoaptimestampcxfws-security

解决方案


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

ws-security.timestamp.timeToLive

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

ws-security.timestamp.futureTimeToLive

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


推荐阅读