/// <summary> /// Finds a named collection of <see cref="SecurityKey"/>(s) that match the <see cref="SecurityKeyIdentifierClause"/> and returns a <see cref="NamedKeySecurityToken"/> that contains the <see cref="SecurityKey"/>(s). /// </summary> /// <param name="keyIdentifierClause">The <see cref="SecurityKeyIdentifier"/> to resolve to a <see cref="SecurityToken"/></param> /// <param name="token">The resolved <see cref="SecurityToken"/>.</param> /// <remarks>If there is no match, then <see cref="IssuerTokenResolver"/> and 'base' are called in order.</remarks> /// <returns>true if token was resolved.</returns> /// <exception cref="ArgumentNullException">if 'keyIdentifierClause' is null.</exception> protected override bool TryResolveTokenCore(SecurityKeyIdentifierClause keyIdentifierClause, out SecurityToken token) { if (keyIdentifierClause == null) { throw new ArgumentNullException("keyIdentifierClause"); } token = null; NamedKeySecurityKeyIdentifierClause namedKeyIdentifierClause = keyIdentifierClause as NamedKeySecurityKeyIdentifierClause; if (namedKeyIdentifierClause != null) { IList <SecurityKey> resolvedKeys = null; if (this.keys.TryGetValue(namedKeyIdentifierClause.Name, out resolvedKeys)) { token = new NamedKeySecurityToken(namedKeyIdentifierClause.Name, namedKeyIdentifierClause.Id, resolvedKeys); return(true); } } if (IssuerTokenResolver != null && IssuerTokenResolver.TryResolveToken(keyIdentifierClause, out token)) { return(true); } return(base.TryResolveTokenCore(keyIdentifierClause, out token)); }
/// <summary> /// Initializes a new instance of the <see cref="NamedKeyIssuerTokenResolver"/> class. /// Populates this instance with a named collection of <see cref="SecurityKey"/>(s) and an optional <see cref="SecurityTokenResolver"/> that will be called when a /// <see cref="SecurityKeyIdentifier"/> or <see cref="SecurityKeyIdentifierClause"/> cannot be resolved. /// </summary> /// <param name="keys"> /// A named collection of <see cref="SecurityKey"/>(s). /// </param> /// <param name="innerTokenResolver"> /// A <see cref="IssuerTokenResolver"/> to call when resolving fails, before calling base. /// </param> /// <remarks> /// if 'keys' is null an empty collection will be created. A named collection of <see cref="SecurityKey"/>(s) can be added by accessing the property <see cref="SecurityKeys"/>. /// </remarks> public NamedKeyIssuerTokenResolver(IDictionary<string, IList<SecurityKey>> keys = null, IssuerTokenResolver innerTokenResolver = null) { if (keys == null) { this.keys = new Dictionary<string, IList<SecurityKey>>(); } else { this.keys = keys; } this.issuerTokenResolver = innerTokenResolver; }
/// <summary> /// Initializes a new instance of the <see cref="NamedKeyIssuerTokenResolver"/> class. /// Populates this instance with a named collection of <see cref="SecurityKey"/>(s) and an optional <see cref="SecurityTokenResolver"/> that will be called when a /// <see cref="SecurityKeyIdentifier"/> or <see cref="SecurityKeyIdentifierClause"/> cannot be resolved. /// </summary> /// <param name="keys"> /// A named collection of <see cref="SecurityKey"/>(s). /// </param> /// <param name="innerTokenResolver"> /// A <see cref="IssuerTokenResolver"/> to call when resolving fails, before calling base. /// </param> /// <remarks> /// if 'keys' is null an empty collection will be created. A named collection of <see cref="SecurityKey"/>(s) can be added by accessing the property <see cref="SecurityKeys"/>. /// </remarks> public NamedKeyIssuerTokenResolver(IDictionary <string, IList <SecurityKey> > keys = null, IssuerTokenResolver innerTokenResolver = null) { if (keys == null) { this.keys = new Dictionary <string, IList <SecurityKey> >(); } else { this.keys = keys; } this.issuerTokenResolver = innerTokenResolver; }