/// <summary> /// Processes a request. /// </summary> /// <param name="context">The context in which the request to process is running.</param> /// <param name="evaluatorCallback">A callback to a custom request evaluator.</param> public void Process(HttpContextBase context, RequestEvaluatorCallback evaluatorCallback) { Logger.Log("Begin request processing."); RequestSecurity expectedSecurity = EvaluateRequestViaCallbackOrEvaluator(context, evaluatorCallback); if (expectedSecurity == RequestSecurity.Ignore) { // No redirect is needed for a result of Ignore. EnrichResponse(context, _settings); Logger.Log("Expected security is Ignore; done.", Logger.LogLevel.Info); return; } string targetUrl = DetermineTargetUrl(context, expectedSecurity); if (string.IsNullOrEmpty(targetUrl)) { // No redirect is needed for a null/empty target URL. EnrichResponse(context, _settings); Logger.Log("No target URI determined; done.", Logger.LogLevel.Info); return; } Redirect(context, targetUrl); }
/// <summary> /// Evaluates this request via any request evaluator callback or an IRequestEvaluator. /// </summary> /// <param name="context"></param> /// <param name="evaluatorCallback">A callback to a custom request evaluator.</param> /// <returns></returns> private RequestSecurity EvaluateRequestViaCallbackOrEvaluator(HttpContextBase context, RequestEvaluatorCallback evaluatorCallback) { RequestSecurity?evaluatorSecurity = null; if (evaluatorCallback != null) { evaluatorSecurity = evaluatorCallback(context); } RequestSecurity expectedSecurity; if (evaluatorSecurity.HasValue) { // Use the value returned by the EvaluateRequest event. Logger.Log("Using the expected security value provided by the RequestEvaluatorCallback.", Logger.LogLevel.Info); expectedSecurity = evaluatorSecurity.Value; } else { // Evaluate this request with the configured settings, if necessary. IRequestEvaluator requestEvaluator = RequestEvaluatorFactory.Instance.Create(context); expectedSecurity = requestEvaluator.Evaluate(context.Request, _settings); } return(expectedSecurity); }
/// <summary> /// Evaluates this request via any request evaluator callback or an IRequestEvaluator. /// </summary> /// <param name="context"></param> /// <param name="evaluatorCallback">A callback to a custom request evaluator.</param> /// <returns></returns> private RequestSecurity EvaluateRequestViaCallbackOrEvaluator(HttpContextBase context, RequestEvaluatorCallback evaluatorCallback) { RequestSecurity? evaluatorSecurity = null; if (evaluatorCallback != null) { evaluatorSecurity = evaluatorCallback(context); } RequestSecurity expectedSecurity; if (evaluatorSecurity.HasValue) { // Use the value returned by the EvaluateRequest event. Logger.Log("Using the expected security value provided by the RequestEvaluatorCallback.", Logger.LogLevel.Info); expectedSecurity = evaluatorSecurity.Value; } else { // Evaluate this request with the configured settings, if necessary. IRequestEvaluator requestEvaluator = RequestEvaluatorFactory.Instance.Create(context); expectedSecurity = requestEvaluator.Evaluate(context.Request, _settings); } return expectedSecurity; }