Ejemplo n.º 1
0
 /**
  * Set default LDAP Adapter for all new instances.
  *
  * @param	Zmax_Ldap_Adapter	$ldap
  * @return	void
  */
 public static function setDefaultAdapter(Zmax_Ldap_Adapter $ldap = null)
 {
     self::$_defaultLdap = $ldap;
 }
Ejemplo n.º 2
0
 /**
  * check whether a user is connected, and if yes retrieves the user's row
  * and assigns it to the context
  *
  */
 public static function setupUser()
 {
     $user = null;
     $zmax_context = self::getRegistry()->get("zmax_context");
     if (!isset($zmax_context)) {
         throw new Zend_Exception('setupZmaxContext() must be called before ' . __FUNCTION__ . '()');
     }
     $config = $zmax_context->config;
     if (!isset($config)) {
         throw new Zend_Exception('setupConfig() must be called before ' . __FUNCTION__ . '()');
     }
     // Get a reference to the Singleton instance of Zmax_Auth
     $auth = Zend_Auth::getInstance();
     // Check whether an identity exists
     if ($auth->hasIdentity()) {
         $zmax_context->is_authenticated = true;
         // Identity exists; get it
         $identity = $auth->getIdentity();
         if ($config->app->auth->method == "cas") {
             $user_id = $identity['user_id'];
             // Returned by CAS
         } else {
             if ($config->app->auth->method == "couchdb") {
                 $user_id = $identity['user_id'];
                 // Returned by CAS
             } else {
                 if ($config->app->auth->method == "db") {
                     $user_id = $identity;
                     // Returned by DB
                 } else {
                     $user_id = $identity['username'];
                     // Returned by DIGEST
                 }
             }
         }
         // Try to find the user with the source configured in the app ini file
         switch ($zmax_context->config->app->user->source) {
             case 'ldap':
                 $ldap = new Zmax_Ldap_Adapter($zmax_context->config->sector->ldap);
                 Zmax_Ldap_Gateway_Abstract::setDefaultAdapter($ldap);
                 $ldap_user = new Zmax_Model_LdapUser();
                 $res_ldap_user = $ldap_user->findById($user_id);
                 $tab_user = $ldap_user->getAllEntries($res_ldap_user);
                 if (isset($tab_user) && count($tab_user) > 0) {
                     $tmp['user_lname'] = strtoupper($tab_user[0]['lastname']);
                     $tmp['user_fname'] = $tab_user[0]['firstname'];
                     $tmp['user_email'] = strtolower($tab_user[0]['email']);
                     $user = $user_table->initFromArray($tmp);
                 }
                 break;
             case 'db':
                 // by default search in the database
                 if ($zmax_context->config->app->use_database) {
                     // Create an empty object
                     $user_table = new Zmax_Model_User();
                     $user = $user_table->find($user_id)->current();
                 }
                 break;
             case "couchdb":
                 // Check whether an identity exists
                 $user = new Zmax_Couchdb_User($zmax_context->db);
                 $user->setId($user_id);
                 $user->load();
                 break;
         }
         if (is_object($user)) {
             $zmax_context->user = $user;
         } else {
             $zmax_context->user = null;
         }
     } else {
         $zmax_context->is_authenticated = false;
     }
 }