コード例 #1
0
 public IActionResult GetUserProfile()
 {
     try
     {
         var response = UserProfileResponseMapper.MapUserToResponseModel(User);
         return(Ok(response));
     }
     catch (Exception e)
     {
         _logger.LogError(e, "User does not have permission. Error: '{message}'", e.Message);
         return(Unauthorized());
     }
 }
コード例 #2
0
        public void Should_refuse_access_with_missing_role()
        {
            var USERNAME = ClaimsPrincipalBuilder.USERNAME;

            var userWithoutRole = new ClaimsPrincipalBuilder()
                                  .WithClaim(ClaimTypes.GivenName, UserData.FIRST_NAME)
                                  .WithClaim(ClaimTypes.Surname, UserData.LAST_NAME)
                                  .WithClaim("name", UserData.DISPLAY_NAME)
                                  .WithUsername(USERNAME)
                                  .Build();

            Assert.Throws <UnauthorizedAccessException>(() => UserProfileResponseMapper.MapUserToResponseModel(userWithoutRole));
        }
コード例 #3
0
 public IActionResult GetUserProfile()
 {
     try
     {
         var response = UserProfileResponseMapper.MapUserToResponseModel(User);
         return(Ok(response));
     }
     catch (Exception e)
     {
         const string message = "User does not have permission";
         _logger.LogError(e, message);
         return(Unauthorized(message));
     }
 }
コード例 #4
0
        public void Should_map_all_properties()
        {
            const string ROLE     = "VHQA";
            var          USERNAME = ClaimsPrincipalBuilder.USERNAME;

            var user = new ClaimsPrincipalBuilder()
                       .WithClaim(ClaimTypes.GivenName, UserData.FIRST_NAME)
                       .WithClaim(ClaimTypes.Surname, UserData.LAST_NAME)
                       .WithClaim("name", UserData.DISPLAY_NAME)
                       .WithUsername(USERNAME)
                       .WithRole(ROLE).Build();

            var response = UserProfileResponseMapper.MapUserToResponseModel(user);

            response.Username.Should().Be(USERNAME);
            response.Role.Should().Be(ROLE);
        }