如何使用回退设置多个身份验证适配器

时间:2013-08-06 16:08:48

标签: zend-framework2 zfcuser

我正在尝试设置ZfcUser以通过回退到LDAP进行身份验证。我的zfcuser.global.php包含:

'auth_adapters' => array( 
    100 => 'ZfcUser\Authentication\Adapter\Db', 
    99 => 'ZfcUser\Authentication\Adapter\Ldap', 
),

我已经使用以下设置创建了一个Ldap.php作为AbstractAdapter。为简洁起见,我删除了功能代码:

namespace ZfcUser\Authentication\Adapter;

use DateTime;
use Zend\Authentication\Result as AuthenticationResult;
use Zend\ServiceManager\ServiceManagerAwareInterface;
use Zend\ServiceManager\ServiceManager;
use Zend\Session\Container as SessionContainer;
use ZfcUser\Authentication\Adapter\AdapterChainEvent as AuthEvent;
use ZfcUser\Mapper\User as UserMapperInterface;
use ZfcUser\Options\AuthenticationOptionsInterface;


class Ldap extends AbstractAdapter implements ServiceManagerAwareInterface
{
    protected $mapper;
    protected $serviceManager;
    protected $options;

    public function authenticate(AuthEvent $e)
    {
        ...
    }

    public function getMapper()
    {
        ...
    }

    public function setMapper(UserMapperInterface $mapper)
    {
        ...
    }

    public function getServiceManager()
    {
        return $this->serviceManager;
    }

    public function setServiceManager(ServiceManager $serviceManager)
    {
        $this->serviceManager = $serviceManager;
    }

    public function setOptions(AuthenticationOptionsInterface $options)
    {
        $this->options = $options;
    }

    public function getOptions()
    {
        ...
    }  

}

我还将它作为invokable包含在Module.php文件中:

public function getServiceConfig()
{
    return array(
        'invokables' => array(
            'ZfcUser\Authentication\Adapter\Db' => 'ZfcUser\Authentication\Adapter\Db',
            'ZfcUser\Authentication\Adapter\Ldap' => 'ZfcUser\Authentication\Adapter\Ldap',
            ...
        ),
        ...
 }

如果我翻转优先级值,它会更改谁可以登录。无论先执行哪个适配器都允许登录,但其他适配器永远不会被使用。任何人都知道如果第一个适配器失败,如何让ZfcUser回退到下一个适配器?

1 个答案:

答案 0 :(得分:0)

此处修复了问题https://github.com/SocalNick/ScnSocialAuth/issues/123

对我来说,我只是遵循了matwright(github)的回复(见https://github.com/matwright/ScnSocialAuth),所以我更换了两个文件:

  1. socalnick / src / ScnSocialAuth / Controller / Plugin / ScnSocialAuthProvider.php ScnSocialAuthProvider.php
  2. socalnick / src / ScnSocialAuth / Controller / UserController.php UserController.php
  3. 在zfcuser.global.php中:

    'auth_adapters' => array( 100 => 'ZfcUser\Authentication\Adapter\Db', ),

    希望这有帮助...

相关问题