Example #1
0
 public static function createSampleUser($forename, $surname, $dn)
 {
     $u = new User();
     $u->setForename($forename);
     $u->setSurname($surname);
     $u->setCertificateDn($dn);
     $u->setAdmin(FALSE);
     return $u;
 }
Example #2
0
 //     if(isset($rightWhiteDNs[rtrim($dn)])) {
 //     	echo "Identical DN inserted apart from right hand whitespace: "
 //     			. $dn . "-----------\r\n";
 //     	continue;
 //     }
 //     $rightWhiteDNs[rtrim($dn)] = true;
 $doctrineUser = new User();
 $doctrineUser->setForename((string) $user->FORENAME);
 $doctrineUser->setSurname((string) $user->SURNAME);
 $doctrineUser->setTitle((string) $user->TITLE);
 $doctrineUser->setEmail((string) $user->EMAIL);
 $doctrineUser->setTelephone((string) $user->TEL);
 $doctrineUser->setWorkingHoursStart((string) $user->WORKING_HOURS_START);
 $doctrineUser->setWorkingHoursEnd((string) $user->WORKING_HOURS_END);
 //$doctrineUser->setCertificateDn((string) $user->CERTDN);
 $doctrineUser->setCertificateDn($dn);
 $doctrineUser->setAdmin(false);
 //  echo "DN is " . (string) $doctrineUser->getCertificateDn() . ".\r\n";
 // Roughly half of users don't have a home site set
 if ($user->HOMESITE != "" && !isBad($user->HOMESITE)) {
     // get the home site entity
     $dql = "SELECT s from Site s WHERE s.shortName = ?1";
     $homeSites = $entityManager->createQuery($dql)->setParameter(1, (string) $user->HOMESITE)->getResult();
     /* Error checking: ensure each "home site" refers to exactly
      * one home site */
     if (count($homeSites) !== 1) {
         throw new Exception(count($homeSites) . " sites found with short name: " . $user->HOMESITE . ". user DN is  " . $user->CERTDN);
     }
     foreach ($homeSites as $result) {
         $homeSite = $result;
     }
Example #3
0
 /**
  * Update a user's DN
  * @param \User $user user to have DN updated
  * @param string $dn new DN
  * @param \User $currentUser User doing the updating
  * @throws \Exception
  * @throws \org\gocdb\services\Exception
  */
 public function editUserDN(\User $user, $dn, \User $currentUser = null)
 {
     //Authorisation - only GOCDB Admins shoud be able to change DNs (Throws exception if not)
     $this->checkUserIsAdmin($currentUser);
     //Check the DN is changed
     if ($dn == $user->getCertificateDn()) {
         throw new \Exception("The specified certificate DN is the same as the current DN");
     }
     //Check the DN is unique (if not null)
     if (!is_null($this->getUserByPrinciple($dn))) {
         throw new \Exception("DN is already registered in GOCDB");
     }
     //Validate the DN
     $dnInAnArray['CERTIFICATE_DN'] = $dn;
     $this->validateUser($dnInAnArray);
     //Explicity demarcate our tx boundary
     $this->em->getConnection()->beginTransaction();
     try {
         $user->setCertificateDn($dn);
         $this->em->merge($user);
         $this->em->flush();
         $this->em->getConnection()->commit();
     } catch (\Exception $e) {
         $this->em->getConnection()->rollback();
         $this->em->close();
         throw $e;
     }
 }