Пример #1
0
        public ControlSettings Deserialize(NameValueCollection queryString)
        {
            var settings = new ControlSettings();

            if (queryString == null)
            {
                return(settings);
            }

            var actualSettings = queryString.AllKeys.Where(IsControlSetting);

            foreach (var setting in actualSettings)
            {
                var property = UriParameters[setting];
                var value    = queryString[setting];
                if (_isEncrypted)
                {
                    value = SecurityUtil.Decrypt(value);
                }

                DeserializeValue(settings, property, value);
            }

            return(settings);
        }
        private static bool CheckEncryption(ref NameValueCollection source)
        {
            bool isEncrypted;
            var  encryptParametesConfig = ConfigurationManager.AppSettings[WebConfigSettings.EncryptParameters];

            if (!bool.TryParse(encryptParametesConfig, out isEncrypted))
            {
                isEncrypted = false;
            }

            // each parameter is encrypted when POST method is used
            if (string.Compare(HttpContext.Current.Request.HttpMethod, "POST", true) == 0)
            {
                return(isEncrypted);
            }

            if (!isEncrypted)
            {
                return(isEncrypted);
            }

            var encrypted = source[UriParameters.Encrypted];
            var decrypted = SecurityUtil.Decrypt(encrypted);

            isEncrypted = false;
            source      = HttpUtility.ParseQueryString(decrypted);
            return(isEncrypted);
        }
Пример #3
0
        private static bool CheckEncryption(ref NameValueCollection source)
        {
            var isEncrypted = Config.EncryptParameters;

            // each parameter is encrypted when POST method is used
            if (string.Compare(HttpContext.Current.Request.HttpMethod, "POST", StringComparison.OrdinalIgnoreCase) == 0)
            {
                return(isEncrypted);
            }

            if (!isEncrypted)
            {
                return(false);
            }

            var encrypted = source[UriParameters.Encrypted];
            var decrypted = SecurityUtil.Decrypt(encrypted);

            source = HttpUtility.ParseQueryString(decrypted);
            return(false);                                       // Return false here because we have already decrypted query string
        }
        public ReportViewerParameters Parse(NameValueCollection queryString)
        {
            if (queryString == null)
            {
                throw new ArgumentNullException("queryString");
            }

            var isEncrypted = CheckEncryption(ref queryString);

            var settinsManager = new ControlSettingsManager(isEncrypted);

            var parameters = InitializeDefaults();

            ResetDefaultCredentials(queryString, parameters);
            parameters.ControlSettings = settinsManager.Deserialize(queryString);

            foreach (var key in queryString.AllKeys)
            {
                var urlParam = queryString[key];
                if (key.EqualsIgnoreCase(UriParameters.ReportPath))
                {
                    parameters.ReportPath = isEncrypted ? SecurityUtil.Decrypt(urlParam) : urlParam;
                }
                else if (key.EqualsIgnoreCase(UriParameters.ControlId))
                {
                    var parameter = isEncrypted ? SecurityUtil.Decrypt(urlParam) : urlParam;
                    parameters.ControlId = Guid.Parse(parameter);
                }
                else if (key.EqualsIgnoreCase(UriParameters.ProcessingMode))
                {
                    var parameter = isEncrypted ? SecurityUtil.Decrypt(urlParam) : urlParam;
                    parameters.ProcessingMode = (ProcessingMode)Enum.Parse(typeof(ProcessingMode), parameter);
                }
                else if (key.EqualsIgnoreCase(UriParameters.ReportServerUrl))
                {
                    parameters.ReportServerUrl = isEncrypted ? SecurityUtil.Decrypt(urlParam) : urlParam;
                }
                else if (key.EqualsIgnoreCase(UriParameters.Username))
                {
                    parameters.Username = isEncrypted ? SecurityUtil.Decrypt(urlParam) : urlParam;
                }
                else if (key.EqualsIgnoreCase(UriParameters.Password))
                {
                    parameters.Password = isEncrypted ? SecurityUtil.Decrypt(urlParam) : urlParam;
                }
                else if (!settinsManager.IsControlSetting(key))
                {
                    var values = queryString.GetValues(key);
                    if (values != null)
                    {
                        foreach (var value in values)
                        {
                            var realValue = isEncrypted ? SecurityUtil.Decrypt(value) : value;
                            var parsedKey = ParseKey(key);
                            var realKey   = parsedKey.Item1;
                            var isVisible = parsedKey.Item2;

                            if (parameters.ReportParameters.ContainsKey(realKey))
                            {
                                parameters.ReportParameters[realKey].Values.Add(realValue);
                            }
                            else
                            {
                                var reportParameter = new ReportParameter(realKey);
                                reportParameter.Visible = isVisible;
                                reportParameter.Values.Add(realValue);
                                parameters.ReportParameters.Add(realKey, reportParameter);
                            }
                        }
                    }
                }
            }

            if (parameters.ProcessingMode == ProcessingMode.Remote &&
                string.IsNullOrEmpty(parameters.ReportServerUrl))
            {
                throw new MvcReportViewerException("Report Server is not specified.");
            }

            if (string.IsNullOrEmpty(parameters.ReportPath))
            {
                throw new MvcReportViewerException("Report is not specified.");
            }

            return(parameters);
        }
