public void TestAddSystemSecurableObject()
 {
     SecurableApplication system = new SecurableApplication();
     system.Name = "my system";
     system.Description = "my system can do this and that";
     new AuthorizationSvc().AddSystemSecurableObject(system);
 }
Exemple #2
0
        private void InitializeApplication(Application application)
        {
            var securableApplication = new SecurableApplication();
            securableApplication.CopyFrom(application);

            // adding the system securable object type.
            SecurableObjectType systemObjectType = new SecurableObjectType()
            {
                    Id = 0,
                    Application = securableApplication,
                    Name = "system",
                    Description = "System Securable Object Type"
            };

            // adding the systemObjectType as a securable object type.
            GatekeeperFactory.SecurableObjectTypeSvc.Add(systemObjectType);

            securableApplication.SecurableObjectType = systemObjectType;

            // adding the application as a securable object.
            GatekeeperFactory.SecurableObjectSvc.Add(securableApplication as ISecurableObject);

            // defining the system administrator role.
            Role systemAdministerRole = new Role()
            {
                Application = securableApplication,
                Name = "system_admin",
                Description = "Administers the System",
                SecurableObjectType = systemObjectType
            };

            // adding the system administrator and the system user roles.
            IRoleSvc roleSvc = GatekeeperFactory.RoleSvc;
            roleSvc.Add(systemAdministerRole);//adding the systemAdministerRole as a role.

            // defining the Administer_System right.
            Right administerSystemRight = new Right()
            {
                Application = securableApplication,
                Name = "administer_system",
                Description = "Administers the System",
                SecurableObjectType = systemObjectType
            };

            // defining the View_System right.
            Right viewSystemRight = new Right()
            {
                Application = securableApplication,
                Name = "view_system",
                Description = "Views the System",
                SecurableObjectType = systemObjectType
            };

            // adding the Administer_System and the View_System rights.
            IRightSvc rightSvc = GatekeeperFactory.RightSvc;
            rightSvc.Add(administerSystemRight);//adding the administerSystemRight as a right.
            rightSvc.Add(viewSystemRight);//adding the viewSystemRight as a right.

            // adding the role-right assignment (System Admin - Administer_System)
            RoleRightAssignment admin_administer = new RoleRightAssignment()
            {
                Application = securableApplication,
                Role = systemAdministerRole,
                Right = administerSystemRight,
                SecurableObjectType = systemObjectType
            };

            // adding the role-right assignment (System Admin - View_System)
            RoleRightAssignment admin_view = new RoleRightAssignment()
            {
                Application = securableApplication,
                Role = systemAdministerRole,
                Right = viewSystemRight,
                SecurableObjectType = systemObjectType
            };

            IRoleRightAssignmentSvc rraSvc = GatekeeperFactory.RoleRightAssignmentSvc;
            rraSvc.Add(admin_administer);
            rraSvc.Add(admin_view);

            var adminUser = GatekeeperFactory.UserSvc.GetByLoginName("admin");
            IApplicationUserSvc appUserSvc = GatekeeperFactory.ApplicationUserSvc;
            appUserSvc.Save(new ApplicationUser(){Application = securableApplication, User = adminUser, Role = systemAdministerRole});
        }