文章目录
第四十章 创建安全对话 - 启用 IRIS Web 服务以支持 WS-SecureConversation
启用 IRIS Web 服务以支持 WS-SecureConversation
当 Web 客户端向 Web 服务发送请求安全对话的消息时,安全对话就开始了。作为响应,Web 服务发送双方都可以使用的 <SecurityContextToken>。
要使 IRIS Web 服务能够使用此令牌进行响应,请重写 Web 服务的 OnStartSecureConversation() 方法。此方法具有以下签名:
Method OnStartSecureConversation(RST As %SOAP.WST.RequestSecurityToken) As
%SOAP.WST.RequestSecurityTokenResponseCollection
该方法应该执行以下操作:
- 加密
SOAP主体。OnStartSecureConversation()发送的消息包含必须保护的信息;此信息在SOAP主体中携带。
根据需要,可以选择采用其他方式保护消息安全。
- (可选)调用
%SOAP.WST.Entropy的CreateBinarySecret()方法。此方法返回表示随机服务器熵的该类的实例。该方法接受一个参数,即熵的大小(以字节为单位)。
set serverEntropy=##class(%SOAP.WST.Entropy).CreateBinarySecret(32)
该实例表示 <Entropy>元素和其中包含的 <BinarySecret>。
- 在
OnStartSecureConversation()收到的实例中调用%SOAP.WST.RequestSecurityToken的CreateIssueResponse()方法。CreateIssueResponse()方法采用以下参数:
a. $THIS,代表当前的 Web 服务实例。
b. keysize,所需密钥的大小(以字节为单位)。仅当同时提供服务器熵和客户端熵时才使用此参数。默认值是较小密钥的大小(给定客户端熵中的密钥和服务器熵中的密钥)。
c. requireClientEntropy,其值为 true 或 false,取决于 Web 服务是否要求请求包含客户端熵。如果为 false,则请求不得包含客户端熵。
d. serverEntropy,在步骤2中创建的服务器熵对象(如果适用)。
e. error错误,作为输出参数返回的状态代码。
f. lifetime,一个整数,指定安全对话的生存期(以秒为单位)。
set responseCollection=RST.CreateIssueResponse($this,,1,serverEntropy,.error)
- 检查上一步中的错误输出参数。如果发生错误,代码应设置
Web服务的SoapFault属性并返回一个空字符串。 - 如果成功,则中返回由步骤 2 创建 的
%SOAP.WST.RequestSecurityTokenResponseCollection的实例。
该实例代表<RequestSecurityTokenResponseCollection>元素,其中包含双方可以使用的 <SecurityContextToken>。
以下显示一个例子:
Method OnStartSecureConversation(RST As %SOAP.WST.RequestSecurityToken)
As %SOAP.WST.RequestSecurityTokenResponseCollection
{
// encrypt the SOAP body sent by this messsage
//because it contains part of the shared secret key
Set x509alias = "clientnopassword"
Set cred = ##class(%SYS.X509Credentials).GetByAlias(x509alias)
set enckey=##class(%XML.Security.EncryptedKey).CreateX509(cred)
do ..SecurityOut.AddSecurityElement(enckey)
//Supply the server entropy
set serverEntropy=##class(%SOAP.WST.Entropy).CreateBinarySecret(32)
// Get the response collection for computed key
set responseCollection=RST.CreateIssueResponse($this,,1,serverEntropy,.error)
If error'="" {
set ..SoapFault=##class(%SOAP.WST.RequestSecurityTokenResponse).MakeFault("InvalidRequest")
Quit ""
}
Quit responseCollection
}
注意:OnStartSecureConversation() 方法最初定义为仅当策略指定时才返回 <SecurityContextToken>。请参阅创建和使用策略。









