Ejemplo n.º 1
0
 protected function seed()
 {
     $default_users = array(array('id' => '1', 'ipAddress' => inet_pton('127.0.0.1'), 'username' => 'administrator', 'password' => '$2y$10$EiqipvSt3lnD//nchj4u9OgOTL9R3J4AbZ5bUVVrh.Tq/gmc5xIvS', 'passwordChange' => '0', 'email' => '*****@*****.**', 'createdOn' => date('Y-m-d H:i:s'), 'lastLogin' => date('Y-m-d H:i:s'), 'active' => '1', 'sharedKey' => '9tThG2rFhZv+LslrrPy0I6QcCn9E3kNcyv5rqb3qKLywvFCfwHiSZ2fH2qQAgQXAkfBIrd0zHP+1v/FJ4W/kMA=='));
     //default user to roles
     $default_users_to_roles = array(array('admin', 'member'));
     //roles to descriptions
     $default_roles = array('admin' => 'Site Administrators', 'member' => 'General Members');
     //roles to permissions to permission descriptions
     $default_role_permissions = array('admin' => array('admin_create' => 'Creating administration resources.', 'admin_read' => 'Viewing administration resources.', 'admin_update' => 'Editing administration resources.', 'admin_delete' => 'Deleting administration resources.'), 'member' => array('public_read' => 'Viewing public resources.'));
     //seeding user accounts
     foreach ($default_users as $user) {
         $this->db->insert('user_accounts', $user);
     }
     //seeding roles and permissions
     $role_manager = new RoleManager(new MySQLAdapter($this->db->conn_id, new Options()));
     foreach ($default_role_permissions as $role => $permissions_array) {
         //create the role
         $created_role = Role::create($role, $default_roles[$role]);
         foreach ($permissions_array as $permission => $reason) {
             //create the permission
             $created_permission = Permission::create($permission, $reason);
             //save the permission to the database
             $role_manager->permissionSave($created_permission);
             //add the permission to the role
             $created_role->addPermission($created_permission);
         }
         $role_manager->roleSave($created_role);
     }
     //assign the role to the users
     foreach ($default_users_to_roles as $key => $roles) {
         $user_id = $default_users[$key]['id'];
         foreach ($roles as $role) {
             $assignable_role = $role_manager->roleFetchByName($role);
             $role_manager->roleAddSubjectId($assignable_role, $user_id);
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * @expectedException \RBAC\Exception\ValidationError
  */
 public function testRoleAddSubjectIdInvalidId()
 {
     $this->rm->roleAddSubjectId($this->generateRole(), null);
 }