如何在 spring-ws 安全性上手动设置时间戳

问题描述

客户端和服务器没有同步时间,因此soap服务器的安全返回未授权的响应。 我将获取服务器的当前时间,并在发送 soap 请求时使用该时间(在安全标头上,创建的用户名令牌 vs)。

如何在 spring-ws 上手动设置时间戳。

我正在使用 spring ws.client.core、ws.soap.security.wss4j2(Wss4jSecurityInterceptor 和 webservicetemplate)。 WS-Usernametoken 是为了安全而发送的(现时、用户名、密码、已创建(我猜是创建的问题。我应该设置它。) 服务器是onvif设备。

解决方法

您可以执行以下操作(来源here

<bean class="org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor">
<property name="validationActions" value="Timestamp"/>
<property name="timestampStrict" value="true"/>
<property name="timeToLive" value="10"/>

简而言之,您可以执行以下操作

  1. 调用 %SOAP.Security.Timestamp 的 Create() 类方法 set ts=##class(%SOAP.Security.Timestamp).Create()
  2. 调用 Web 客户端或 Web 服务的 SecurityOut 属性的 AddSecurityElement() 方法 do client.SecurityOut.AddSecurityElement(ts)e
  3. 发送 SOAP 消息