【问题标题】:How do I handle ActAs tokens in WIF 4.5?如何在 WIF 4.5 中处理 ActAs 令牌?
【发布时间】:2013-01-30 19:06:55
【问题描述】:

我正在使用 .NET 4.5 中的 WIF (System.IdentityModel) 类创建 STS。此 STS 需要处理 ActAs 令牌。我已经成功地将客户端原型化为发送 ActAs 令牌,这会导致服务器端出现以下错误消息:

ID3265:找到 ActAs 元素,但没有注册令牌处理程序来读取 ActAs 元素。考虑将有效的 SecurityTokenHandlerCollection 添加到 SecurityTokenHanderCollectionManager 以供 ActAs 使用。

但是,我认为无法将SecurityTokenHandlerCollection 添加到SecurityTokenHanderCollectionManager。这是怎么做到的?

我已经尝试了this 文档中的建议:

<securityTokenHandlers name="ActAs">
    ...
</securityTokenHandlers>

但这会导致这个错误:

ID0005:输入“configElement.ElementInformation.Properties”集合不包含名为“ActAs”的属性。

“等效”(根据该文档)咒语,ServiceConfiguration.SecurityTokenHandlerCollectionManager["ActAs"] 同样没有帮助:

未处理的异常:System.Collections.Generic.KeyNotFoundException:字典中不存在给定的键。 在 System.Collections.Generic.Dictionary`2.get_Item(TKey 键) 在 System.IdentityModel.Tokens.SecurityTokenHandlerCollectionManager.get_Item(字符串使用)

请注意,this 文档提供的信息与 1 基本相同,但专门针对 .NET 4.5。

如何处理 ActAs 令牌?

【问题讨论】:

    标签: c# wif ws-trust


    【解决方案1】:

    SecurityTokenHandlerCollectionManager 上的索引器不是只读的:

    // Summary:
    //     Returns the security token handler collection for the specified usage.
    //
    // Parameters:
    //   usage:
    //     The usage name for the token handler collection.
    //
    // Returns:
    //     The token handler collection associated with the specified usage.
    public SecurityTokenHandlerCollection this[string usage] { get; set; }
    

    只需将给定键的SecurityTokenHandlerCollection 设置为所需的集合:

    SecurityTokenHandlerCollectionManager["ActAs"] = new SecurityTokenHandlerCollection();
    // or:
    SecurityTokenHandlerCollectionManager[SecurityTokenHandlerCollectionManager.Usage.ActAs] = new SecurityTokenHandlerCollection();
    

    【讨论】:

      猜你喜欢
      • 2012-11-10
      • 2014-10-28
      • 1970-01-01
      • 1970-01-01
      • 2021-10-06
      • 1970-01-01
      • 1970-01-01
      • 2017-08-25
      • 1970-01-01
      相关资源
      最近更新 更多