public void AddIamClaimsMtTest()
        {
            var identity = new ClaimsIdentity();

            identity.AddIamClaims <long>(new Dictionary <long, IList <string> >()
            {
                { 1, new List <string>()
                  {
                      "Admin", "Manager"
                  } }
            },
                                         new Dictionary <long, IList <Claim> >()
            {
                { 1, new List <Claim>()
                  {
                      new Claim(Constants.POLICY_CLAIM_TYPE, "resource:operation"), new Claim("otherClaimtType", "otherClaimValue")
                  } }
            },
                                         new Dictionary <long, IList <Claim> >()
            {
                { 1, new List <Claim>()
                  {
                      new Claim($"{Constants.RESOURCE_ID_CLAIM_TYPE}:resource:operation", "1,2,3")
                  } }
            });

            Assert.AreEqual(4, identity.Claims.Count());

            Assert.IsNotNull(identity.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Role && x.Value == "Admin_1"));
            Assert.IsNotNull(identity.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Role && x.Value == "Manager_1"));
            Assert.IsNotNull(identity.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Role && x.Value == "resource:operation_1"));
            Assert.IsNotNull(identity.Claims.FirstOrDefault(x => x.Type.StartsWith(Constants.RESOURCE_ID_CLAIM_TYPE) && x.Value == "1,2,3_1"));
        }
Example #2
0
        public ClaimsIdentity GenerateClaimsIdentity(User user, IList <string> roles, IList <Claim> claims, IList <Claim> roleClaims)
        {
            Claim[] _claims = new[]
            {
                new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
                new Claim(ClaimTypes.Name, user.UserName),
            };

            ClaimsIdentity claimsIdentity = new ClaimsIdentity(_claims, "Token");

            claimsIdentity.AddIamClaims(roles, claims, roleClaims);

            return(claimsIdentity);
        }
Example #3
0
        public ClaimsIdentity GenerateClaimsIdentity <TTenantKey>(User user, IDictionary <TTenantKey, IList <string> > roles, IDictionary <TTenantKey, IList <Claim> > claims, IDictionary <TTenantKey, IList <Claim> > roleClaims)
            where TTenantKey : IEquatable <TTenantKey>
        {
            Claim[] _claims = new[]
            {
                new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
                new Claim(ClaimTypes.Name, user.UserName),
            };

            ClaimsIdentity claimsIdentity = new ClaimsIdentity(_claims, "Token");

            claimsIdentity.AddIamClaims(roles, claims, roleClaims);

            return(claimsIdentity);
        }