예제 #1
0
 private void ValidateMapClaimAddReplace(List <ValidationResult> results)
 {
     if (ClaimsIn?.Count() != 1)
     {
         results.Add(new ValidationResult($"Exactly one is required in the field {nameof(ClaimsIn)} for claim transformation type '{Type}'.", new[] { nameof(ClaimsIn) }));
     }
 }
예제 #2
0
 private void ValidateMatchAddReplace(List <ValidationResult> results)
 {
     if (ClaimsIn?.Count() != 1)
     {
         results.Add(new ValidationResult($"Exactly one is required in the field {nameof(ClaimsIn)} for claim transformation type '{Type}'.", new[] { nameof(ClaimsIn) }));
     }
     if (Transformation.IsNullOrWhiteSpace())
     {
         results.Add(new ValidationResult($"The field {nameof(Transformation)} is required for claim transformation type '{Type}'.", new[] { nameof(Transformation) }));
     }
     if (TransformationExtension.IsNullOrWhiteSpace())
     {
         results.Add(new ValidationResult($"The field {nameof(TransformationExtension)} is required for claim transformation type '{Type}'.", new[] { nameof(TransformationExtension) }));
     }
 }
예제 #3
0
        public virtual IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var results = new List <ValidationResult>();

            if (Action == ClaimTransformActions.Add || Action == ClaimTransformActions.Replace)
            {
                switch (Type)
                {
                case ClaimTransformTypes.Constant:
                    if (Transformation.IsNullOrWhiteSpace())
                    {
                        results.Add(new ValidationResult($"The field {nameof(Transformation)} is required for claim transformation type '{Type}'.", new[] { nameof(Transformation) }));
                    }
                    break;

                case ClaimTransformTypes.MatchClaim:
                    ValidateMatchClaimAddReplace(results);
                    break;

                case ClaimTransformTypes.Match:
                case ClaimTransformTypes.RegexMatch:
                    ValidateMatchAddReplace(results);
                    break;

                case ClaimTransformTypes.Map:
                    ValidateMapClaimAddReplace(results);
                    break;

                case ClaimTransformTypes.RegexMap:
                    ValidateRegexMapClaimAddReplace(results);
                    break;

                case ClaimTransformTypes.Concatenate:
                    if (ClaimsIn?.Count() < 1)
                    {
                        results.Add(new ValidationResult($"At least one is required in the field {nameof(ClaimsIn)} for claim transformation type '{Type}'.", new[] { nameof(ClaimsIn) }));
                    }
                    if (Transformation.IsNullOrWhiteSpace())
                    {
                        results.Add(new ValidationResult($"The field {nameof(Transformation)} is required for claim transformation type '{Type}'.", new[] { nameof(Transformation) }));
                    }
                    break;

                default:
                    throw new NotSupportedException($"Claim transformation type '{Type}' not supported.");
                }
            }
            else if (Action == ClaimTransformActions.AddIfNot || Action == ClaimTransformActions.ReplaceIfNot)
            {
                switch (Type)
                {
                case ClaimTransformTypes.MatchClaim:
                    ValidateMatchClaimAddReplace(results);
                    break;

                case ClaimTransformTypes.Match:
                case ClaimTransformTypes.RegexMatch:
                    ValidateMatchAddReplace(results);
                    break;

                default:
                    throw new NotSupportedException($"Claim transformation type '{Type}' not supported.");
                }
            }
            else if (Action == ClaimTransformActions.AddIfNotOut)
            {
                switch (Type)
                {
                case ClaimTransformTypes.Map:
                    ValidateMapClaimAddReplace(results);
                    break;

                case ClaimTransformTypes.RegexMap:
                    ValidateRegexMapClaimAddReplace(results);
                    break;

                default:
                    throw new NotSupportedException($"Claim transformation type '{Type}' not supported.");
                }
            }
            else if (Action == ClaimTransformActions.Remove)
            {
                switch (Type)
                {
                case ClaimTransformTypes.MatchClaim:
                    break;

                case ClaimTransformTypes.Match:
                case ClaimTransformTypes.RegexMatch:
                    if (Transformation.IsNullOrWhiteSpace())
                    {
                        results.Add(new ValidationResult($"The field {nameof(Transformation)} is required for claim transformation type '{Type}'.", new[] { nameof(Transformation) }));
                    }
                    break;

                default:
                    throw new NotSupportedException($"Claim transformation type '{Type}' not supported.");
                }
            }
            return(results);
        }
예제 #4
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var results = new List <ValidationResult>();

            switch (Type)
            {
            case ClaimTransformTypes.Constant:
                if (ClaimsIn?.Count() > 0)
                {
                    results.Add(new ValidationResult($"The field {nameof(ClaimsIn)} can not be used with claim transformation type '{Type}'.", new[] { nameof(ClaimsIn) }));
                }
                if (Transformation.IsNullOrWhiteSpace())
                {
                    results.Add(new ValidationResult($"The field {nameof(Transformation)} is required for claim transformation type '{Type}'.", new[] { nameof(Transformation) }));
                }
                break;

            case ClaimTransformTypes.Match:
            case ClaimTransformTypes.RegexMatch:
                if (ClaimsIn?.Count() != 1)
                {
                    results.Add(new ValidationResult($"Exactly one is required in the field {nameof(ClaimsIn)} for claim transformation type '{Type}'.", new[] { nameof(ClaimsIn) }));
                }
                if (Transformation.IsNullOrWhiteSpace())
                {
                    results.Add(new ValidationResult($"The field {nameof(Transformation)} is required for claim transformation type '{Type}'.", new[] { nameof(Transformation) }));
                }
                if (TransformationExtension.IsNullOrWhiteSpace())
                {
                    results.Add(new ValidationResult($"The field {nameof(TransformationExtension)} is required for claim transformation type '{Type}'.", new[] { nameof(TransformationExtension) }));
                }
                break;

            case ClaimTransformTypes.Map:
                if (ClaimsIn?.Count() != 1)
                {
                    results.Add(new ValidationResult($"Exactly one is required in the field {nameof(ClaimsIn)} for claim transformation type '{Type}'.", new[] { nameof(ClaimsIn) }));
                }
                break;

            case ClaimTransformTypes.RegexMap:
                if (ClaimsIn?.Count() != 1)
                {
                    results.Add(new ValidationResult($"Exactly one is required in the field {nameof(ClaimsIn)} for claim transformation type '{Type}'.", new[] { nameof(ClaimsIn) }));
                }
                if (Transformation.IsNullOrWhiteSpace())
                {
                    results.Add(new ValidationResult($"The field {nameof(Transformation)} is required for claim transformation type '{Type}'.", new[] { nameof(Transformation) }));
                }
                break;

            case ClaimTransformTypes.Concatenate:
                if (ClaimsIn?.Count() < 1)
                {
                    results.Add(new ValidationResult($"At least one is required in the field {nameof(ClaimsIn)} for claim transformation type '{Type}'.", new[] { nameof(ClaimsIn) }));
                }
                if (Transformation.IsNullOrWhiteSpace())
                {
                    results.Add(new ValidationResult($"The field {nameof(Transformation)} is required for claim transformation type '{Type}'.", new[] { nameof(Transformation) }));
                }
                break;

            default:
                throw new NotSupportedException($"Claim transformation type '{Type}' not supported.");
            }
            return(results);
        }