美文网首页
第十章 创建和使用策略 - 在运行时添加证书

第十章 创建和使用策略 - 在运行时添加证书

作者: Cache技术分享 | 来源:发表于2024-08-28 09:04 被阅读0次

第十章 创建和使用策略 - 在运行时添加证书

在运行时添加证书

如果 Web 服务或客户端必须以编程方式选择并包含证书,请使用以下过程:

  1. 检索 %SYS.X509Credentials 的实例,如以编程方式检索凭据集中所述。

例如:

 set credset=##class(%SYS.X509Credentials).GetByAlias(alias,password)

 set credset=..SecurityIn.Signature.X509Credentials 
  1. 创建 %SOAP.Security.BinarySecurityToken 实例,其中包含来自该凭证集的证书。例如:
 set bst=##class(%SOAP.Security.BinarySecurityToken).CreateX509Token(credset)

其中 credentials 是在上一步中检索到的凭证集。

这将返回一个代表 <BinarySecurityToken> 元素的对象,该元素以序列化的 base-64 编码形式携带证书。

  1. 调用Web 客户端或 Web 服务的 SecurityOut 属性的 AddSecurityElement() 方法。对于方法参数,请使用之前创建的二进制安全令牌。例如:
 do ..SecurityOut.AddSecurityElement(bst)

重要提示:在某些情况下,需要两个二进制安全令牌:一个用于加密,一个用于签名。请确保按适当的顺序添加它们。如果策略先加密消息然后对其进行签名,请确保先添加用于加密的二进制安全令牌,然后再添加用于签名的令牌。相反,如果策略先签名然后加密,则第一个二进制安全令牌必须是用于签名的令牌。

下面显示了 Web 服务中的 Web 方法的示例:

 //get credentials
 set x509alias = "something"
 set pwd = "password"
 set credset = ##class(%SYS.X509Credentials).GetByAlias(x509alias,pwd)

 //get certificate and add it as binary security token
 set cert = ##class(%SOAP.Security.BinarySecurityToken).CreateX509Token(credset)
 do ..SecurityOut.AddSecurityElement(cert)

对于 Web 客户端,代码会略有不同,因为通常不会编辑代理客户端:

 set client=##class(proxyclient.classname).%New()
 //get credentials
 set x509alias = "something"
 set pwd = "password"
 set credset = ##class(%SYS.X509Credentials).GetByAlias(x509alias,pwd)

 //get certificate and add it as binary security token
 set cert = ##class(%SOAP.Security.BinarySecurityToken).CreateX509Token(credset)
 do client.SecurityOut.AddSecurityElement(cert)
 //invoke web method of client

相关文章

  • 为什么说OC是一门动态语言?

    自己理解:OC语言是在运行时才确定类型的,通过Runtime运行时机制,在运行时动态的添加变量,方法,类等,所以说...

  • 策略模式

    改接口匹配的对象实现策略更改 一个类的行为或其他算法可以在运行时更改。使用switch...case或者if......

  • 读《Design Patterns by Tutorials》笔

    策略模式定义了一系列可交换的对象,这些对象可以在运行时设置或者切换。这个模式有三部分。 使用策略的对象:在 iOS...

  • 策略模式

    1.策略模式概念 策略模式(Strategy Pattern),实现一个类的行为或其算法可以在运行时更改。策略模式...

  • python设计模式(二十二):策略模式

    策略模式,让一个类的行为或其算法可以在运行时更改,策略是让实例化对象动态的更改自身的某些方法使用的是types.M...

  • retrofit 添加SSL证书校验

    使用https时添加证书防止捉包 读取ssl证书 添加到retrofit中方

  • Typescript策略模式

    这次写写策略模式(Strategy Pattern),先看定义: 策略模式是一种行为设计模式;可以在运行时根据不同...

  • 神奇的runtime

    (1)在运行时对函数进行动态替换 : class_replaceMethod 使用该函数可以在运行时动态替换某个类...

  • Strategy

    策略模式 针对同一任务有多个不同的实现,在运行时,选择一种特定的算法实现。 特征 有多个算法实现 在运行时,针对不...

  • c++策略模式

    1.策略模式简介    在策略模式(Strategy Pattern)中,一个类的行为或其算法可以在运行时更改。 ...

网友评论

      本文标题:第十章 创建和使用策略 - 在运行时添加证书

      本文链接:https://www.haomeiwen.com/subject/toxtljtx.html