示例#1
0
        private static void SecuritySetUp()
        {
            using (PermissionsProviderContext dbContext = new PermissionsProviderContext()) {
                SecurityUser user = new SecurityUser()
                {
                    Name = "John", Password = "******"
                };
                SecurityRole roleForUser = new SecurityRole();
                SecurityUser admin       = new SecurityUser()
                {
                    Name = "Admin", Password = "******"
                };
                SecurityRole roleForAdmin = new SecurityRole();

                // "Address" member of contacts "Ezra" will be denied
                roleForUser.AddMemberPermission <EFCoreDemoDbContext, Contact>(SecurityOperation.Read, OperationState.Deny, "Address", (db, obj) => obj.Name == "Ezra");
                // Contact "Kevin" will be denied
                roleForUser.AddObjectPermission <EFCoreDemoDbContext, Contact>(SecurityOperation.Read, OperationState.Deny, (db, obj) => obj.Address == "California");

                user.AddRole(roleForUser);
                admin.AddRole(roleForAdmin);

                dbContext.Add(user);
                dbContext.Add(admin);
                dbContext.SaveChanges();
            }
        }
示例#2
0
        private static void SecuritySetUp()
        {
            using (PermissionsProviderContext dbContext = new PermissionsProviderContext()) {
                SecurityUser user = new SecurityUser()
                {
                    Name = "John", Password = "******"
                };
                SecurityRole roleForUser = new SecurityRole();
                SecurityUser admin       = new SecurityUser()
                {
                    Name = "Admin", Password = "******"
                };
                SecurityRole roleForAdmin = new SecurityRole();

                ContactSecuritySetUp(roleForUser);
                DepartmentSecuritySetUp(roleForUser);
                TaskSecuritySetUp(roleForUser);

                user.AddRole(roleForUser);
                admin.AddRole(roleForAdmin);

                dbContext.Add(user);
                dbContext.Add(admin);
                dbContext.SaveChanges();
            }
        }