Exemplo n.º 1
1
 /**
  * Attempts to log the authenticated CAS user into Drupal.
  *
  * This method should be used to login a user after they have successfully
  * authenticated with the CAS server.
  *
  * @param CasPropertyBag $property_bag
  *   CasPropertyBag containing username and attributes from CAS.
  * @param string $ticket
  *   The service ticket.
  *
  * @throws CasLoginException
  *   Thrown if there was a problem logging in the user.
  */
 public function loginToDrupal(CasPropertyBag $property_bag, $ticket)
 {
     // Dispatch an event that allows modules to change user data we received
     // from CAS before attempting to use it to load a Drupal user.
     // Auto-registration can also be disabled for this user if their account
     // does not exist.
     $user_load_event = new CasUserLoadEvent($property_bag);
     $this->eventDispatcher->dispatch(CasHelper::EVENT_USER_LOAD, $user_load_event);
     $account = $this->userLoadByName($property_bag->getUsername());
     if (!$account) {
         $config = $this->settings->get('cas.settings');
         if ($config->get('user_accounts.auto_register') === TRUE) {
             if ($user_load_event->allowAutoRegister) {
                 $account = $this->registerUser($property_bag->getUsername(), $config->get('user_accounts.auto_assigned_roles'));
             } else {
                 throw new CasLoginException("Cannot register user, an event listener denied access.");
             }
         } else {
             throw new CasLoginException("Cannot login, local Drupal user account does not exist.");
         }
     }
     // Dispatch an event that allows modules to prevent this user from logging
     // in and/or alter the user entity before we save it.
     $pre_auth_event = new CasPreAuthEvent($account, $property_bag);
     $this->eventDispatcher->dispatch(CasHelper::EVENT_PRE_AUTH, $pre_auth_event);
     // Save user entity since event listeners may have altered it.
     $account->save();
     if (!$pre_auth_event->allowLogin) {
         throw new CasLoginException("Cannot login, an event listener denied access.");
     }
     $this->userLoginFinalize($account);
     $this->storeLoginSessionData($this->session->getId(), $ticket);
 }
Exemplo n.º 2
0
 /**
  * Attempts to log the authenticated CAS user into Drupal.
  *
  * This method should be used to login a user after they have successfully
  * authenticated with the CAS server.
  *
  * @param CasPropertyBag $property_bag
  *   CasPropertyBag containing username and attributes from CAS.
  *
  * @throws CasLoginException
  */
 public function loginToDrupal(CasPropertyBag $property_bag, $ticket)
 {
     $this->eventDispatcher->dispatch(CasHelper::CAS_PROPERTY_ALTER, new CasPropertyEvent($property_bag));
     $account = $this->userLoadByName($property_bag->getUsername());
     if (!$account) {
         $config = $this->settings->get('cas.settings');
         if ($config->get('user_accounts.auto_register') === TRUE) {
             if (!$property_bag->getRegisterStatus()) {
                 $_SESSION['cas_temp_disable'] = TRUE;
                 throw new CasLoginException("Cannot register user, an event listener denied access.");
             }
             $account = $this->registerUser($property_bag->getUsername());
         } else {
             throw new CasLoginException("Cannot login, local Drupal user account does not exist.");
         }
     }
     $this->eventDispatcher->dispatch(CasHelper::CAS_USER_ALTER, new CasUserEvent($account, $property_bag));
     $account->save();
     if (!$property_bag->getLoginStatus()) {
         $_SESSION['cas_temp_disable'] = TRUE;
         throw new CasLoginException("Cannot login, an event listener denied access.");
     }
     $this->userLoginFinalize($account);
     $this->storeLoginSessionData($this->sessionManager->getId(), $ticket);
 }