lib: Add AuthChain::setSkipExternalBackends() in favor of setIteratorMode()

There's only one mode.

refs #9660
This commit is contained in:
Eric Lippmann 2015-07-29 16:18:30 +02:00
parent 3ca85f9daa
commit c3a057dbdb
2 changed files with 14 additions and 20 deletions

View File

@ -85,7 +85,7 @@ class LoginForm extends Form
{
$auth = Auth::getInstance();
$authChain = $auth->getAuthChain();
$authChain->setIteratorMode($authChain::IT_MODE_NOT_EXTERNAL);
$authChain->setSkipExternalBackends(true);
$user = new User($this->getElement('username')->getValue());
$password = $this->getElement('password')->getValue();
$authenticated = $authChain->authenticate($user, $password);
@ -107,6 +107,7 @@ class LoginForm extends Form
. ' Please check the system log or Icinga Web 2 log for more information.'
));
break;
/** @noinspection PhpMissingBreakStatementInspection */
case $authChain::ENOTALL:
$this->addError($this->translate(
'Please note that not all authentication methods were available.'

View File

@ -53,13 +53,6 @@ class AuthChain implements Authenticatable, Iterator
*/
const ENOTALL = 4;
/**
* External user backends are excluded by the iterator
*
* @var int
*/
const IT_MODE_NOT_EXTERNAL = 1;
/**
* User backends configuration
*
@ -82,11 +75,11 @@ class AuthChain implements Authenticatable, Iterator
protected $error;
/**
* Mode of iteration
* Whether external user backends should be skipped on iteration
*
* @var int
* @var bool
*/
protected $iteratorMode;
protected $skipExternalBackends = false;
/**
* Create a new authentication chain from config
@ -159,25 +152,25 @@ class AuthChain implements Authenticatable, Iterator
}
/**
* Get the iterator mode
* Get whether to skip external user backends on iteration
*
* @return int
* @return bool
*/
public function getIteratorMode()
public function getSkipExternalBackends()
{
return $this->iteratorMode;
return $this->skipExternalBackends;
}
/**
* Set the iterator mode
* Set whether to skip external user backends on iteration
*
* @param int $iteratorMode
* @param bool $skipExternalBackends
*
* @return $this
*/
public function setIteratorMode($iteratorMode)
public function setSkipExternalBackends($skipExternalBackends = true)
{
$this->iteratorMode = (int) $iteratorMode;
$this->skipExternalBackends = (bool) $skipExternalBackends;
return $this;
}
@ -254,7 +247,7 @@ class AuthChain implements Authenticatable, Iterator
return $this->valid();
}
if ($this->iteratorMode === static::IT_MODE_NOT_EXTERNAL
if ($this->getSkipExternalBackends()
&& $backend instanceof ExternalBackend
) {
$this->next();