| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Globalization; |
| | | 6 | | |
| | | 7 | | namespace CoreWCF.IdentityModel.Tokens |
| | | 8 | | { |
| | | 9 | | public class LocalIdKeyIdentifierClause : SecurityKeyIdentifierClause |
| | | 10 | | { |
| | | 11 | | private readonly Type[] _ownerTypes; |
| | | 12 | | |
| | | 13 | | public LocalIdKeyIdentifierClause(string localId) |
| | 0 | 14 | | : this(localId, (Type[])null) |
| | | 15 | | { |
| | 0 | 16 | | } |
| | | 17 | | |
| | | 18 | | public LocalIdKeyIdentifierClause(string localId, Type ownerType) |
| | 10 | 19 | | : this(localId, ownerType == null ? (Type[])null : new Type[] { ownerType }) |
| | | 20 | | { |
| | 10 | 21 | | } |
| | | 22 | | |
| | | 23 | | public LocalIdKeyIdentifierClause(string localId, byte[] derivationNonce, int derivationLength, Type ownerType) |
| | 0 | 24 | | : this(null, derivationNonce, derivationLength, ownerType == null ? (Type[])null : new Type[] { ownerType }) |
| | | 25 | | { |
| | 0 | 26 | | } |
| | | 27 | | |
| | | 28 | | internal LocalIdKeyIdentifierClause(string localId, Type[] ownerTypes) |
| | 10 | 29 | | : this(localId, null, 0, ownerTypes) |
| | | 30 | | { |
| | 10 | 31 | | } |
| | | 32 | | |
| | | 33 | | internal LocalIdKeyIdentifierClause(string localId, byte[] derivationNonce, int derivationLength, Type[] ownerTy |
| | 33 | 34 | | : base(null, derivationNonce, derivationLength) |
| | | 35 | | { |
| | 33 | 36 | | if (localId == null) |
| | | 37 | | { |
| | 0 | 38 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(localId)); |
| | | 39 | | } |
| | 33 | 40 | | if (localId == string.Empty) |
| | | 41 | | { |
| | 0 | 42 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.LocalIdCannotBeEmpty); |
| | | 43 | | } |
| | 33 | 44 | | LocalId = localId; |
| | 33 | 45 | | _ownerTypes = ownerTypes; |
| | 33 | 46 | | } |
| | | 47 | | |
| | 33 | 48 | | public string LocalId { get; } |
| | | 49 | | |
| | | 50 | | public Type OwnerType |
| | | 51 | | { |
| | 16 | 52 | | get { return (_ownerTypes == null || _ownerTypes.Length == 0) ? null : _ownerTypes[0]; } |
| | | 53 | | } |
| | | 54 | | |
| | | 55 | | public override bool Matches(SecurityKeyIdentifierClause keyIdentifierClause) |
| | | 56 | | { |
| | 0 | 57 | | LocalIdKeyIdentifierClause that = keyIdentifierClause as LocalIdKeyIdentifierClause; |
| | 0 | 58 | | return ReferenceEquals(this, that) || (that != null && that.Matches(LocalId, OwnerType)); |
| | | 59 | | } |
| | | 60 | | |
| | | 61 | | public bool Matches(string localId, Type ownerType) |
| | | 62 | | { |
| | 23 | 63 | | if (string.IsNullOrEmpty(localId)) |
| | | 64 | | { |
| | 0 | 65 | | return false; |
| | | 66 | | } |
| | | 67 | | |
| | 23 | 68 | | if (LocalId != localId) |
| | | 69 | | { |
| | 0 | 70 | | return false; |
| | | 71 | | } |
| | | 72 | | |
| | 23 | 73 | | if (_ownerTypes == null || ownerType == null) |
| | | 74 | | { |
| | 4 | 75 | | return true; |
| | | 76 | | } |
| | | 77 | | |
| | 38 | 78 | | for (int i = 0; i < _ownerTypes.Length; ++i) |
| | | 79 | | { |
| | 19 | 80 | | if (_ownerTypes[i] == null || _ownerTypes[i] == ownerType) |
| | | 81 | | { |
| | 19 | 82 | | return true; |
| | | 83 | | } |
| | | 84 | | } |
| | 0 | 85 | | return false; |
| | | 86 | | } |
| | | 87 | | |
| | | 88 | | public override string ToString() |
| | | 89 | | { |
| | 0 | 90 | | return string.Format(CultureInfo.InvariantCulture, "LocalIdKeyIdentifierClause(LocalId = '{0}', Owner = '{1} |
| | | 91 | | } |
| | | 92 | | } |
| | | 93 | | } |