public override SystemPermissions GetPermissionsForUser(IUserIdentity user)
        {
            if (user == null || !user.IsAuthenticated())
            {
                return(SystemPermissions.None);
            }

            var calculatedPermissions = SystemPermissions.None;

            if (!String.IsNullOrEmpty(user.UserName))
            {
                // See if there are user-specific permissions
                SystemPermissions userPermissions;
                if (_userPermissions.TryGetValue(user.UserName, out userPermissions))
                {
                    calculatedPermissions |= userPermissions;
                }
            }

            foreach (var claim in user.Claims)
            {
                SystemPermissions claimPermissions;
                if (_claimPermissions.TryGetValue(claim, out claimPermissions))
                {
                    calculatedPermissions |= claimPermissions;
                }
            }

            return(calculatedPermissions);
        }
        public override SystemPermissions GetPermissionsForUser(IUserIdentity user)
        {

            if (user == null || !user.IsAuthenticated())
            {
                return SystemPermissions.None;
            }

            var calculatedPermissions = SystemPermissions.None;
            if (!String.IsNullOrEmpty(user.UserName))
            {
                // See if there are user-specific permissions
                SystemPermissions userPermissions;
                if (_userPermissions.TryGetValue(user.UserName, out userPermissions))
                {
                    calculatedPermissions |= userPermissions;
                }
            }

            foreach (var claim in user.Claims)
            {
                SystemPermissions claimPermissions;
                if (_claimPermissions.TryGetValue(claim, out claimPermissions))
                {
                    calculatedPermissions |= claimPermissions;
                }
            }

            return calculatedPermissions;
        }
        public void Should_return_true_for_authentication_if_username_is_set()
        {
            // Given
            IUserIdentity user = GetFakeUser("Fake");

            // When
            var result = user.IsAuthenticated();

            // Then
            result.ShouldBeTrue();
        }
        public void Should_return_false_for_authentication_if_the_username_is_whitespace()
        {
            // Given
            IUserIdentity user = GetFakeUser("   \r\n   ");

            // When
            var result = user.IsAuthenticated();

            // Then
            result.ShouldBeFalse();
        }
        public void Should_return_false_for_authentication_if_the_user_is_null()
        {
            // Given
            IUserIdentity user = null;

            // When
            var result = user.IsAuthenticated();

            // Then
            result.ShouldBeFalse();
        }
Example #6
0
        public override StorePermissions GetStorePermissions(IUserIdentity currentUser, string storeName)
        {
            if (currentUser == null || !currentUser.IsAuthenticated())
            {
                return(StorePermissions.None);
            }

            var calculatedPermissions = StorePermissions.None;

            if (!String.IsNullOrEmpty(currentUser.UserName))
            {
                // See if there are user-specific permissions
                Dictionary <string, StorePermissions> storeUserPermissions;
                if (_storeUsers.TryGetValue(storeName, out storeUserPermissions))
                {
                    StorePermissions userPermissions;
                    if (storeUserPermissions.TryGetValue(currentUser.UserName, out userPermissions))
                    {
                        calculatedPermissions |= userPermissions;
                    }
                }
            }

            Dictionary <string, StorePermissions> storeClaimPermissions;

            if (_storeClaims.TryGetValue(storeName, out storeClaimPermissions))
            {
                foreach (var claim in currentUser.Claims)
                {
                    StorePermissions claimPermissions;
                    if (storeClaimPermissions.TryGetValue(claim, out claimPermissions))
                    {
                        calculatedPermissions |= claimPermissions;
                    }
                }
            }
            return(calculatedPermissions);
        }
        public override StorePermissions GetStorePermissions(IUserIdentity currentUser, string storeName)
        {
            if (currentUser == null || !currentUser.IsAuthenticated())
            {
                return StorePermissions.None;
            }

            var calculatedPermissions = StorePermissions.None;
            if (!String.IsNullOrEmpty(currentUser.UserName))
            {
                // See if there are user-specific permissions
                Dictionary<string, StorePermissions> storeUserPermissions;
                if (_storeUsers.TryGetValue(storeName, out storeUserPermissions))
                {
                    StorePermissions userPermissions;
                    if (storeUserPermissions.TryGetValue(currentUser.UserName, out userPermissions))
                    {
                        calculatedPermissions |= userPermissions;
                    }
                }
            }

            Dictionary<string, StorePermissions> storeClaimPermissions;
            if (_storeClaims.TryGetValue(storeName, out storeClaimPermissions))
            {
                foreach (var claim in currentUser.Claims)
                {
                    StorePermissions claimPermissions;
                    if (storeClaimPermissions.TryGetValue(claim, out claimPermissions))
                    {
                        calculatedPermissions |= claimPermissions;
                    }
                }
            }
            return calculatedPermissions;
        }