Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Zend_身份验证链接适配器和所有权角色acl_Php_Zend Framework_Zend Auth_Zend Acl - Fatal编程技术网

Php Zend_身份验证链接适配器和所有权角色acl

Php Zend_身份验证链接适配器和所有权角色acl,php,zend-framework,zend-auth,zend-acl,Php,Zend Framework,Zend Auth,Zend Acl,我设置了一个Zend_Acl和Zend_Auth方案,其中用户使用Zend_Auth_Adapter_Ldap进行身份验证,并存储在会话中。我使用一个控制器插件来检查$auth->hasintity()和$acl->isAllowed()是否显示登录表单(如果需要) 除了Zend_Auth中的会话检查之外,我想做的是添加登录cookie(我的实现)和API密钥。我还需要在用户创建的内容上将角色切换为“所有者” 我关注的是: 只有在常规会话身份验证失败时,登录cookie才应用作回退,因此应验证

我设置了一个Zend_Acl和Zend_Auth方案,其中用户使用Zend_Auth_Adapter_Ldap进行身份验证,并存储在会话中。我使用一个控制器插件来检查
$auth->hasintity()
$acl->isAllowed()
是否显示登录表单(如果需要)

除了Zend_Auth中的会话检查之外,我想做的是添加登录cookie(我的实现)和API密钥。我还需要在用户创建的内容上将角色切换为“所有者”

我关注的是:

  • 只有在常规会话身份验证失败时,登录cookie才应用作回退,因此应验证会话
  • 如果登录cookie和会话cookie都失败,则应使用API键作为回退
  • 我不想将密码存储在任何地方,它应该只驻留在LDAP中
  • 我需要标识的持久存储,因为若并没有完整的用户名和密码,在LDAP中查找它是不可能的
  • 该角色既取决于LDAP组成员身份(需要持久存储),也取决于该身份是否应被视为内容的所有者(这意味着它在两个请求之间发生变化,除非是admin)

使用Zend Framework MVC和Zend_Auth+Zend_Acl解决这个问题的好模式/方法是什么?

通过实现Zend_Auth_Adpater_接口和Zend_Auth_storage_接口,您可以创建自己的适配器/存储类

在这些类中,您可以重用原始适配器(如LDAP)或存储,并且只编写实现身份验证规则的代码

例如,为Zend_Auth_适配器使用多个源:

<?php 
class My_Auth_Adapter implements Zend_Auth_Adapter_Interface
{
    private $ldapAdapter;
    private $cookieAdapter;
    private $apiKeyAdapter;

    public function __construct($ldapAdapter, $cookieAdapter, $apiKeyAdapter) {
    {
        $this->ldapAdapter = $ldapAdapter;
        $this->cookieAdapter = $cookieAdapter;
        $this->apyKeyAdapter = $apiKeyAdapter;
    }
    public function authenticate()
    {
         if ($this->ldapAdapter->authenticate()) {
             //return the Zend_Auth_Restult
         } elseif ($this->cookieAdapter->authenticate() {
            //return the result
         } elseif ($this->apiKeyAdapter->authenticate() {
           //return the result
         } else {
           //Create and return a Zend_Auth_Result which prevents logging in
          }
     }
}

 <?php 
 class My_Auth_Storage implements Zend_Auth_Storage_Interface
  private $sessionStorage;
  private $cookieStorage;
  private $apiStorage;

  public function read()
  {
      if (!$this->sessionStorage->isEmpty())
      {
           return $this->sessionStorage->read();
      } elseif (!$this->cookieStorage->isEmpty())
      { 
           return $this->cookieStorage->read();
      } //And so one, do not forget to implement all the interface's methods