/// <summary> /// Method to call the claims transformer to create the /// /// @author: Rachel Dang /// @updated: 04/28/18 /// </summary> /// <param name="username"></param> /// <param name="isFirstTimeUser"></param> /// <returns></returns> private ResponseDto <ClaimsIdentity> CreateClaimsIdentity(string username) { // Check if user is a first time user from the SSO var isFirstTimeUser = CheckIfFirstTimeUser(username); // If user is invalid and an error occurs, return dto with error if (isFirstTimeUser.Error != null) { return(new ResponseDto <ClaimsIdentity> { Error = GeneralErrorMessages.GENERAL_ERROR }); } // Call the Claims Transformer manager to create the claims identity var transformer = new ClaimsTransformer(); if (isFirstTimeUser.Data == true) { return(new ResponseDto <ClaimsIdentity> { Data = transformer.CreateSsoClaimsIdentity(username) }); } return(new ResponseDto <ClaimsIdentity> { Data = transformer.CreateAuthenticationClaimsIdentity(username) }); }
public void Should_ReturnClaimsIdentity_With_ReadPermissions() { // Arrange var username = "******"; var claims = new List <Claim> { new Claim(ResourceConstant.USERNAME, username) }; var identity = new ClaimsIdentity(claims); // Act var result = transformer.CreateAuthenticationClaimsIdentity(username); // Assert var readClaim = result.HasClaim(ActionConstant.READ + ResourceConstant.PREFERENCES, "True"); var notReadClaim = result.HasClaim(ActionConstant.UPDATE + ResourceConstant.PREFERENCES, "True"); // Assert readClaim.Should().BeTrue(); notReadClaim.Should().BeFalse(); }