/// <summary>
        ///     Executes the transform.
        /// </summary>
        /// <param name="claimSet">Set of claims to apply the transform.</param>
        /// <param name="sourceClaim">The claim to remove.</param>
        /// <param name="targetClaim">This claim is ignored in the remove transform action.</param>
        /// <returns>Transformed set of claims.</returns>
        public override IEnumerable <Claim> Execute(IEnumerable <Claim> claims, IList <Claim> matchedClaims,
                                                    LiteralClaim targetClaim)
        {
            _ = claims ?? throw new ArgumentNullException(nameof(claims));
            _ = matchedClaims ?? throw new ArgumentNullException(nameof(matchedClaims));

            if (targetClaim != null)
            {
                throw new ArgumentException("The expected value of targetClaim is null.");
            }

            ClaimsIdentity      ci       = new ClaimsIdentity(claims);
            IEnumerable <Claim> claimSet = ci.FindAll(delegate(Claim claim) {
                foreach (Claim c in matchedClaims)
                {
                    if (c.Type == claim.Type && c.Value == claim.Value)
                    {
                        return(true);
                    }
                }

                return(false);
            });

            List <Claim> claimList = new List <Claim>();

            foreach (Claim claim in claimSet)
            {
                claimList.Remove(claim);
            }

            return(claimList.ToArray());
        }
Exemple #2
0
        /// <summary>
        ///     Executes the add transform action.
        /// </summary>
        /// <param name="claimSet">Set of claims to perform the action.</param>
        /// <param name="sourceClaim">The source claims, which is ignored for the add transform action.</param>
        /// <param name="targetClaim">The target claim to be added with this action.</param>
        /// <returns>A transformed set of claims.</returns>
        public override IEnumerable <Claim> Execute(IEnumerable <Claim> claims, IList <Claim> matchedClaims,
                                                    LiteralClaim targetClaim)
        {
            _ = claims ?? throw new ArgumentNullException(nameof(claims));
            _ = matchedClaims ?? throw new ArgumentNullException(nameof(matchedClaims));
            _ = targetClaim ?? throw new ArgumentNullException(nameof(targetClaim));

            List <Claim> claimList = new List <Claim>(claims);

            Claim claim = new Claim(targetClaim.ClaimType, targetClaim.ClaimValue);

            claimList.Add(claim);

            return(claimList.ToArray());
        }
Exemple #3
0
        /// <summary>
        ///     Executes the replacement transform.
        /// </summary>
        /// <param name="claimSet">The set of claims to perform the action.</param>
        /// <param name="sourceClaim">The claim to be replaced.</param>
        /// <param name="targetClaim">The claim to replace the source claim.</param>
        /// <returns>Transformed set of claims.</returns>
        public override IEnumerable <Claim> Execute(IEnumerable <Claim> claims, IList <Claim> matchedClaims,
                                                    LiteralClaim targetClaim)
        {
            _ = claims ?? throw new ArgumentNullException(nameof(claims));
            _ = matchedClaims ?? throw new ArgumentNullException(nameof(matchedClaims));
            _ = targetClaim ?? throw new ArgumentNullException(nameof(targetClaim));

            ClaimsIdentity      ci       = new ClaimsIdentity(claims);
            IEnumerable <Claim> claimSet = ci.FindAll(delegate(Claim claim) {
                foreach (Claim c in matchedClaims)
                {
                    if (c.Type == claim.Type && c.Value == claim.Value)
                    {
                        return(true);
                    }
                }

                return(false);
            });

            List <Claim>  claimList = new List <Claim>(claimSet);
            List <string> valueList = new List <string>();

            foreach (Claim claim in claimSet)
            {
                valueList.Add(claim.Value);
                claimList.Remove(claim);
            }

            if (claimList.Count > 0)
            {
                if (targetClaim.ClaimValue == null)
                {
                    int index = 0;
                    while (index < valueList.Count)
                    {
                        claimList.Add(new Claim(targetClaim.ClaimType, valueList[index]));
                        index++;
                    }
                }
                else
                {
                    claimList.Add(new Claim(targetClaim.ClaimType, targetClaim.ClaimValue));
                }
            }

            return(claimList.ToArray());
        }
Exemple #4
0
 /// <summary>
 ///     Executes a transform.
 /// </summary>
 /// <param name="claimSet">A set of claims to transform.</param>
 /// <param name="sourceClaim">The source claim used in matching.</param>
 /// <param name="targetClaim">The resultant claim used in the transform.</param>
 /// <returns>Transformed set of claims.</returns>
 public abstract IEnumerable <Claim> Execute(IEnumerable <Claim> claims, IList <Claim> matchedClaims,
                                             LiteralClaim targetClaim);
        /// <summary>
        /// Executes the add transform action.
        /// </summary>
        /// <param name="claimSet">Set of claims to perform the action.</param>
        /// <param name="sourceClaim">The source claims, which is ignored for the add transform action.</param>
        /// <param name="targetClaim">The target claim to be added with this action.</param>
        /// <returns>A transformed set of claims.</returns>
        public override IEnumerable <Claim> Execute(IEnumerable <Claim> claims, IList <Claim> matchedClaims, LiteralClaim targetClaim)
        {
            if (claims == null)
            {
                throw new ArgumentNullException("claims");
            }

            if (targetClaim == null)
            {
                throw new ArgumentNullException("targetClaim");
            }

            if (matchedClaims != null)
            {
                throw new ArgumentException("The expected value of matchedClaims must be null.");
            }

            List <Claim> claimList = new List <Claim>(claims);

            Claim claim = new Claim(targetClaim.ClaimType, targetClaim.ClaimValue);

            claimList.Add(claim);

            return(claimList.ToArray());
        }
Exemple #6
0
        protected override void ProcessRecord()
        {
            LiteralClaim literalClaim = new LiteralClaim(ClaimType, ClaimValue);

            WriteObject(literalClaim);
        }