Пример #5
0
        public ReportViewerParameters Parse(NameValueCollection queryString)
        {
            if (queryString == null)
            {
                throw new ArgumentNullException("queryString");
            }

            var isEncrypted = CheckEncryption(ref queryString);

            var settinsManager = new ControlSettingsManager(isEncrypted);

            var parameters = InitializeDefaults();

            ResetDefaultCredentials(queryString, parameters);
            parameters.ControlSettings = settinsManager.Deserialize(queryString);

            foreach (var key in queryString.AllKeys)
            {
                var urlParam = queryString[key];
                if (key.EqualsIgnoreCase(UriParameters.ReportPath))
                {
                    parameters.ReportPath = isEncrypted ? SecurityUtil.Decrypt(urlParam) : urlParam;
                }
                else if (key.EqualsIgnoreCase(UriParameters.ReportServerUrl))
                {
                    parameters.ReportServerUrl = isEncrypted ? SecurityUtil.Decrypt(urlParam) : urlParam;
                }
                else if (key.EqualsIgnoreCase(UriParameters.Username))
                {
                    parameters.Username = isEncrypted ? SecurityUtil.Decrypt(urlParam) : urlParam;
                }
                else if (key.EqualsIgnoreCase(UriParameters.Password))
                {
                    parameters.Password = isEncrypted ? SecurityUtil.Decrypt(urlParam) : urlParam;
                }
                else if (key.EqualsIgnoreCase(UriParameters.Local))
                {
                    var  isLocalStringValue = isEncrypted ? SecurityUtil.Decrypt(urlParam) : urlParam;
                    bool isLocalValue;
                    if (Boolean.TryParse(isLocalStringValue, out isLocalValue))
                    {
                        parameters.IsLocal = isLocalValue;
                    }
                }
                else if (!settinsManager.IsControlSetting(key))
                {
                    var values = queryString.GetValues(key);
                    if (values != null)
                    {
                        foreach (var value in values)
                        {
                            var realValue = isEncrypted ? SecurityUtil.Decrypt(value) : value;

                            if (parameters.ReportParameters.ContainsKey(key))
                            {
                                parameters.ReportParameters[key].Values.Add(realValue);
                            }
                            else
                            {
                                var reportParameter = new ReportParameter(key);
                                reportParameter.Values.Add(realValue);
                                parameters.ReportParameters.Add(key, reportParameter);
                            }
                        }
                    }
                }
            }

            if (string.IsNullOrEmpty(parameters.ReportServerUrl))
            {
                throw new MvcReportViewerException("Report Server is not specified.");
            }

            if (string.IsNullOrEmpty(parameters.ReportPath))
            {
                throw new MvcReportViewerException("Report is not specified.");
            }

            return(parameters);
        }