protected override bool AuthorizeCore(System.Web.HttpContextBase httpContext) { bool?result = AuthorizationBehavior == null ? null : AuthorizationBehavior.OverrideAuthorize(this, httpContext); return(result.HasValue ? result.Value : base.AuthorizeCore(httpContext)); }
private AuthorizationBehavior toBehavior(AuthorizationNode node) { AuthorizationBehavior behavior = null; using (var runtime = FubuRuntime.Basic()) { behavior = (AuthorizationBehavior)runtime.Get <IContainer>().GetInstance <IActionBehavior>(node.As <IContainerModel>().ToInstance()); } return(behavior); }
public async Task Handle_RequestにするAuthorizerが空の場合はなにも実行されない() { var list = new List <string>(); var factory = new ServiceFactory(type => { return(Enumerable.Empty <IAuthorizer <TestBehaviorRequest> >()); }); var auth = new AuthorizationBehavior <TestBehaviorRequest, TestBehaviorResponse>(factory); await auth.Handle(new TestBehaviorRequest(), new CancellationToken(), () => Task.FromResult(new TestBehaviorResponse())); list.Should().BeEmpty(); }
protected override bool AuthorizeCore(System.Web.HttpContextBase httpContext) { bool?result = AuthorizationBehavior == null ? null : AuthorizationBehavior.OverrideAuthorize(this, httpContext); log.Debug("AuthorizeCore1: ", result); bool aux = result.HasValue ? result.Value : base.AuthorizeCore(httpContext); log.Debug("AuthorizeCore2: ", result); return(aux); }
public async Task Handle_Requestに一致する全てのAuthorizerが実行される() { var list = new List <string>(); var factory = new ServiceFactory(type => { return(new IAuthorizer <TestBehaviorRequest>[] { new SuccessAuthorizer1(list), new SuccessAuthorizer2(list) }); }); var auth = new AuthorizationBehavior <TestBehaviorRequest, TestBehaviorResponse>(factory); await auth.Handle(new TestBehaviorRequest(), new CancellationToken(), () => Task.FromResult(new TestBehaviorResponse())); list.Count.Should().Be(2); list[0].Should().Be(AuthorizerMessages.SuccessAuthorizer1Message); list[1].Should().Be(AuthorizerMessages.SuccessAuthorizer2Message); }
public async Task Handle_失敗した時にメッセージが設定されていない場合は例外にデフォルトのメッセージが設定される() { using var cal = TestHelper.SetEnglishCulture(); var list = new List <string>(); var factory = new ServiceFactory(type => { return(new IAuthorizer <TestBehaviorRequest>[] { new FailurAuthorizer1(list, string.Empty), }); }); var auth = new AuthorizationBehavior <TestBehaviorRequest, TestBehaviorResponse>(factory); Func <Task> act = () => auth.Handle(new TestBehaviorRequest(), new CancellationToken(), () => Task.FromResult(new TestBehaviorResponse())); await act.Should().ThrowAsync <UnauthorizedException>().WithMessage("Not authorized."); list.Count.Should().Be(1); list[0].Should().Be(AuthorizerMessages.FailurAuthorizer1Message); }
public async Task Handle_Authorizerが途中で失敗した場合はそこで処理が止まりUnauthorizedExceptionが発行される() { var list = new List <string>(); var factory = new ServiceFactory(type => { return(new IAuthorizer <TestBehaviorRequest>[] { new SuccessAuthorizer1(list), new FailurAuthorizer1(list, "unauthorized!"), new SuccessAuthorizer2(list) }); }); var auth = new AuthorizationBehavior <TestBehaviorRequest, TestBehaviorResponse>(factory); Func <Task> act = () => auth.Handle(new TestBehaviorRequest(), new CancellationToken(), () => Task.FromResult(new TestBehaviorResponse())); await act.Should().ThrowAsync <UnauthorizedException>().WithMessage("unauthorized!"); list.Count.Should().Be(2); list[0].Should().Be(AuthorizerMessages.SuccessAuthorizer1Message); list[1].Should().Be(AuthorizerMessages.FailurAuthorizer1Message); }
public static Fault CreateAccessDeniedFault(MessageVersion version) { FaultException exception = (FaultException)AuthorizationBehavior.CreateAccessDeniedFaultException(); return(new Fault(version.Addressing.DefaultFaultAction, exception.Code, exception.Reason.ToString())); }