Exemplo n.º 1
0
        public void MultipleUserTypeClaimsShouldMatchAllTypes()
        {
            var principal = new ClaimsPrincipal(new ClaimsIdentity(new[]
            {
                new Claim(AllReady.Security.ClaimTypes.UserType, "SiteAdmin"),
                new Claim(AllReady.Security.ClaimTypes.UserType, "OrgAdmin"),
                new Claim(AllReady.Security.ClaimTypes.UserType, "BasicUser")
            }));

            Assert.True(principal.IsUserType(UserType.SiteAdmin));
            Assert.True(principal.IsUserType(UserType.OrgAdmin));
            Assert.True(principal.IsUserType(UserType.BasicUser));
        }
Exemplo n.º 2
0
        public void MultipleUserTypeClaimsShouldMatchAllTypes()
        {
            ClaimsPrincipal principal = new ClaimsPrincipal(
                new ClaimsIdentity(
                        new[]
                        {
                            new Claim(AllReady.Security.ClaimTypes.UserType, "SiteAdmin"),
                            new Claim(AllReady.Security.ClaimTypes.UserType, "TenantAdmin"),
                        }
                    ));

            Assert.True(principal.IsUserType(UserType.SiteAdmin));
            Assert.True(principal.IsUserType(UserType.TenantAdmin));
        }
Exemplo n.º 3
0
        public IEnumerable<SelectListItem> GetOrganizations(ClaimsPrincipal user)
        {
            // Default to authorizing the return of no organizations
            var listOfOrganizations = new List<SelectListItem>();

            if (user.IsUserType(UserType.SiteAdmin))
            {
                listOfOrganizations = GetOrganizationsForSiteAdmin();
            }
            else if (user.IsUserType(UserType.OrgAdmin))
            {
                listOfOrganizations = GetOrganizationForOrgAdmin(user);
            }

            return listOfOrganizations;
        }
Exemplo n.º 4
0
        public void OrganizationAdminUserShouldNotMatchSiteAdmin()
        {
            ClaimsPrincipal principal = new ClaimsPrincipal(
                new ClaimsIdentity(
                        new[]
                        {
                            new Claim(AllReady.Security.ClaimTypes.UserType, "OrgAdmin")
                        }
                    ));

            Assert.False(principal.IsUserType(UserType.SiteAdmin));
        }
Exemplo n.º 5
0
 public void SiteAdminUserShouldMatchSiteAdmin()
 {
     ClaimsPrincipal principal = new ClaimsPrincipal(
         new ClaimsIdentity(
                 new[] 
                 {
                     new Claim(AllReady.Security.ClaimTypes.UserType, "SiteAdmin")
                 }
             ));
    
     Assert.True(principal.IsUserType(UserType.SiteAdmin));
 }
Exemplo n.º 6
0
        public bool For(ClaimsPrincipal user, AllReadyTask task, UserManager<ApplicationUser> userManager)
        {
            var userId = userManager.GetUserId(user);

            if (user.IsUserType(UserType.SiteAdmin))
            {
                return true;
            }

            if (user.IsUserType(UserType.OrgAdmin))
            {
                //TODO: Modify to check that user is organization admin for organization of task
                return true;
            }

            if (task.Event?.Organizer != null && task.Event.Organizer.Id == userId)
            {
                return true;
            }

            if (task.Event?.Campaign?.Organizer != null && task.Event.Campaign.Organizer.Id == userId)
            {
                return true;
            }

            return false;
        }
Exemplo n.º 7
0
        public void OrganizationAdminUserShouldMatchOrganizationAdmin()
        {
            var principal = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(AllReady.Security.ClaimTypes.UserType, "OrgAdmin") }));

            Assert.True(principal.IsUserType(UserType.OrgAdmin));
        }
Exemplo n.º 8
0
 public void UserWithNoUserTypeClaimShouldNotMatchSiteAdmin()
 {
     var principal = new ClaimsPrincipal();
     Assert.False(principal.IsUserType(UserType.SiteAdmin));
 }