Example #1
0
        /// <summary>
        ///     Liefert alle <see cref="IGrantedAuthority" /> der angebenen Rolle für den Nutzer im AuthotizationManager.
        /// </summary>
        /// <param name="roles"></param>
        /// <returns></returns>
        public IList <IGrantedAuthority> GetAuthorities(IList <string> roles)
        {
            Require.NotNull(roles, nameof(roles));

            List <IGrantedAuthority> grantedAuthorities = new List <IGrantedAuthority>();

            foreach (string role in roles)
            {
                if (_rolesToPermissions.ContainsKey(role))
                {
                    // Rolle als Authority hinzufügen
                    grantedAuthorities.Add(new SimpleGrantedAuthority(role));
                    foreach (string permission in _rolesToPermissions[role])
                    {
                        if (AttributeExpressionParser.IsExpression(permission))
                        {
                            SimpleGrantedAuthority authorityForExpression = GetAuthorityForExpression(permission);
                            if (!grantedAuthorities.Contains(authorityForExpression))
                            {
                                grantedAuthorities.Add(authorityForExpression);
                            }
                        }
                        else
                        {
                            SimpleGrantedAuthority authority = new SimpleGrantedAuthority(permission);
                            if (!grantedAuthorities.Contains(authority))
                            {
                                grantedAuthorities.Add(authority);
                            }
                        }
                    }
                }
            }
            return(grantedAuthorities);
        }
        public void TestIsExpressionBracketsPermuted()
        {
            string testText = "eins}zwei{drei";
            // when:
            bool isExpression = AttributeExpressionParser.IsExpression(testText);

            // then:
            isExpression.ShouldBeEquivalentTo(false);
        }
        public void TestIsExpressionOnlyClosingBracket()
        {
            string testText = "einszwei}drei";
            // when:
            bool isExpression = AttributeExpressionParser.IsExpression(testText);

            // then:
            isExpression.ShouldBeEquivalentTo(false);
        }
        public void TestIsExpressionTrue()
        {
            string testText = "eins{zwei}drei";
            // when:
            bool isExpression = AttributeExpressionParser.IsExpression(testText);

            // then
            isExpression.ShouldBeEquivalentTo(true);
        }