【问题标题】:How to setup multiple authentication adapters with fallback如何使用回退设置多个身份验证适配器
【发布时间】:2013-08-06 16:08:47
【问题描述】:

我正在尝试设置 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()
    {
        ...
    }  

}

我还将它作为可调用的形式包含在 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 回退到下一个适配器?

【问题讨论】:

    标签: zend-framework2 zfcuser


    【解决方案1】:

    问题在这里修复https://github.com/SocalNick/ScnSocialAuth/issues/123

    对我来说,我只是关注了 matwright(github) 的响应(参见 https://github.com/matwright/ScnSocialAuth),所以我替换了两个文件:

    1. socalnick/src/ScnSocialAuth/Controller/Plugin/ScnSocialAuthProvider.php by ScnSocialAuthProvider.php
    2. socalnick/src/ScnSocialAuth/Controller/UserController.php by UserController.php

    在 zfcuser.global.php 中:

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

    希望对您有所帮助...

    【讨论】:

      猜你喜欢
      • 2014-11-25
      • 2023-03-15
      • 2018-11-17
      • 2016-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多