【问题标题】:Custom SecurityTokenHandler for WIFWIF 的自定义 SecurityTokenHandler
【发布时间】:2011-08-03 01:26:39
【问题描述】:

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

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

到目前为止,它工作得很好,但我被困在 SecurityTokenHandler.CreateSecurityTokenReference(SecurityToken token, bool attached) 上,它应该返回一个 SecurityKeyIndetifierClause

我的问题是:什么是 SecurityKeySecurityKeyIndentifierSecurityKeyIndentifierClause,具体来说是什么?

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

提前致谢。

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

【问题讨论】:

    标签: c# .net wif sts-securitytokenservice


    【解决方案1】:

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

    安全密钥

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

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

    SecurityKeyIdentifierClause

    正如另一个答案已经指出的那样,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 中的实现。通常不需要您自己处理。

    【讨论】:

      【解决方案2】:

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

      • 从 CanWriteKeyIdentifierClause 返回 false:

        public override bool CanWriteKeyIdentifierClause(SecurityKeyIdentifierClause securityKeyIdentifierClause) { 返回假; }

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

        public override SecurityKeyIdentifierClause CreateSecurityTokenReference(SecurityToken token, bool attach) { 返回默认值(SecurityKeyIdentifierClause); }

      【讨论】:

        猜你喜欢
        • 2012-10-05
        • 1970-01-01
        • 2013-05-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-12-16
        • 1970-01-01
        • 2012-11-20
        相关资源
        最近更新 更多