public ActionResult Handle(PolicyViolationException exception) { return new ViewResult { ViewName = "~/Views/Home/Index.cshtml" }; }
public ActionResult Handle(PolicyViolationException exception) { Log.Warn(exception); // We should really use 401 - Unauthorized, however with windows authentication, that keeps asking for credentials // We can't have this as the user is already authenticated return(new RedirectResult("~/Error/403.aspx")); }
public ActionResult Handle(PolicyViolationException exception) { //return new HttpUnauthorizedResult(exception.Message); return (new RedirectToRouteResult( new RouteValueDictionary(new { action = "Test", controller = "Account" }))); //Created a view for testing }
public void Should_return_first_handler_returned_by_convention() { var expectedHandler = new ExceptionPolicyViolationHandler(); var convention1 = new MockConvention(null); var convention2 = new MockConvention(expectedHandler); var convention3 = new MockConvention(null); var conventions = new List <IPolicyViolationHandlerConvention> { convention1, convention2, convention3 }; var policy = new IgnorePolicy(); var policyResult = PolicyResult.CreateFailureResult(policy, "Access denied"); var exception = new PolicyViolationException(policyResult); var selector = new PolicyViolationHandlerSelector(conventions); // Act var handler = selector.FindHandlerFor(exception); // Assert Assert.That(handler, Is.EqualTo(expectedHandler)); Assert.That(convention1.WasCalled, Is.True); Assert.That(convention2.WasCalled, Is.True); Assert.That(convention3.WasCalled, Is.False); }
public ActionResult Handle(PolicyViolationException exception) { //return new RedirectToRouteResult("Account/LogIn", // new RouteValueDictionary { { "error", "You have to be logged in order to view this website" } }); return(new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Account", action = "LogIn", area = "" }))); }
public ActionResult Handle(PolicyViolationException exception) { return(new RedirectToRouteResult("SignIn", new RouteValueDictionary { { "error", "You have to be logged in order to view this website" } })); }
public void Should_have_PolicyType_set_to_DelegatePolicy() { // Act var exception = new PolicyViolationException <DelegatePolicy>("Access denied"); // Assert Assert.That(exception.PolicyType, Is.EqualTo(typeof(DelegatePolicy))); Assert.That(exception.Message, Is.EqualTo("Access denied")); }
public ActionResult Handle(PolicyViolationException exception) { var routeData = RouteTable.Routes.GetRouteData(new HttpContextWrapper(HttpContext.Current)); var areaName = routeData.GetAreaName(); return (new RedirectToRouteResult( new RouteValueDictionary(new { action = "AnonymousError", controller = "Error", area = areaName }))); }
public void Should_have_PolicyType_set_to_RequireRolePolicy() { // Act var exception = new PolicyViolationException<RequireRolePolicy>("Access denied"); // Assert Assert.That(exception.PolicyType, Is.EqualTo(typeof(RequireRolePolicy))); Assert.That(exception.Message, Is.EqualTo("Access denied")); }
public ActionResult Handle(PolicyViolationException exception) { if (exception == null) { throw new ArgumentNullException("exception"); } return(new UnauthorizedResult()); //return new HttpUnauthorizedResult(exception.Message); }
public void Should_have_PolicyType_set_to_DenyAuthenticatedAccessPolicy() { // Act var exception = new PolicyViolationException<DenyAuthenticatedAccessPolicy>("Authenticated access denied"); // Assert Assert.That(exception.PolicyType, Is.EqualTo(typeof(DenyAuthenticatedAccessPolicy))); Assert.That(exception.Message, Is.EqualTo("Authenticated access denied")); }
public void Should_throw_when_exception_is_null() { // Arrange PolicyViolationException exception = null; var handler = new HttpUnauthorizedPolicyViolationHandler(); // Act & Assert Assert.Throws <ArgumentNullException>(() => handler.Handle(exception)); }
public IPolicyViolationHandler FindHandlerFor(PolicyViolationException exception) { IPolicyViolationHandler matchingHandler = null; foreach (var convention in _conventions) { matchingHandler = convention.GetHandlerFor(exception); if (matchingHandler != null) break; } return matchingHandler; }
public IPolicyViolationHandler GetHandlerFor(PolicyViolationException exception) { var type = GetHandlerTypeFor(exception); if (type != null) { if (typeof(IPolicyViolationHandler).IsAssignableFrom(type)) return PolicyViolationHandlerProvider.Invoke(type) as IPolicyViolationHandler; } return null; }
public ActionResult Handle(PolicyViolationException exception) { RouteValueDictionary rvd = new RouteValueDictionary(); rvd["controller"] = "AdminAccount"; rvd["Action"] = "Index"; rvd["Area"] = "Admin"; return(new RedirectToRouteResult(rvd)); }
public ActionResult Handle(PolicyViolationException exception) { //TODO: want to record where we were trying to go return(new RedirectToRouteResult(new RouteValueDictionary(new { action = "ChooseElection", controller = "Dashboard", area = "" }))); }
public void Should_not_return_handler_for_RequireRolePolicy() { // Arrange var exception = new PolicyViolationException<RequireRolePolicy>("Access denied"); // Act var handler = _violationHandler.FindHandlerFor(exception); // Assert Assert.That(handler, Is.Null); }
public void Should_return_handler_for_DenyAuthenticatedAccessPolicy() { // Arrange var exception = new PolicyViolationException<DenyAuthenticatedAccessPolicy>("Authenticated access denied"); // Act var handler = _violationHandler.FindHandlerFor(exception); // Assert Assert.That(handler, Is.TypeOf(typeof(DenyAuthenticatedAccessPolicyViolationHandler))); }
public void Should_not_return_handler_for_RequireRolePolicy() { // Arrange var exception = new PolicyViolationException <RequireRolePolicy>("Access denied"); // Act var handler = _violationHandler.FindHandlerFor(exception); // Assert Assert.That(handler, Is.Null); }
public void Should_return_handler_for_DenyAuthenticatedAccessPolicy() { // Arrange var exception = new PolicyViolationException <DenyAuthenticatedAccessPolicy>("Authenticated access denied"); // Act var handler = _violationHandler.FindHandlerFor(exception); // Assert Assert.That(handler, Is.TypeOf(typeof(DenyAuthenticatedAccessPolicyViolationHandler))); }
public IPolicyViolationHandler GetHandlerFor(PolicyViolationException exception) { var type = GetHandlerTypeFor(exception); if (type != null) { if (typeof(IPolicyViolationHandler).IsAssignableFrom(type)) { return(PolicyViolationHandlerProvider.Invoke(type) as IPolicyViolationHandler); } } return(null); }
public ActionResult Handle(PolicyViolationException exception) { //Log the violation, send mail etc. etc. var rvd = new RouteValueDictionary(new { area = "", controller = "Home", action = "Home", statusDescription = exception.Message }); return(new RedirectToRouteResult(rvd)); }
public ActionResult Handle(PolicyViolationException exception) { var delegatePolicyResult = (DelegatePolicyResult)exception.PolicyResult; if (delegatePolicyResult.ViolationHandler != null) return delegatePolicyResult.ViolationHandler.Invoke(exception); var matchingViolationHandler = _policyViolationHandlers.SingleOrDefault(handler => HandlerIsMatchForException(handler, delegatePolicyResult.PolicyName)); if (matchingViolationHandler != null) return matchingViolationHandler.Handle(exception); throw exception; }
public IPolicyViolationHandler FindHandlerFor(PolicyViolationException exception) { IPolicyViolationHandler matchingHandler = null; foreach (var convention in _conventions) { matchingHandler = convention.GetHandlerFor(exception); if (matchingHandler != null) { break; } } return(matchingHandler); }
public void Should_have_PolicyResult_PolicyType_and_Message_set() { // Arrange var policy = new DenyAnonymousAccessPolicy(); var policyResult = PolicyResult.CreateFailureResult(policy, "Anonymous access denied"); // Act var exception = new PolicyViolationException(policyResult); // Assert Assert.That(exception.PolicyResult, Is.EqualTo(policyResult)); Assert.That(exception.PolicyType, Is.EqualTo(typeof(DenyAnonymousAccessPolicy))); Assert.That(exception.Message, Is.EqualTo("Anonymous access denied")); }
public void Should_have_PolicyResult_PolicyType_and_Message_set() { // Arrange var policy = new DenyAnonymousAccessPolicy(); var policyResult = PolicyResult.CreateFailureResult(policy, "Anonymous access denied"); // Act var exception = new PolicyViolationException(policyResult); // Assert Assert.That(exception.PolicyResult, Is.EqualTo(policyResult)); Assert.That(exception.PolicyType, Is.EqualTo(typeof(DenyAnonymousAccessPolicy))); Assert.That(exception.Message, Is.EqualTo("Anonymous access denied")); }
public void Should_throw_when_no_violation_handler_has_been_set_and_no_violation_handler_match_name() { // Arrange var violationHandlers = Enumerable.Empty<IPolicyViolationHandler>(); var failureResult = PolicyResult.CreateFailureResult(new IgnorePolicy(), "Access denied"); var policy = new DelegatePolicy("Test", c => failureResult); var delegatePolicyResult = new DelegatePolicyResult(failureResult, policy.Name, policy.ViolationHandler); var exception = new PolicyViolationException(delegatePolicyResult); var handler = new DelegatePolicyViolationHandler(violationHandlers); // Act & assert var caughtException = Assert.Throws<PolicyViolationException>(() => handler.Handle(exception)); Assert.That(caughtException, Is.EqualTo(exception)); }
public void Should_throw_when_no_violation_handler_has_been_set_and_no_violation_handler_match_name() { // Arrange var violationHandlers = Enumerable.Empty <IPolicyViolationHandler>(); var failureResult = PolicyResult.CreateFailureResult(new IgnorePolicy(), "Access denied"); var policy = new DelegatePolicy("Test", c => failureResult); var delegatePolicyResult = new DelegatePolicyResult(failureResult, policy.Name, policy.ViolationHandler); var exception = new PolicyViolationException(delegatePolicyResult); var handler = new DelegatePolicyViolationHandler(violationHandlers); // Act & assert var caughtException = Assert.Throws <PolicyViolationException>(() => handler.Handle(exception)); Assert.That(caughtException, Is.EqualTo(exception)); }
public void Should_return_action_result_from_explicitly_set_violation_handler() { // Arrange var violationHandlers = Enumerable.Empty<IPolicyViolationHandler>(); var expectedResult = new ContentResult { Content = "Some content" }; var failureResult = PolicyResult.CreateFailureResult(new IgnorePolicy(), "Access denied"); var policy = new DelegatePolicy("Test", c => failureResult, e => expectedResult); var delegatePolicyResult = new DelegatePolicyResult(failureResult, policy.Name, policy.ViolationHandler); var exception = new PolicyViolationException(delegatePolicyResult); var handler = new DelegatePolicyViolationHandler(violationHandlers); // Act var result = handler.Handle(exception); // Assert Assert.That(result, Is.EqualTo(expectedResult)); }
public ActionResult Handle(PolicyViolationException exception) { var delegatePolicyResult = (DelegatePolicyResult)exception.PolicyResult; if (delegatePolicyResult.ViolationHandler != null) { return(delegatePolicyResult.ViolationHandler.Invoke(exception)); } var matchingViolationHandler = _policyViolationHandlers.SingleOrDefault(handler => HandlerIsMatchForException(handler, delegatePolicyResult.PolicyName)); if (matchingViolationHandler != null) { return(matchingViolationHandler.Handle(exception)); } throw exception; }
public void Should_return_action_result_from_explicitly_set_violation_handler() { // Arrange var violationHandlers = Enumerable.Empty <IPolicyViolationHandler>(); var expectedResult = new ContentResult { Content = "Some content" }; var failureResult = PolicyResult.CreateFailureResult(new IgnorePolicy(), "Access denied"); var policy = new DelegatePolicy("Test", c => failureResult, e => expectedResult); var delegatePolicyResult = new DelegatePolicyResult(failureResult, policy.Name, policy.ViolationHandler); var exception = new PolicyViolationException(delegatePolicyResult); var handler = new DelegatePolicyViolationHandler(violationHandlers); // Act var result = handler.Handle(exception); // Assert Assert.That(result, Is.EqualTo(expectedResult)); }
public void Should_return_action_result_from_violation_handler_that_match_name() { // Arrange var nonMatchingNameViolationHandler = new NonMatchingNameViolationHandler(); var matchingNameViolationHandler = new MatchingNameViolationHandler(); var violationHandlers = new List <IPolicyViolationHandler> { nonMatchingNameViolationHandler, matchingNameViolationHandler }; var failureResult = PolicyResult.CreateFailureResult(new IgnorePolicy(), "Access denied"); var policy = new DelegatePolicy("MatchingName", c => failureResult); var delegatePolicyResult = new DelegatePolicyResult(failureResult, policy.Name, policy.ViolationHandler); var exception = new PolicyViolationException(delegatePolicyResult); var handler = new DelegatePolicyViolationHandler(violationHandlers); // Act var result = handler.Handle(exception); // Assert Assert.That(result, Is.EqualTo(matchingNameViolationHandler.ActionResult)); }
public void Should_return_action_result_from_violation_handler_that_match_name() { // Arrange var nonMatchingNameViolationHandler = new NonMatchingNameViolationHandler(); var matchingNameViolationHandler = new MatchingNameViolationHandler(); var violationHandlers = new List<IPolicyViolationHandler> { nonMatchingNameViolationHandler, matchingNameViolationHandler }; var failureResult = PolicyResult.CreateFailureResult(new IgnorePolicy(), "Access denied"); var policy = new DelegatePolicy("MatchingName", c => failureResult); var delegatePolicyResult = new DelegatePolicyResult(failureResult, policy.Name, policy.ViolationHandler); var exception = new PolicyViolationException(delegatePolicyResult); var handler = new DelegatePolicyViolationHandler(violationHandlers); // Act var result = handler.Handle(exception); // Assert Assert.That(result, Is.EqualTo(matchingNameViolationHandler.ActionResult)); }
public IPolicyViolationHandler FindHandlerFor(PolicyViolationException exception) { IPolicyViolationHandler matchingHandler = null; foreach (var violationHandlerConvention in _conventions) { var convention = violationHandlerConvention; Publish.RuntimeEvent(() => { var conventionName = convention.ToString(); return "Finding policy violation handler using convention {0}.".FormatWith(conventionName); }, exception.SecurityContext); matchingHandler = convention.GetHandlerFor(exception); if (matchingHandler != null) { Publish.RuntimeEvent(() => "Found policy violation handler {0}.".FormatWith(matchingHandler.GetType().FullName), exception.SecurityContext); break; } } return matchingHandler; }
public IPolicyViolationHandler FindHandlerFor(PolicyViolationException exception) { IPolicyViolationHandler matchingHandler = null; foreach (var violationHandlerConvention in _conventions) { var convention = violationHandlerConvention; Publish.RuntimeEvent(() => { var conventionName = convention.ToString(); return("Finding policy violation handler using convention {0}.".FormatWith(conventionName)); }, exception.SecurityContext); matchingHandler = convention.GetHandlerFor(exception); if (matchingHandler != null) { Publish.RuntimeEvent(() => "Found policy violation handler {0}.".FormatWith(matchingHandler.GetType().FullName), exception.SecurityContext); break; } } return(matchingHandler); }
public ActionResult Handle(PolicyViolationException exception) { if (SecurityProvider.UserIsAuthenticated()) { return(new ViewResult { ViewName = ViewName }); } else { var rvd = new System.Web.Routing.RouteValueDictionary(); if (System.Web.HttpContext.Current.Request.RawUrl != "/") { rvd["ReturnUrl"] = System.Web.HttpContext.Current.Request.RawUrl; } rvd["controller"] = "Account"; rvd["action"] = "LogOn"; rvd["area"] = ""; return(new RedirectToRouteResult(rvd)); } }
public IPolicyViolationHandler GetHandlerFor(PolicyViolationException exception) { throw new NotImplementedException(); }
public virtual ActionResult Handle(PolicyViolationException exception) { return _actionResult; }
public override Type GetHandlerTypeFor(PolicyViolationException exception) { return null; }
public ActionResult Handle(PolicyViolationException exception) { return new ViewResult { ViewName = ViewName }; }
public IPolicyViolationHandler GetHandlerFor(PolicyViolationException exception) { var policyViolationHandlers = PolicyViolationHandlerProvider.Invoke().ToList(); return GetHandlerFor(exception, policyViolationHandlers); }
public override IPolicyViolationHandler GetHandlerFor(PolicyViolationException exception, IEnumerable<IPolicyViolationHandler> policyViolationHandlers) { var matchingHandler = policyViolationHandlers.SingleOrDefault(HandlerIsDefaultPolicyViolationHandler); return matchingHandler; }
public abstract IPolicyViolationHandler GetHandlerFor(PolicyViolationException exception, IEnumerable<IPolicyViolationHandler> policyViolationHandlers);
private static bool HandlerIsMatchForPolicyName(IPolicyViolationHandler handler, PolicyViolationException exception) { var expectedHandlerName = "{0}ViolationHandler".FormatWith(exception.PolicyType.Name); var actualHandlerName = handler.GetType().Name; return expectedHandlerName == actualHandlerName; }
public abstract Type GetHandlerTypeFor(PolicyViolationException exception);
public override IPolicyViolationHandler GetHandlerFor(PolicyViolationException exception, IEnumerable<IPolicyViolationHandler> policyViolationHandlers) { var matchingHandler = policyViolationHandlers.SingleOrDefault(handler => HandlerIsMatchForPolicyName(handler, exception)); return matchingHandler; }
public IPolicyViolationHandler GetHandlerFor(PolicyViolationException exception) { throw new NotImplementedException(); }
public IPolicyViolationHandler GetHandlerFor(PolicyViolationException exception) { WasCalled = true; return _handlerToReturn; }
public ActionResult Handle(PolicyViolationException exception) { return(new ViewResult { ViewName = ViewName }); }
public ActionResult Handle(PolicyViolationException exception) { throw exception; }
public ActionResult Handle(PolicyViolationException exception) { if (exception == null) throw new ArgumentNullException("exception"); return new HttpUnauthorizedResult(exception.Message); }
public override Type GetHandlerTypeFor(PolicyViolationException exception) { return(null); }
public ActionResult Handle(PolicyViolationException exception) { throw new NotImplementedException(); }
private static bool HandlerIsMatchForPolicyName(IPolicyViolationHandler handler, PolicyViolationException exception) { var expectedHandlerName = "{0}ViolationHandler".FormatWith(exception.PolicyType.Name); var actualHandlerName = handler.GetType().Name; return(expectedHandlerName == actualHandlerName); }
public override IPolicyViolationHandler GetHandlerFor(PolicyViolationException exception, IEnumerable <IPolicyViolationHandler> policyViolationHandlers) { var matchingHandler = policyViolationHandlers.SingleOrDefault(handler => HandlerIsMatchForPolicyName(handler, exception)); return(matchingHandler); }
public ActionResult Handle(PolicyViolationException exception) { return ActionResult; }
public ActionResult Handle(PolicyViolationException exception) { Log.Warn(exception); return(new RedirectResult(string.Format("~/Error/NoMarketAccess.aspx?Message={0}", HttpUtility.UrlEncode(exception.Message)))); }
public ActionResult Handle(PolicyViolationException exception) { throw new NotImplementedException(); }