Ejemplo n.º 1
0
 /**
  * (non-PHPdoc)
  * @see app/modules/AppKit/lib/auth/AppKitIAuthProvider#doAuthenticate()
  */
 public function doAuthenticate(NsmUser $user, $password, $username = null, $authid = null)
 {
     $authid = $user->getAuthId();
     $username = $user->user_name;
     $this->log('Auth.Provider.LDAP Trying authenticate (authkey=%s,user=%s)', $authid, $username, AgaviLogger::DEBUG);
     if ($password == '') {
         $this->log('Auth.Provider.LDAP Empty password given, bind aborted', AgaviLogger::DEBUG);
         return false;
     }
     try {
         // Check if user always is available
         $filter = $this->getSearchFilter($user->user_name);
         if (!$filter) {
             return false;
         }
         $search_record = $this->getLdaprecord($filter);
         if (isset($search_record['dn'])) {
             // Check bind
             $this->log('Auth.Provider.LDAP Trying bind with dn=%s', $search_record['dn'], AgaviLogger::DEBUG);
             $conn = $this->getLdapConnection(false);
             $re = @ldap_bind($conn, $search_record['dn'], $password);
             if ($this->isLdapError($conn) == false && $re === true && ldap_errno($conn) === 0) {
                 $this->log('Auth.Provider.LDAP Successfull bind (dn=%s,user=%s)', $search_record['dn'], $username, AgaviLogger::DEBUG);
                 return true;
             }
         }
     } catch (AgaviSecurityException $e) {
         // PASS
     }
     $this->log('Auth.Provider.LDAP Bind failed (authkey=%s,user=%s)', $authid, $username, AgaviLogger::WARN);
     return false;
 }
 private function updateProfile(NsmUser &$user, AppKitIAuthProvider &$provider)
 {
     $username = $user->user_name;
     $provider_name = $user->user_authsrc;
     $this->log('Auth.Dispatch: Updating profile (user=%s,provider=%s)', $username, $provider_name, AgaviLogger::DEBUG);
     try {
         $provider = $this->getProvider($provider_name);
     } catch (AgaviSecurityException $e) {
         $this->log('Auth.Dispatch: Provider not found for user %s (provider=%s)', $username, $provider_name, AgaviLogger::DEBUG);
         return false;
     }
     $user_data = $provider->getUserdata($username, $user->getAuthId());
     if (is_array($user_data) && count($user_data)) {
         $user_data = $this->secureUpdateValues($user_data);
         $this->log('Auth.Dispatch: Profile data (user=%s,provider=%s) %s', $username, $provider_name, print_r($user_data, true), AgaviLogger::DEBUG);
         $user->synchronizeWithArray($user_data, false);
         if ($user->isModified(false)) {
             $user->save();
         }
         return true;
     }
 }