/** * Creates a user for the specified group, and authenticates a BBUserToken. * * @param string $groupId * * @return \BackBee\Security\Token\BBUserToken */ protected function createAuthUser($groupId, $roles = array('ROLE_API_USER')) { $token = new BBUserToken($roles); $user = new User(); $user->setEmail('*****@*****.**')->setLogin('admin')->setPassword('pass')->setApiKeyPrivate(uniqid("PRIVATE", true))->setApiKeyPublic(uniqid("PUBLIC", true))->setApiKeyEnabled(true); $group = $this->getBBApp()->getEntityManager()->getRepository('BackBee\\Security\\Group')->findOneBy(array('_name' => $groupId)); if (!$group) { $group = new Group(); $group->setName($groupId); $this->getBBApp()->getEntityManager()->persist($group); $this->getBBApp()->getEntityManager()->flush($group); } $user->addGroup($group); $token->setAuthenticated(true); $token->setUser($user)->setCreated(new \DateTime())->setLifetime(300); $this->getSecurityContext()->setToken($token); return $user; }