1

我正在尝试使用 Microsoft.IndentityModel (= Windows Indentity Foundation) 为 STS实现自定义SecurityTokenSecurityTokenHandler 。

令牌被序列化为带有签名的简单 xml 文档(使用 X509 证书),并且有时(并非总是)加密(取决于目标领域)。

直到现在它工作得很好,但我被困在SecurityTokenHandler.CreateSecurityTokenReference(SecurityToken token, bool attach)上,它应该返回一个SecurityKeyIndetifierClause.

我的问题是:什么是SecurityKey,SecurityKeyIndentifierSecurityKeyIndentifierClause通常以及我的 sceanrio(rsa 签名(和加密)xml 令牌)具体是什么?

MSDN 中几乎没有文档,我也找不到任何对这个主题有帮助的东西。

提前致谢。

PS:我知道最简单和推荐的方法是使用像 saml 这样的内置令牌格式,但令牌是由旧系统评估的,该系统需要我无法影响的特定格式。

4

2 回答 2

2

与此同时,我找到了我自己的问题的答案:

安全密钥

SecurityKey 用于加密操作。不记名令牌实现不需要这。因此,您可以在SecurityToken的相应属性中返回一个空列表:

public override ReadOnlyCollection<SecurityKey> SecurityKeys
{
    get { return new List<SecurityKey>().AsReadOnly(); }
}

安全密钥标识符子句

正如另一个答案已经指出的那样,SecurityKeyIdentifierClause是一种安全令牌的唯一标识符。SecurityTokenResolver使用它来为指定的SecurityKeyIdentifierClause返回相应的SecurityToken

对于您自己的SecurityTokenHandler实现来说,最好的解决方案可能是返回一个LocalIdKeyIdentifierClause,其中您的令牌的 id 作为localId参数:

public override SecurityKeyIdentifierClause CreateSecurityTokenReference(SecurityToken token, bool attached)
{
    if (token == null)
        throw new ArgumentNullException("token");

    return new LocalIdKeyIdentifierClause(token.Id);
}

安全密钥标识符

SecurityKeyIdentifierSecurityKeyIdentifierClauses的集合。如有需要,您可以在此处使用System.IdentityModel.Tokens中的实现。通常不需要您自己处理。

于 2011-08-02T17:26:39.637 回答
0

密钥标识符与自定义令牌一起使用来做几件事。它们描述了令牌,和/或指向其他相关的令牌(因为令牌可以只是指针 - 可能是出于性能原因等)。如果您不需要密钥标识符,您可以做两件事:

  • 从 CanWriteKeyIdentifierClause 返回 false:

    公共覆盖 bool CanWriteKeyIdentifierClause(SecurityKeyIdentifierClause securityKeyIdentifierClause) { return false; }

  • 从 CreateSecurityTokenReference 返回一个默认(或空)值:

    公共覆盖 SecurityKeyIdentifierClause CreateSecurityTokenReference(SecurityToken token, bool attach) { return default(SecurityKeyIdentifierClause); }

于 2011-07-27T16:33:27.880 回答