provide fallback for login if authmethod fails

This commit is contained in:
Klaus Leithoff 2012-01-16 16:57:14 +00:00
parent 06265cee4e
commit e35a4f9dbb
2 changed files with 28 additions and 5 deletions

View File

@ -432,15 +432,33 @@ class Net_Sieve
}
switch ($method) {
case 'DIGEST-MD5':
//$result = $this->_authDigest_MD5( $uid , $pwd , $euser );
//return $result;
//break;
$result = $this->_authDigest_MD5( $uid , $pwd , $euser );
return $result;
break;
if ( !PEAR::isError($result)) break;
$res = $this->_doCmd();
unset($this->_error);
$this->supportedAuthMethods = array_diff($this->supportedAuthMethods,array($method,'CRAM-MD5'));
return $this->_cmdAuthenticate($uid , $pwd, null, $euser);
case 'CRAM-MD5':
//$result = $this->_authCRAM_MD5( $uid , $pwd, $euser);
//break;
$result = $this->_authCRAM_MD5( $uid , $pwd, $euser);
break;
if ( !PEAR::isError($result)) break;
$res = $this->_doCmd();
unset($this->_error);
$this->supportedAuthMethods = array_diff($this->supportedAuthMethods,array($method,'DIGEST-MD5'));
return $this->_cmdAuthenticate($uid , $pwd, null, $euser);
case 'LOGIN':
//$result = $this->_authLOGIN( $uid , $pwd , $euser );
//break;
$result = $this->_authLOGIN( $uid , $pwd , $euser );
break;
if ( !PEAR::isError($result)) break;
$res = $this->_doCmd();
unset($this->_error);
$this->supportedAuthMethods = array_diff($this->supportedAuthMethods,array($method));
return $this->_cmdAuthenticate($uid , $pwd, null, $euser);
case 'PLAIN':
$result = $this->_authPLAIN( $uid , $pwd , $euser );
break;
@ -448,7 +466,7 @@ class Net_Sieve
$result = new PEAR_Error( "$method is not a supported authentication method" );
break;
}
if (PEAR::isError($result)) return $result;
if (PEAR::isError($res = $this->_doCmd() )) {
return $res;
}

View File

@ -68,6 +68,7 @@ class emailadmin_sieve extends Net_Sieve
function _connect($_icServer,$euser='')
{
static $isConError;
static $sieveAuthMethods;
$_icServerID = $_icServer->ImapServerId;
if (is_null($isConError)) $isConError =& egw_cache::getCache(egw_cache::INSTANCE,'email','icServerSIEVE_connectionError'.trim($GLOBALS['egw_info']['user']['account_id']),$callback=null,$callback_params=array(),$expiration=60*15);
if ( isset($isConError[$_icServerID]) )
@ -109,6 +110,10 @@ class emailadmin_sieve extends Net_Sieve
egw_cache::setCache(egw_cache::INSTANCE,'email','icServerSIEVE_connectionError'.trim($GLOBALS['egw_info']['user']['account_id']),$isConError,$expiration=60*15);
return false;
}
// we cache the supported AuthMethods during session, to be able to speed up login.
if (is_null($sieveAuthMethods)) $sieveAuthMethods =& egw_cache::getSession('email','sieve_supportedAuthMethods');
if (isset($sieveAuthMethods[$_icServerID])) $this->supportedAuthMethods = $sieveAuthMethods[$_icServerID];
if(PEAR::isError($this->error = $this->login($username, $password, null, $euser) ) ){
if ($this->debug) error_log(__CLASS__.'::'.__METHOD__.array2string($this->icServer));
if ($this->debug) error_log(__CLASS__.'::'.__METHOD__.": error in login($username,$password,null,$euser): ".$this->error->getMessage());