文章目录
- 第十九章 添加时间戳和用户名令牌 - 时间戳和用户名令牌示例
- 时间戳和用户名令牌示例
第十九章 添加时间戳和用户名令牌 - 时间戳和用户名令牌示例
时间戳和用户名令牌示例
此示例显示了一个需要密码验证的 Web
服务,以及一个在其请求消息中发送时间戳和用户名令牌的 We
b 客户端。
注意:此示例以明文形式发送用户名和密码。
为了使此示例在自己的环境中运行,请首先执行以下操作:
- 对于
Web
服务所属的Web
应用程序,将该应用程序配置为仅支持密码验证:
- 从管理门户主页,选择系统管理 > 安全 > 应用程序 > Web 应用程序。
- 选择 Web 应用程序。
- 仅选择密码选项,然后选择保存。
- 如果不使用默认设置,请编辑客户端以使用适当的 IRIS 用户名和密码。
Web
服务如下:
Class Tokens.DivideWS Extends %SOAP.WebService
{Parameter SECURITYIN = "REQUIRE";/// Name of the Web service.
Parameter SERVICENAME = "TokensDemo";/// SOAP namespace for the Web service
Parameter NAMESPACE = "http://www.myapp.org";/// Divide arg1 by arg2 and return the result. In case of error, call ApplicationError.
Method Divide(arg1 As %Numeric = 2, arg2 As %Numeric = 8) As %Numeric [ WebMethod ]
{Try {Set ans=arg1 / arg2}Catch{Do ..ApplicationError("division error")}Quit ans
}/// Create our own method to produce application specific SOAP faults.
Method ApplicationError(detail As %String)
{//details not shown here
}}
以下客户端类调用代理客户端(此处未显示)并添加用户名令牌:
Include %systemIncludeClass TokensClient.UseClient
{ClassMethod Test() As %Numeric
{Set client=##class(TokensClient.TokensDemoSoap).%New()Do ..AddSecElements(.client)Set ans=client.Divide(1,2)Quit ans
}ClassMethod AddSecElements(ByRef client As %SOAP.WebClient)
{Set utoken=##class(%SOAP.Security.UsernameToken).Create("_SYSTEM","SYS")Do client.SecurityOut.AddSecurityElement(utoken)Set ts=##class(%SOAP.Security.Timestamp).Create()Do client.SecurityOut.AddSecurityElement(ts) Quit
}}
来自该客户端的示例消息如下:
<?xml version="1.0" encoding="UTF-8" ?>
<SOAP-ENV:Envelope [parts omitted]><SOAP-ENV:Header><Security xmlns="[parts omitted]oasis-200401-wss-wssecurity-secext-1.0.xsd"><Timestamp xmlns="[parts omitted]oasis-200401-wss-wssecurity-utility-1.0.xsd"><Created>2010-03-12T20:18:03Z</Created><Expires>2010-03-12T20:23:03Z</Expires></Timestamp><UsernameToken><Username>_SYSTEM</Username><Password Type="[parts omitted]#PasswordText">SYS</Password></UsernameToken></Security></SOAP-ENV:Header><SOAP-ENV:Body>[omitted]</SOAP-ENV:Body>
</SOAP-ENV:Envelope>