Ejemplo n.º 1
0
        public SecureChannelMessage <string> Invoke(string className, string methodName, string jsonParams)
        {
            SecureChannelMessage <string> result = new SecureChannelMessage <string>();

            HttpArgs args = new HttpArgs();

            args.ParseJson(jsonParams);
            string parameters = args["jsonParams"];
            SecureExecutionRequest request = new SecureExecutionRequest(HttpContext, className, methodName, parameters)
            {
                ApiKeyResolver  = ApiKeyResolver,
                ServiceProvider = ServiceProvider
            };
            bool success = request.Execute();

            string data = request.Result as string;

            if (string.IsNullOrEmpty(data))
            {
                throw new SecureChannelInvokeException(className, methodName, jsonParams);
            }
            result.Data    = data;
            result.Success = success;

            return(result);
        }
Ejemplo n.º 2
0
        public static SecureExecutionRequest Create <T>(IHttpContext context, string methodName, Incubator serviceProvider, params object[] parameters)
        {
            string jsonParams = ApiParameters.ParametersToJsonParamsArray(parameters).ToJson();
            SecureExecutionRequest request = new SecureExecutionRequest(context, typeof(T).Name, methodName, jsonParams);

            request.ServiceProvider = serviceProvider;
            return(request);
        }
Ejemplo n.º 3
0
        public SecureChannelMessage <string> Invoke(string className, string methodName, string jsonParams)
        {
            SecureChannelMessage <string> result = new SecureChannelMessage <string>();

            HttpArgs args = new HttpArgs();

            args.ParseJson(jsonParams);
            string parameters = args["jsonParams"];
            SecureExecutionRequest request = new SecureExecutionRequest(HttpContext, className, methodName, parameters)
            {
                ApiKeyResolver  = ApiKeyResolver,
                ServiceProvider = ServiceProvider
            };
            bool success = request.Execute();

            if (request.Result is ValidationResult validationResult)
            {
                result.Data    = "validation failed";
                result.Message = validationResult.Message;
                result.Success = false;
                Logger.AddEntry("Validation failed for SecureChannel.Invoke for {0}.{1}:\r\n\tMessage={2}\r\n\tFailures: {3}:\r\n *** jsonParams were ***\r\n{4}",
                                LogEventType.Warning,
                                className,
                                methodName,
                                validationResult.Message,
                                string.Join(",", validationResult.ValidationFailures),
                                jsonParams);
            }
            else
            {
                string data = request.Result as string;
                if (string.IsNullOrEmpty(data))
                {
                    throw new SecureChannelInvokeException(className, methodName, jsonParams);
                }
                result.Data    = data;
                result.Success = success;
            }

            return(result);
        }
Ejemplo n.º 4
0
        public SecureChannelMessage <string> Invoke(string className, string methodName, string jsonParams)
        {
            SecureChannelMessage <string> result = new SecureChannelMessage <string>();

            HttpArgs args = new HttpArgs();

            args.ParseJson(jsonParams);
            string parameters = args["jsonParams"];
            SecureExecutionRequest request = new SecureExecutionRequest(HttpContext, className, methodName, parameters);

            request.ApiKeyResolver  = ApiKeyResolver;
            request.ServiceProvider = ServiceProvider;
            bool success = request.Execute();

            ValidationResult validationResult = request.Result as ValidationResult;

            if (Debug && validationResult != null)
            {
                result.Data    = "validation failed";
                result.Message = validationResult.Message;
                result.Success = false;
            }
            else
            {
                if (validationResult != null)
                {
                    Logger.AddEntry("Validation failed for SecureChannel.Invoke for {0}.{1}:\r\n *** jsonParams were ***\r\n{2}",
                                    LogEventType.Warning,
                                    className,
                                    methodName,
                                    jsonParams);
                }

                result.Data    = (string)request.Result; //this will throw an exception if validation failed causing 404 not found to be sent back which is what we want for security if debug is off
                result.Success = success;
            }

            return(result);
        }