Exemple #1
0
        // Note: null string represents any.
        public override IEnumerable <Claim> FindClaims(string claimType, string right)
        {
            ThrowIfDisposed();
            if (!SupportedClaimType(claimType) || !ClaimSet.SupportedRight(right))
            {
                yield break;
            }
            else if (_claims == null && (ClaimTypes.Sid == claimType || ClaimTypes.DenyOnlySid == claimType))
            {
                if (ClaimTypes.Sid == claimType)
                {
                    if (right == null || Rights.Identity == right)
                    {
                        yield return(new Claim(ClaimTypes.Sid, _windowsIdentity.User, Rights.Identity));
                    }
                }

                if (right == null || Rights.PossessProperty == right)
                {
                    Claim sid;
                    if (TryCreateWindowsSidClaim(_windowsIdentity, out sid))
                    {
                        if (claimType == sid.ClaimType)
                        {
                            yield return(sid);
                        }
                    }
                }

                if (_includeWindowsGroups && (right == null || Rights.PossessProperty == right))
                {
                    // Not sure yet if GroupSidClaimCollections are necessary in .NET Core, but default
                    // _includeWindowsGroups is true; don't throw here or we bust the default case on UWP/.NET Core
                }
            }
            else
            {
                EnsureClaims();

                bool anyClaimType = (claimType == null);
                bool anyRight     = (right == null);

                for (int i = 0; i < _claims.Count; ++i)
                {
                    Claim claim = _claims[i];
                    if ((claim != null) &&
                        (anyClaimType || claimType == claim.ClaimType) &&
                        (anyRight || right == claim.Right))
                    {
                        yield return(claim);
                    }
                }
            }
        }
Exemple #2
0
        protected void Initialize(ClaimSet issuer, IList <Claim> claims)
        {
            if (issuer == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(issuer));
            }
            if (claims == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(claims));
            }

            this.issuer = issuer;
            this.claims = claims;
        }
        // Note: null string represents any.
        public override IEnumerable <Claim> FindClaims(string claimType, string right)
        {
            ThrowIfDisposed();
            if (!SupportedClaimType(claimType) || !ClaimSet.SupportedRight(right))
            {
                yield break;
            }
            else if (claims == null && ClaimTypes.Thumbprint.Equals(claimType))
            {
                if (right == null || Rights.Identity.Equals(right))
                {
                    yield return(new Claim(ClaimTypes.Thumbprint, certificate.GetCertHash(), Rights.Identity));
                }
                if (right == null || Rights.PossessProperty.Equals(right))
                {
                    yield return(new Claim(ClaimTypes.Thumbprint, certificate.GetCertHash(), Rights.PossessProperty));
                }
            }
            else if (claims == null && ClaimTypes.Dns.Equals(claimType))
            {
                if (right == null || Rights.PossessProperty.Equals(right))
                {
                    foreach (var claim in GetDnsClaims(certificate))
                    {
                        yield return(claim);
                    }
                }
            }
            else
            {
                EnsureClaims();

                bool anyClaimType = (claimType == null);
                bool anyRight     = (right == null);

                for (int i = 0; i < claims.Count; ++i)
                {
                    Claim claim = claims[i];
                    if ((claim != null) &&
                        (anyClaimType || claimType.Equals(claim.ClaimType)) &&
                        (anyRight || right.Equals(claim.Right)))
                    {
                        yield return(claim);
                    }
                }
            }
        }
Exemple #4
0
 public DefaultClaimSet(ClaimSet issuer, IList <Claim> claims)
 {
     Initialize(issuer, claims);
 }
Exemple #5
0
 public DefaultClaimSet(ClaimSet issuer, params Claim[] claims)
 {
     Initialize(issuer, claims);
 }
Exemple #6
0
 protected void Initialize(ClaimSet issuer, IList <Claim> claims)
 {
     _issuer = issuer ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(issuer));
     _claims = claims ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(claims));
 }