public function setUp()
 {
     if (self::$DefaultGroups === null) {
         self::$DefaultGroups = array();
         $conf = UMManager::getConfiguration('EyeosSQLPrincipalsManager');
         foreach ($conf->defaultGroups->group as $group) {
             self::$DefaultGroups[] = (string) $group['name'];
         }
     }
     $uManager = UMManager::getInstance();
     $this->group0 = $uManager->getNewGroupInstance();
     $this->group0->setName('group0');
     $uManager->createGroup($this->group0);
     $this->user0 = $uManager->getNewUserInstance();
     $this->user0->setName('userLogin0');
     $this->user0->setPassword('userPassword0', true);
     $this->user0->setPrimaryGroupId($this->group0->getId());
     $uManager->createUser($this->user0);
     $this->user1 = $uManager->getNewUserInstance();
     $this->user1->setName('userLogin1');
     $this->user1->setPassword('userPassword1', true);
     $this->user1->setPrimaryGroupId($this->group0->getId());
     $uManager->createUser($this->user1);
     $this->authConfig = new XMLAuthConfiguration(SYSTEM_CONF_PATH . '/' . SERVICES_DIR . '/' . SERVICE_UM_DIR . '/' . SERVICE_UM_AUTHCONFIGURATIONS_DIR . '/eyeos_default.xml');
 }
 public function setUp()
 {
     $this->fixture = UMManager::getInstance();
     if (self::$DefaultGroups === null) {
         self::$DefaultGroups = array();
         $conf = UMManager::getConfiguration('EyeosSQLPrincipalsManager');
         foreach ($conf->defaultGroups->group as $group) {
             $groupObj = $this->fixture->getGroupByName((string) $group['name']);
             self::$DefaultGroups[$groupObj->getId()] = $groupObj;
         }
     }
     if (self::$InitGroups === null) {
         self::$InitGroups = array();
         foreach ($GLOBALS['eyeos_UnitTests']['initGroupNames'] as $groupName) {
             $groupObj = $this->fixture->getGroupByName($groupName);
             self::$InitGroups[$groupObj->getId()] = $groupObj;
         }
     }
     if (self::$InitUsers === null) {
         self::$InitUsers = array();
         foreach ($GLOBALS['eyeos_UnitTests']['initUserNames'] as $userName) {
             $userpObj = $this->fixture->getUserByName($userName);
             self::$InitUsers[$userpObj->getId()] = $userpObj;
         }
     }
     $this->tearDown();
     $this->group0 = $this->fixture->getNewGroupInstance();
     $this->group0->setName('group0');
     $this->fixture->createGroup($this->group0);
     $this->user0 = $this->fixture->getNewUserInstance();
     $this->user0->setName('user0');
     $this->user0->setPassword('password0', true);
     $this->user0->setPrimaryGroupId($this->group0->getId());
     $this->fixture->createUser($this->user0);
 }
 /**
  * Creates a user.
  *
  * @param IUser $user
  * @throws EyeUMException User already exists.
  */
 public function createUser(IUser $user)
 {
     if (!$user instanceof AbstractEyeosUser) {
         throw new EyeInvalidArgumentException($user);
     }
     if ($user->getName() == '') {
         throw new EyeInvalidArgumentException('Cannot create a user with an empty name.');
     }
     self::checkPrincipalName($user->getName());
     SecurityManager::getInstance()->checkPermission($user, new SimplePermission('', array('create')));
     $primaryGroupId = $user->getPrimaryGroupId();
     if ($primaryGroupId === null) {
         throw new EyeInvalidArgumentException('Cannot create user "' . $user->getName() . '" without a primary group.');
     } else {
         try {
             $this->getGroupById($primaryGroupId);
         } catch (EyeNoSuchGroupException $e) {
             throw new EyeInvalidArgumentException('Given primary group ID "' . $primaryGroupId . '" does not match any existing group.');
         }
     }
     try {
         try {
             $this->eyeosDAO->create($user);
         } catch (EyeIntegrityConstraintViolationException $e) {
             throw new EyeUserAlreadyExistsException('User "' . $user->getName() . '" already exists.', 0, $e);
         }
         $primaryGroup = $this->getGroupById($primaryGroupId);
         $this->addToGroup($user, $primaryGroup);
         //add to default groups
         $conf = UMManager::getConfiguration(__CLASS__);
         foreach ($conf->defaultGroups->group as $group) {
             $groupName = (string) $group['name'];
             $secondaryGroup = $this->getGroupByName($groupName);
             $this->addToGroup($user, $secondaryGroup);
         }
     } catch (Exception $e) {
         //{
         //TODO: rollback
         //}
         if ($e instanceof EyeUMException) {
             throw $e;
         }
         throw new EyeUMException('Unable to create user "' . $user->getName() . '".', 0, $e);
     }
 }