如何在WIF 4.5中处理ActAs令牌?

时间:2013-01-30 19:06:55

标签: c# wif ws-trust

我正在使用.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 key)      at System.IdentityModel.Tokens.SecurityTokenHandlerCollectionManager.get_Item(String usage)

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

我如何处理ActAs令牌?

1 个答案:

答案 0 :(得分: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();