public async Task AccessApplicationRequirement_Succeeds_If_User_Has_Access_To_Application()
        {
            var handlerContext = CreateHandlerContext(new AccessApplicationRequirement());
            await _handler.HandleAsync(handlerContext);

            Assert.IsTrue(handlerContext.HasSucceeded);
        }
        protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, TRequirement requirement, TEntity resource)
        {
            IAuthorizationRequirement delegateRequirement = CreateInstance <TDelegateRequirement>();
            var delegateContext = new AuthorizationHandlerContext(new[] { delegateRequirement }, context.User, _delegateResourceFn.Invoke(resource));
            await _delegateHandler.HandleAsync(delegateContext);

            if (delegateContext.HasSucceeded)
            {
                context.Succeed(requirement);
            }
        }
예제 #3
0
        public void HandleRequirementFailTest()
        {
            ClaimsPrincipal user = new ClaimsPrincipal(new ClaimsIdentity(new GenericIdentity("UnitTestUser"), new List <Claim> {
                new Claim(ClaimTypes.Role, "SecondRole")
            }));
            IAuthorizationRequirement requirement = new SimplePermissionRequirement("FirstPermission");

            AuthorizationHandlerContext authorizationContext = new AuthorizationHandlerContext(new List <IAuthorizationRequirement> {
                requirement
            }, user, null);

            AuthorizationHandler <SimplePermissionRequirement> authorizationHandler = (AuthorizationHandler <SimplePermissionRequirement>)requirement;

            authorizationHandler.HandleAsync(authorizationContext);

            Assert.IsFalse(authorizationContext.HasSucceeded);
        }