您可以创建自己的适配器/存储类,实现 Zend_Auth_Adpater_Interface 和 Zend_Auth_Storage_Interface
在这些类中,您可以重用原始适配器(如 LDAP)或存储,并且只编写实现您的身份验证规则的代码。
例如,为 Zend_Auth_Adapter 使用多个源:
<?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
}
}
}
我不确定是否理解您的登录规则,但 Storage 类的概念仍然相同:
<?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
通过此实现,您可以拥有多个凭证源和多个会话存储引擎(cookie、会话、数据库或任何您想要使用的)。
对于您的 acl 问题,您可以在您的控制器插件中获取 LDAP 组,并将其存储在您需要的任何地方,在身份验证后。然后,您可以使用第二个插件检查每个请求的 ACL。