当前位置: 首页>>代码示例>>C#>>正文


C# Role.AddChildrenRole方法代码示例

本文整理汇总了C#中Role.AddChildrenRole方法的典型用法代码示例。如果您正苦于以下问题:C# Role.AddChildrenRole方法的具体用法?C# Role.AddChildrenRole怎么用?C# Role.AddChildrenRole使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Role的用法示例。


在下文中一共展示了Role.AddChildrenRole方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            ms_rbac1 = new RBAC1();

            string[] users = new string[] { "u1", "u2", "u3", "u4" };

            // roles
            Role r1 = new Role("r1");
            Role r2 = new Role("r2");
            Role r3 = new Role("r3");
            Role r4 = new Role("r4");

            // permissions
            Permission p1 = new Permission("p1", "GET", "URI1");
            Permission p2 = new Permission("p2", "GET", "URI2");
            Permission p4 = new Permission("p4", "GET", "URI4");

            // Add Permissions
            ms_rbac1.AddPermission(p1);
            ms_rbac1.AddPermission(p2);
            ms_rbac1.AddPermission(p4);

            // populate users
            foreach (string user in users)
                ms_rbac1.AddUser(user);

            // Populate Roles
            ms_rbac1.AddRole(r1);
            ms_rbac1.AddRole(r2);
            ms_rbac1.AddRole(r3);
            ms_rbac1.AddRole(r4);

            // associate permissions with roles
            ms_rbac1.AddRolePermission(r1, p1);
            ms_rbac1.AddRolePermission(r2, p2);
            ms_rbac1.AddRolePermission(r4, p4);

            // build hierarchy
            r4.AddChildrenRole(r3);
            r3.AddChildrenRole(r1);
            r3.AddChildrenRole(r2);

            ListUsers(ms_rbac1.UserList);
            ListRoles(ms_rbac1.RoleList);
            ListPermissions(ms_rbac1.PermissionList);

            RBACSession session = new RBACSession("u1", "r4");

            // Test role permission
            TestRolePermission(session, p1);
            TestRolePermission(session, p2);
            TestRolePermission(session, p4);

            session = new RBACSession("u1", new string[]{"r1","r2"});

            // Test role permission
            TestRolePermission(session, p1);
            TestRolePermission(session, p2);
            TestRolePermission(session, p4);

            // Now let's load it from a file
            Console.WriteLine("\n\nLoading rbac1 from xml file!");
            session = new RBACSession("u1", "r3");
            ms_rbac1 = new RBAC1();
            ms_rbac1.Load("rbac1.xml");

            // Test role permission
            TestRolePermission(session, p1);
            TestRolePermission(session, p2);
            TestRolePermission(session, p4);
        }
开发者ID:pepipe,项目名称:ISEL,代码行数:71,代码来源:Program.cs


注:本文中的Role.AddChildrenRole方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。