我正在使用.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令牌?

最佳答案

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();

关于c# - 如何在WIF 4.5中处理ActAs token ?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14611773/

10-11 02:12