public function setUp() { $this->user = new User(); $this->userRole = new UserRole(); $this->role = new Role(); $this->permission = new Permission(); $this->permission->setPermissions(122); $this->permission->setContext('sulu.security.roles'); $this->role->addPermission($this->permission); $this->userRole->setRole($this->role); $this->user->addUserRole($this->userRole); $this->userGroup = new UserGroup(); $this->group = new Group(); $this->role = new Role(); $this->permission = new Permission(); $this->permission->setPermissions(122); $this->permission->setContext('sulu.security.groups'); $this->role->addPermission($this->permission); $this->group->addRole($this->role); $this->userGroup->setGroup($this->group); $this->nestedGroup = new Group(); $this->role = new Role(); $this->permission = new Permission(); $this->permission->setPermissions(122); $this->permission->setContext('sulu.security.groups.nested'); $this->role->addPermission($this->permission); $this->nestedGroup->addRole($this->role); $this->group->addChildren($this->nestedGroup); $this->user->addUserGroup($this->userGroup); $this->token = $this->prophesize(TokenInterface::class); $this->token->getUser()->willReturn($this->user); $this->aclProvider = $this->prophesize(AclProviderInterface::class); $this->aclProvider->findAcl(Argument::any())->willReturn(true); $this->voter = new SecurityContextVoter($this->permissions, $this->aclProvider->reveal()); }
protected function initOrm() { $this->purgeDatabase(); $contact = new Contact(); $contact->setFirstName('Max'); $contact->setLastName('Mustermann'); $this->em->persist($contact); $this->em->flush(); $emailType = new EmailType(); $emailType->setName('Private'); $this->em->persist($emailType); $this->em->flush(); $email = new Email(); $email->setEmail('*****@*****.**'); $email->setEmailType($emailType); $this->em->persist($email); $this->em->flush(); $role1 = new Role(); $role1->setName('Role1'); $role1->setSystem('Sulu'); $this->em->persist($role1); $this->em->flush(); $user = new User(); $user->setUsername('admin'); $user->setPassword('securepassword'); $user->setSalt('salt'); $user->setLocale('de'); $user->setContact($contact); $this->em->persist($user); $this->em->flush(); $userRole1 = new UserRole(); $userRole1->setRole($role1); $userRole1->setUser($user); $userRole1->setLocale(json_encode(['de', 'en'])); $this->em->persist($userRole1); $this->em->flush(); $permission1 = new Permission(); $permission1->setPermissions(122); $permission1->setRole($role1); $permission1->setContext('Context 1'); $this->em->persist($permission1); $this->em->flush(); $tag1 = new Tag(); $tag1->setName('tag1'); $this->em->persist($tag1); $this->em->flush(); $tag2 = new Tag(); $tag2->setName('tag2'); $this->em->persist($tag2); $this->em->flush(); $tag3 = new Tag(); $tag3->setName('tag3'); $this->em->persist($tag3); $this->em->flush(); $tag4 = new Tag(); $tag4->setName('tag4'); $this->em->persist($tag4); $this->em->flush(); }
private function createRole($roleName) { $doctrine = $this->getContainer()->get('doctrine'); $em = $doctrine->getManager(); $now = new \Datetime(); $role = new Role(); $role->setName($roleName); $role->setSystem('Sulu'); $em->persist($role); $em->flush(); }
public function setUp() { $this->em = $this->db('ORM')->getOm(); $this->purgeDatabase(); $this->securityType1 = new SecurityType(); $this->securityType1->setName('Security Type 1'); $this->em->persist($this->securityType1); $this->securityType2 = new SecurityType(); $this->securityType2->setName('Security Type 2'); $this->em->persist($this->securityType2); $role = new Role(); $role->setName('Sulu Administrator'); $role->setSystem('Sulu'); $role->setSecurityType($this->securityType1); $this->em->persist($role); $this->role1 = $role; $role2 = new Role(); $role2->setName('Sulu Editor'); $role2->setSystem('Sulu'); $this->em->persist($role2); $this->role2 = $role2; $this->em->flush(); $permission1 = new Permission(); $permission1->setRole($role); $permission1->setContext('context1'); $permission1->setPermissions(15); $this->em->persist($permission1); $this->permission1 = $permission1; $permission2 = new Permission(); $permission2->setRole($role); $permission2->setContext('context2'); $permission2->setPermissions(17); $this->em->persist($permission2); $this->permission2 = $permission2; $permission3 = new Permission(); $permission3->setRole($role2); $permission3->setContext('context1'); $permission3->setPermissions(64); $this->em->persist($permission3); $permission4 = new Permission(); $permission4->setRole($role2); $permission4->setContext('context2'); $permission4->setPermissions(35); $this->em->persist($permission4); $this->em->flush(); }
public function setUp() { $roleIdReflection = new \ReflectionProperty(BaseRole::class, 'id'); $roleIdReflection->setAccessible(true); $this->user = new User(); $this->userRole = new UserRole(); $this->role = new Role(); $roleIdReflection->setValue($this->role, 1); $this->role->setName('role1'); $this->permission = new Permission(); $this->permission->setPermissions(122); $this->permission->setContext('sulu.security.roles'); $this->role->addPermission($this->permission); $this->userRole->setRole($this->role); $this->user->addUserRole($this->userRole); $this->token = $this->prophesize(TokenInterface::class); $this->token->getUser()->willReturn($this->user); $this->accessControlManager = $this->prophesize(AccessControlManagerInterface::class); $this->voter = new SecurityContextVoter($this->accessControlManager->reveal(), $this->permissions); }
public function testPut() { $client = $this->createAuthenticatedClient(); $client->request('PUT', '/api/groups/' . $this->group1->getId(), ['name' => 'Updated Group1', 'parent' => ['id' => $this->group2->getId()], 'roles' => [['id' => $this->role1->getId()]]]); $response = json_decode($client->getResponse()->getContent()); $this->assertEquals('Updated Group1', $response->name); $this->assertEquals($this->group2->getId(), $response->parent->id); $this->assertCount(1, $response->roles); $this->assertEquals('Sulu Administrator', $response->roles[0]->name); $client->request('GET', '/api/groups/' . $this->group1->getId()); $this->assertEquals('Updated Group1', $response->name); $this->assertEquals($this->group2->getId(), $response->parent->id); $this->assertCount(1, $response->roles); $this->assertEquals('Sulu Administrator', $response->roles[0]->name); }
public function testPutWithEmptyPassword() { $client = $this->createAuthenticatedClient(); $client->request('PUT', '/api/users/' . $this->user1->getId(), ['username' => 'manager', 'password' => '', 'locale' => 'en', 'contact' => ['id' => $this->contact1->getId()], 'userRoles' => [['id' => $this->user1->getId(), 'role' => ['id' => $this->role1->getId()], 'locales' => ['de', 'en']], ['id' => 2, 'role' => ['id' => $this->role2->getId()], 'locales' => ['en']]]]); $response = json_decode($client->getResponse()->getContent()); $this->assertEquals('manager', $response->username); $this->assertEquals('securepassword', $response->password); $this->assertEquals($this->contact1->getId(), $response->contact->id); $this->assertEquals('en', $response->locale); $this->assertEquals('Role1', $response->userRoles[0]->role->name); $this->assertEquals('de', $response->userRoles[0]->locales[0]); $this->assertEquals('en', $response->userRoles[0]->locales[1]); $this->assertEquals('Role2', $response->userRoles[1]->role->name); $this->assertEquals('en', $response->userRoles[1]->locales[0]); $refreshedUser = $this->em->getRepository('SuluSecurityBundle:User')->find($this->user1->getId()); $this->assertEquals($this->user1->getSalt(), $refreshedUser->getSalt()); }
private function prepareUser($username, $password, $enabled = true, $locked = false) { $emailType = new EmailType(); $emailType->setName('Private'); $this->em->persist($emailType); $email = new Email(); $email->setEmail('*****@*****.**'); $email->setEmailType($emailType); $this->em->persist($email); $contact1 = new Contact(); $contact1->setFirstName('Max'); $contact1->setLastName('Muster'); $contact1->addEmail($email); $this->em->persist($contact1); $user = new User(); $user->setUsername($username); $user->setPassword($password); $user->setSalt('salt'); $user->setLocale('de'); $user->setContact($contact1); $user->setEnabled($enabled); $user->setLocked($locked); $this->em->persist($user); $role = new Role(); $role->setName('Sulu'); $role->setSystem('Sulu'); $this->em->persist($role); $userRole = new UserRole(); $userRole->setRole($role); $userRole->setUser($user); $userRole->setLocale(''); $this->em->persist($userRole); $this->em->flush(); return $user; }
private function getOrCreateRole($name, $system) { $role = $this->getEntityManager()->getRepository('Sulu\\Bundle\\SecurityBundle\\Entity\\Role')->findOneByName($name); if ($role) { return $role; } $role = new Role(); $role->setName($name); $role->setSystem($system); $pool = $this->getContainer()->get('sulu_admin.admin_pool'); $securityContexts = $pool->getSecurityContexts(); $securityContextsFlat = []; array_walk_recursive($securityContexts['Sulu'], function ($value) use(&$securityContextsFlat) { $securityContextsFlat[] = $value; }); foreach ($securityContextsFlat as $securityContext) { $permission = new Permission(); $permission->setRole($role); $permission->setContext($securityContext); $permission->setPermissions(120); $role->addPermission($permission); } $this->getEntityManager()->persist($role); $this->getEntityManager()->flush(); return $role; }