/// <summary>
        ///
        /// </summary>
        /// <param name="permission"></param>
        /// <param name="principal"></param>
        public PermissionGrantingContext(PermissionDefinition permission, IPrincipal principal)
        {
            Check.NotNull(permission, nameof(permission));

            Permission = permission;
            Principal  = principal;
        }
Exemple #2
0
        public void Name()
        {
            var def = new PermissionDefinition("Test");

            def.Name.ShouldBe("Test");
            def.ToString().ShouldBe("[PermissionDefinition Test]");
        }
Exemple #3
0
        public void AddPermission()
        {
            var def = new PermissionDefinition("Test");

            def.Children.ShouldBeEmpty();
            def.AddChild("TestPermission");
            def.Children.ShouldHaveSingleItem().FullName.ShouldBe("Test.TestPermission");
        }
Exemple #4
0
        public void Properties()
        {
            var def = new PermissionDefinition("Test");

            def.Properties.ShouldBeEmpty();
            def.Properties.Add("TestKey", "TestValue");
            def.Properties.ShouldHaveSingleItem().Key.ShouldBe("TestKey");
        }
Exemple #5
0
        public void This()
        {
            var def = new PermissionDefinition("Test");

            def.Properties.ShouldBeEmpty();
            def["TestKey"].ShouldBeNull();
            def["TestKey"] = "TestValue";
            def.Properties.ShouldHaveSingleItem().Key.ShouldBe("TestKey");
        }
Exemple #6
0
        public void DisplayName()
        {
            var def = new PermissionDefinition("Test", "DisplayName");

            def.DisplayName.ShouldBe("DisplayName");
            Should.Throw <ArgumentNullException>(() => def.DisplayName = null);
            Should.NotThrow(() => def.DisplayName = "TestDisplay");
            def.DisplayName.ShouldBe("TestDisplay");
        }
Exemple #7
0
        public void GetPermissionsWithChildren()
        {
            var def = new PermissionDefinition("Test");

            def.Children.ShouldBeEmpty();
            def
            .AddChild("TestPermission",
                      p => p.AddChild("TestChild"));
            def.Children.ShouldHaveSingleItem().Children.ShouldHaveSingleItem().FullName.ShouldBe("Test.TestPermission.TestChild");
        }
Exemple #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="permissions"></param>
        /// <param name="permission"></param>
        protected virtual void AddPermissionToDictionaryRecursively(Dictionary <string, PermissionDefinition> permissions, PermissionDefinition permission)
        {
            permissions.Add(permission.FullName, permission);

            foreach (var child in permission.Children)
            {
                AddPermissionToDictionaryRecursively(permissions, child);
            }
        }
Exemple #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="permissions"></param>
        /// <param name="permission"></param>
        protected virtual void AddPermissionToDictionaryRecursively(Dictionary <string, PermissionDefinition> permissions, PermissionDefinition permission)
        {
            if (permissions.ContainsKey(permission.Name))
            {
                throw new ScorpioException("Duplicate permission name: " + permission.Name);
            }

            permissions[permission.Name] = permission;

            foreach (var child in permission.Children)
            {
                AddPermissionToDictionaryRecursively(permissions, child);
            }
        }