public static SelectParameterResult TryCast(BindingData bindingData,
                                                    string key, bool checkFileName)
        {
            var parameterRequiringValidation = bindingData.parameterRequiringValidation;
            var queryResult = bindingData.fetchQueryParam(parameterRequiringValidation,
                                                          (v) =>
            {
                return(SelectParameterResult.Query(v, key, parameterRequiringValidation));
            },
                                                          (whyQuery) => SelectParameterResult.FailureQuery(whyQuery, key, parameterRequiringValidation));

            if (queryResult.valid)
            {
                return(queryResult);
            }

            if (!checkFileName)
            {
                return(queryResult);
            }

            return(bindingData.fetchDefaultParam(parameterRequiringValidation,
                                                 (v) =>
            {
                return SelectParameterResult.File(v, key, parameterRequiringValidation);
            },
                                                 (whyQuery) =>
            {
                return queryResult;
            }));
        }
Пример #2
0
        public override SelectParameterResult TryCast(BindingData bindingData)
        {
            var parameterRequiringValidation = bindingData.parameterRequiringValidation;
            var key = this.GetKey(parameterRequiringValidation);

            return(bindingData.fetchBodyParam(parameterRequiringValidation,
                                              vCasted => SelectParameterResult.Body(vCasted, key, parameterRequiringValidation),
                                              why => SelectParameterResult.FailureBody(why, key, parameterRequiringValidation)));
        }
        public virtual SelectParameterResult TryCast(BindingData bindingData)
        {
            var parameterRequiringValidation = bindingData.parameterRequiringValidation;
            var key        = GetKey(parameterRequiringValidation);
            var fileResult = bindingData.fetchDefaultParam(parameterRequiringValidation,
                                                           (v) =>
            {
                return(SelectParameterResult.File(v, key, parameterRequiringValidation));
            },
                                                           (whyQuery) => SelectParameterResult.FailureFile(
                                                               $"Could not create value in file.",
                                                               key, parameterRequiringValidation));

            if (fileResult.valid)
            {
                return(fileResult);
            }

            var queryResult = bindingData.fetchQueryParam(parameterRequiringValidation,
                                                          (v) =>
            {
                if (fileResult.valid)
                {
                    fileResult.fromQuery = true;
                    return(fileResult);
                }
                return(SelectParameterResult.Query(v, key, parameterRequiringValidation));
            },
                                                          (whyQuery) =>
            {
                if (fileResult.valid)
                {
                    return(fileResult);
                }
                return(SelectParameterResult.FailureQuery(whyQuery, key, parameterRequiringValidation));
            });

            if (queryResult.valid)
            {
                return(queryResult);
            }

            return(bindingData.fetchBodyParam(parameterRequiringValidation,
                                              (v) =>
            {
                return SelectParameterResult.Body(v, key, parameterRequiringValidation);
            },
                                              (whyQuery) =>
            {
                if (queryResult.valid)
                {
                    return queryResult;
                }
                return SelectParameterResult.FailureBody(whyQuery, key, parameterRequiringValidation);
            }));
        }
Пример #4
0
        public virtual SelectParameterResult TryCast(BindingData bindingData)
        {
            var request = bindingData.request;
            var parameterRequiringValidation = bindingData.parameterRequiringValidation;

            return(request.GetClaims(
                       (claimsEnumerable) =>
            {
                var claims = claimsEnumerable.ToArray();
                return AppSettings.ActorIdClaimType.ConfigurationString(
                    (accountIdClaimType) =>
                {
                    return claims
                    .First <Claim, SelectParameterResult>(
                        (claim, next) =>
                    {
                        if (String.Compare(claim.Type, accountIdClaimType) == 0)
                        {
                            var accountId = Guid.Parse(claim.Value);
                            if (parameterRequiringValidation.ParameterType.IsSubClassOfGeneric(typeof(IRef <>)))
                            {
                                var instantiatableRefType = typeof(Ref <>)
                                                            .MakeGenericType(parameterRequiringValidation.ParameterType.GenericTypeArguments);
                                var refInstance = Activator.CreateInstance(instantiatableRefType,
                                                                           new object[] { accountId });
                                return SelectParameterResult.Header(refInstance, "Authentication", parameterRequiringValidation);
                            }
                            return SelectParameterResult.FailureHeader(
                                $"Inform server developer type `{parameterRequiringValidation.ParameterType.FullName}` is not a valid Authorization result.",
                                "Authentication", parameterRequiringValidation);
                        }
                        return next();
                    },
                        () =>
                    {
                        return SelectParameterResult.FailureHeader("Account is not set in token",
                                                                   "Authentication", parameterRequiringValidation);
                    });
                },
                    (why) => SelectParameterResult.FailureHeader(why, "Authentication", parameterRequiringValidation));
            },
                       () => SelectParameterResult.FailureHeader("Authentication header not set.",
                                                                 "Authentication", parameterRequiringValidation),
                       (why) => SelectParameterResult.FailureHeader(why, "Authentication", parameterRequiringValidation)));
        }