Exemplo n.º 1
0
        public static RequestValidationResult ResolveQueueRequestByLocalConfig(
            string targetUrl, string queueitToken, QueueEventConfig queueConfig,
            string customerId, string secretKey)
        {
            var debugEntries         = new Dictionary <string, string>();
            var connectorDiagnostics = ConnectorDiagnostics.Verify(customerId, secretKey, queueitToken);

            if (connectorDiagnostics.HasError)
            {
                return(connectorDiagnostics.ValidationResult);
            }

            try
            {
                targetUrl = GenerateTargetUrl(targetUrl);
                return(ResolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, secretKey, debugEntries, connectorDiagnostics.IsEnabled));
            }
            catch (Exception e)
            {
                if (connectorDiagnostics.IsEnabled)
                {
                    debugEntries["Exception"] = e.Message;
                }
                throw;
            }
            finally
            {
                SetDebugCookie(debugEntries);
            }
        }
Exemplo n.º 2
0
        internal static ConnectorDiagnostics Verify(string customerId, string secretKey, string queueitToken)
        {
            var diagnostics = new ConnectorDiagnostics();

            var qParams = QueueParameterHelper.ExtractQueueParams(queueitToken);

            if (qParams == null)
            {
                return(diagnostics);
            }

            if (qParams.RedirectType == null)
            {
                return(diagnostics);
            }

            if (!string.Equals(qParams.RedirectType, "debug", StringComparison.OrdinalIgnoreCase))
            {
                return(diagnostics);
            }

            if (string.IsNullOrEmpty(customerId) || string.IsNullOrEmpty(secretKey))
            {
                diagnostics.SetStateWithSetupError();
                return(diagnostics);
            }

            if (HashHelper.GenerateSHA256Hash(secretKey, qParams.QueueITTokenWithoutHash) != qParams.HashCode)
            {
                diagnostics.SetStateWithTokenError(customerId, "hash");
                return(diagnostics);
            }

            if (qParams.TimeStamp < DateTime.UtcNow)
            {
                diagnostics.SetStateWithTokenError(customerId, "timestamp");
                return(diagnostics);
            }

            diagnostics.IsEnabled = true;

            return(diagnostics);
        }
Exemplo n.º 3
0
        public static RequestValidationResult ValidateRequestByIntegrationConfig(
            string currentUrlWithoutQueueITToken, string queueitToken,
            CustomerIntegration customerIntegrationInfo, string customerId, string secretKey)
        {
            var debugEntries         = new Dictionary <string, string>();
            var connectorDiagnostics = ConnectorDiagnostics.Verify(customerId, secretKey, queueitToken);

            if (connectorDiagnostics.HasError)
            {
                return(connectorDiagnostics.ValidationResult);
            }
            try
            {
                if (connectorDiagnostics.IsEnabled)
                {
                    debugEntries["SdkVersion"]    = UserInQueueService.SDK_VERSION;
                    debugEntries["Runtime"]       = GetRuntime();
                    debugEntries["ConfigVersion"] = customerIntegrationInfo != null?customerIntegrationInfo.Version.ToString() : "NULL";

                    debugEntries["PureUrl"]      = currentUrlWithoutQueueITToken;
                    debugEntries["QueueitToken"] = queueitToken;
                    debugEntries["OriginalUrl"]  = GetHttpContextProvider().HttpRequest.Url.AbsoluteUri;

                    LogExtraRequestDetails(debugEntries);
                }
                if (string.IsNullOrEmpty(currentUrlWithoutQueueITToken))
                {
                    throw new ArgumentException("currentUrlWithoutQueueITToken can not be null or empty.");
                }
                if (customerIntegrationInfo == null)
                {
                    throw new ArgumentException("customerIntegrationInfo can not be null.");
                }

                var configEvaluater = new IntegrationEvaluator();

                var matchedConfig = configEvaluater.GetMatchedIntegrationConfig(
                    customerIntegrationInfo,
                    currentUrlWithoutQueueITToken,
                    GetHttpContextProvider().HttpRequest);

                if (connectorDiagnostics.IsEnabled)
                {
                    debugEntries["MatchedConfig"] = matchedConfig != null ? matchedConfig.Name : "NULL";
                }
                if (matchedConfig == null)
                {
                    return(new RequestValidationResult(null));
                }

                switch (matchedConfig.ActionType ?? string.Empty)
                {
                case "":    //backward compatibility
                case ActionType.QueueAction:
                {
                    return(HandleQueueAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegrationInfo,
                                             customerId, secretKey, debugEntries, matchedConfig, connectorDiagnostics.IsEnabled));
                }

                case ActionType.CancelAction:
                {
                    return(HandleCancelAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegrationInfo,
                                              customerId, secretKey, debugEntries, matchedConfig, connectorDiagnostics.IsEnabled));
                }

                default:
                {
                    return(HandleIgnoreAction(matchedConfig.Name));
                }
                }
            }
            catch (Exception e)
            {
                if (connectorDiagnostics.IsEnabled)
                {
                    debugEntries["Exception"] = e.Message;
                }
                throw;
            }
            finally
            {
                SetDebugCookie(debugEntries);
            }
        }