public UserPermissionAuthorizer(IUserContext userContext,
                                 IPermissionAuthorizationMatcher permissionAuthorizationMatcher,
                                 IUserPermissionResolver userPermissionResolver)
 {
     this.userContext = userContext;
     this.permissionAuthorizationMatcher = permissionAuthorizationMatcher;
     this.userPermissionResolver         = userPermissionResolver;
 }
        public UserPermissionAuthorizerTests()
        {
            userContext = new FakeUserContext();
            permissionAuthorizationMatcher = Substitute.For <IPermissionAuthorizationMatcher>();
            userPermissionResolver         = Substitute.For <IUserPermissionResolver>();

            permissionType1Id = Guid.Parse("0F292EFD-792E-48EC-93DF-CD99EEDB5885");

            sut = new UserPermissionAuthorizer(userContext, permissionAuthorizationMatcher,
                                               userPermissionResolver);
        }
Beispiel #3
0
        public UserPermissionAuthorizerTests()
        {
            userContext = new FakeUserContext();
            permissionAuthorizationMatcher = Substitute.For <IPermissionAuthorizationMatcher>();
            userPermissionResolver         = Substitute.For <IUserPermissionResolver>();
            permissionTypeRegistry         = Substitute.For <IPermissionTypeRegistry>();

            permissionTypeRegistry.GetPermissionTypeById(Guid.Parse("0F292EFD-792E-48EC-93DF-CD99EEDB5885"))
            .Returns(new PermissionType(Guid.Parse("0F292EFD-792E-48EC-93DF-CD99EEDB5885"), "permission"));

            sut = new UserPermissionAuthorizer(userContext, permissionAuthorizationMatcher,
                                               userPermissionResolver, permissionTypeRegistry);
        }
Beispiel #4
0
        public AspNetUserContext(
            [Optional] IAuthenticationManager authenticationManager,
            IUserPermissionResolver userPermissionResolver,
            IUserStore <IIdentityUser, Guid> userStore)
        {
            this.authenticationManager  = authenticationManager;
            this.userPermissionResolver = userPermissionResolver;
            this.userStore = userStore;

            userIdLazy = new Lazy <Guid?>(() =>
            {
                string userIdString = authenticationManager?.User?.Identity?.GetUserId <string>();
                return(userIdString != null ? ((Guid?)Guid.Parse(userIdString)) : null);
            });
        }
Beispiel #5
0
        public AspNetCoreUserContext(IUserPermissionResolver userPermissionResolver,
                                     IClaimsPrincipalUserResolver claimsPrincipalUserResolver,
                                     IHttpContextAccessor httpContextAccessor)
        {
            this.userPermissionResolver      = userPermissionResolver;
            this.claimsPrincipalUserResolver = claimsPrincipalUserResolver;
            this.httpContextAccessor         = httpContextAccessor;

            userIdLazy = new Lazy <Guid?>(() =>
            {
                var httpContext = httpContextAccessor.HttpContext;
                if (httpContext?.User?.Identity?.IsAuthenticated ?? false)
                {
                    var claimsPrincipal = httpContext.User;
                    return(claimsPrincipalUserResolver.TryGetUserId(claimsPrincipal));
                }

                return(null);
            });
        }
Beispiel #6
0
        public AspNetCoreUserContext(IUserPermissionResolver userPermissionResolver,
                                     IUserManager userManager,
                                     IHttpContextAccessor httpContextAccessor)
        {
            this.userPermissionResolver = userPermissionResolver;
            this.userManager            = userManager;
            this.httpContextAccessor    = httpContextAccessor;

            userIdLazy = new Lazy <Guid?>(() =>
            {
                var httpContext = httpContextAccessor.HttpContext;
                if (httpContext?.User?.Identity?.IsAuthenticated ?? false)
                {
                    var claimsPrincipal = httpContext.User;
                    string userIdString = userManager.GetUserId(claimsPrincipal);
                    return(userIdString != null ? (Guid?)Guid.Parse(userIdString) : null);
                }

                return(null);
            });
        }