public void Should_Get_Changed_Principal_If()
        {
            var claimsPrincipal = new ClaimsPrincipal(new ClaimsIdentity(new List <Claim>
            {
                new Claim(ClaimTypes.Name, "bob"),
                new Claim(ClaimTypes.NameIdentifier, "123456")
            }));

            var claimsPrincipal2 = new ClaimsPrincipal(new ClaimsIdentity(new List <Claim>
            {
                new Claim(ClaimTypes.Name, "lee"),
                new Claim(ClaimTypes.NameIdentifier, "654321")
            }));


            _currentPrincipalAccessor.Principal.ShouldBe(null);

            using (_currentPrincipalAccessor.Change(claimsPrincipal))
            {
                _currentPrincipalAccessor.Principal.ShouldBe(claimsPrincipal);

                using (_currentPrincipalAccessor.Change(claimsPrincipal2))
                {
                    _currentPrincipalAccessor.Principal.ShouldBe(claimsPrincipal2);
                }

                _currentPrincipalAccessor.Principal.ShouldBe(claimsPrincipal);
            }
            _currentPrincipalAccessor.Principal.ShouldBeNull();
        }
Пример #2
0
 public virtual string GetUserId(HubConnectionContext connection)
 {
     using (_currentPrincipalAccessor.Change(connection.User))
     {
         return(_currentUser.Id?.ToString());
     }
 }
Пример #3
0
 public async Task Should_Return_True_For_Granted_Current_User_If_The_Permission_State_Is_Enabled()
 {
     using (_currentPrincipalAccessor.Change(new Claim(AbpClaimTypes.Role, "super-admin")))
     {
         (await _permissionChecker.IsGrantedAsync(
              CreatePrincipal(PermissionTestDataBuilder.User1Id, Guid.NewGuid()),
              "MyPermission5"
              )).ShouldBeTrue();
     }
 }
Пример #4
0
    public async Task GetAsync()
    {
        var permissionListResultDto = await _permissionAppService.GetAsync(UserPermissionValueProvider.ProviderName,
                                                                           PermissionTestDataBuilder.User1Id.ToString());

        permissionListResultDto.ShouldNotBeNull();
        permissionListResultDto.EntityDisplayName.ShouldBe(PermissionTestDataBuilder.User1Id.ToString());
        permissionListResultDto.Groups.Count.ShouldBe(1);
        permissionListResultDto.Groups.ShouldContain(x => x.Name == "TestGroup");

        permissionListResultDto.Groups.First().Permissions.ShouldContain(x => x.Name == "MyPermission1");
        permissionListResultDto.Groups.First().Permissions.ShouldContain(x => x.Name == "MyPermission2");
        permissionListResultDto.Groups.First().Permissions.ShouldContain(x => x.Name == "MyPermission2.ChildPermission1");
        permissionListResultDto.Groups.First().Permissions.ShouldContain(x => x.Name == "MyPermission3");
        permissionListResultDto.Groups.First().Permissions.ShouldContain(x => x.Name == "MyPermission4");

        permissionListResultDto.Groups.First().Permissions.ShouldNotContain(x => x.Name == "MyPermission5");

        using (_currentPrincipalAccessor.Change(new Claim(AbpClaimTypes.Role, "super-admin")))
        {
            (await _permissionAppService.GetAsync(UserPermissionValueProvider.ProviderName, PermissionTestDataBuilder.User1Id.ToString())).Groups.First().Permissions
            .ShouldContain(x => x.Name == "MyPermission5");
        }
    }
 public static IDisposable Change(this ICurrentPrincipalAccessor currentPrincipalAccessor, Claim claim)
 {
     return(currentPrincipalAccessor.Change(new[] { claim }));
 }
 public static IDisposable Change(this ICurrentPrincipalAccessor currentPrincipalAccessor, ClaimsIdentity claimsIdentity)
 {
     return(currentPrincipalAccessor.Change(new ClaimsPrincipal(claimsIdentity)));
 }
 public static IDisposable Change(this ICurrentPrincipalAccessor currentPrincipalAccessor, IEnumerable <Claim> claims)
 {
     return(currentPrincipalAccessor.Change(new ClaimsIdentity(claims)));
 }