/**
  * Logout
  */
 public function processOut()
 {
     Logs::set(array('type' => 'LOG', 'message' => 'Logout: ' . _currentUser()->getLogin()));
     CopixAuth::getCurrentUser()->logout(array());
     CopixEventNotifier::notify('logout', array('login' => CopixAuth::getCurrentUser()->getLogin()));
     CopixAuth::destroyCurrentUser();
     CopixSession::destroyNamespace('default');
     return _arRedirect(CopixRequest::get('auth_url_return', _url('||')));
 }
 public function beforeProcess(&$action)
 {
     if (CopixConfig::get('conf_Saml_actif') != 1) {
         return;
     }
     require_once COPIX_UTILS_PATH . '../../simplesamlphp/lib/_autoload.php';
     $asId = 'iconito-sql';
     if (CopixConfig::exists('default|conf_Saml_authSource') && CopixConfig::get('default|conf_Saml_authSource')) {
         $asId = CopixConfig::get('default|conf_Saml_authSource');
     }
     $as = new SimpleSAML_Auth_Simple($asId);
     $ppo->user = _currentUser();
     if ($as->isAuthenticated() && !$ppo->user->isConnected()) {
         $attributes = $as->getAttributes();
         $uidAttribute = 'login_dbuser';
         if (CopixConfig::exists('default|conf_Saml_uidAttribute') && CopixConfig::get('default|conf_Saml_uidAttribute')) {
             $uidAttribute = CopixConfig::get('default|conf_Saml_uidAttribute');
         }
         $ppo->saml_user = null;
         if (isset($attributes[$uidAttribute]) && isset($attributes[$uidAttribute][0])) {
             $ppo->saml_user = $attributes[$uidAttribute][0];
         }
         if ($ppo->saml_user) {
             $ppo->iconito_user = Kernel::getUserInfo("LOGIN", $ppo->saml_user);
             if ($ppo->iconito_user['login']) {
                 _currentUser()->login(array('login' => $ppo->iconito_user['login'], 'assistance' => true));
                 $url_return = CopixUrl::get('kernel||doSelectHome');
                 // $url_return = CopixUrl::get ('assistance||users');
                 return new CopixActionReturn(COPIX_AR_REDIRECT, $url_return);
             } else {
                 $ppo->cas_error = 'no-iconito-user';
                 return _arPpo($ppo, 'cas.tpl');
             }
         }
     }
     if (!$as->isAuthenticated() && $ppo->user->isConnected()) {
         $ppo->user = _currentUser();
         if ($ppo->user->isConnected()) {
             CopixAuth::getCurrentUser()->logout(array());
             CopixEventNotifier::notify('logout', array('login' => CopixAuth::getCurrentUser()->getLogin()));
             CopixAuth::destroyCurrentUser();
             CopixSession::destroyNamespace('default');
         }
     }
 }
 public function processLogout()
 {
     require_once COPIX_UTILS_PATH . '../../simplesamlphp/lib/_autoload.php';
     $asId = 'iconito-sql';
     if (CopixConfig::exists('default|conf_Saml_authSource') && CopixConfig::get('default|conf_Saml_authSource')) {
         $asId = CopixConfig::get('default|conf_Saml_authSource');
     }
     $as = new SimpleSAML_Auth_Simple($asId);
     $ppo = new CopixPPO();
     $ppo->user = _currentUser();
     if ($ppo->user->isConnected()) {
         CopixAuth::getCurrentUser()->logout(array());
         CopixEventNotifier::notify('logout', array('login' => CopixAuth::getCurrentUser()->getLogin()));
         CopixAuth::destroyCurrentUser();
         CopixSession::destroyNamespace('default');
     }
     $as->logout(_url() . 'simplesaml/saml2/idp/initSLO.php?RelayState=' . urlencode(_url('auth|saml|logout_cas')));
     // $as->logout(_url ().'simplesaml/saml2/idp/initSLO.php?RelayState='.urlencode(_url() . 'logout.php'));
 }
 public function processLogout()
 {
     include_once COPIX_UTILS_PATH . '../../CAS-1.2.2/CAS.php';
     $ppo = new CopixPPO();
     $ppo->user = _currentUser();
     if ($ppo->user->isConnected()) {
         CopixAuth::getCurrentUser()->logout(array());
         CopixEventNotifier::notify('logout', array('login' => CopixAuth::getCurrentUser()->getLogin()));
         CopixAuth::destroyCurrentUser();
         CopixSession::destroyNamespace('default');
     }
     phpCAS::setDebug();
     $conf_Cas_host = CopixConfig::get('default|conf_Cas_host');
     $conf_Cas_port = CopixConfig::get('default|conf_Cas_port');
     $conf_Cas_path = CopixConfig::get('default|conf_Cas_path');
     phpCAS::client(CAS_VERSION_2_0, $conf_Cas_host, (int) $conf_Cas_port, $conf_Cas_path, false);
     phpCAS::setNoCasServerValidation();
     phpCAS::forceAuthentication();
     phpCAS::logout();
     return _arRedirect(CopixRequest::get('auth_url_return', _url('||')));
 }
 public function testConnection()
 {
     // Connection avec un utilisateur test présent en base
     $user = CopixAuth::getCurrentUser();
     $this->assertTrue($user->login(array('login' => 'CopixTest', 'password' => 'CopixTestPassword')));
     $this->assertTrue($user->isConnected());
     // Vérifie les infos de copixuser
     $responses = $user->getResponses();
     $this->assertEquals(1, count($responses));
     // Vérifie la première réponse
     $first = $responses[0];
     $this->assertTrue($first->getResult());
     $this->assertEquals("auth|dbuserhandler", $first->getHandler());
     $this->assertEquals("CopixTest", $first->getLogin());
     $this->assertEquals($this->_userId, $first->getId());
     // La méme chose via CopixUser
     $this->assertEquals("auth|dbuserhandler", $user->getHandler());
     $this->assertEquals("CopixTest", $user->getLogin());
     $this->assertEquals($this->_userId, $user->getId());
     // Vérifie IsConnectedAs
     $this->assertTrue($user->IsConnectedAs("auth|dbuserhandler", $this->_userId));
     $this->assertFalse($user->IsConnectedAs("dummyHandler", $this->_userId));
     $this->assertFalse($user->IsConnectedAs("auth|dbuserhandler", $this->_userId + 1));
     // Vérifie isLoggedWith
     $this->assertTrue($user->isLoggedWith('auth|dbuserhandler'));
     $this->assertFalse($user->isLoggedWith('dummyHandler'));
     // Test de la deconnexion
     $user->logout(null);
     $this->assertFalse($user->isConnected());
     // Test de la connection avec un utilisateur présent en base mais avec un mauvais mot de passe
     $this->assertFalse($user->login(array('login' => 'CopixTest', 'password' => 'wrongpass')));
     $this->assertFalse($user->isConnected());
     $this->assertEquals(0, count($user->getResponses()));
     // Test de la connection avec un utilisateur null
     $this->assertFalse($user->login(array()));
     CopixAuth::destroyCurrentUser();
 }