插件配置
Plugin configuration
我正在创建可以使用 LDAP 或回退到自定义解决方案的用户身份验证插件。
LDAP需要域、协议、baseDN等一系列信息。
我想知道对于这样的插件最好的配置方法是什么?
我认为使用 bootstrap.php
文件是最好的,因为这是大多数插件使用的类似方式。
示例 bootstrap 配置:
Configure::write('UserAuth.config', [
'protocol' => 'ldap://',
'domain' => 'example.net',
'basedn' => 'dc=example,dc=net',
]);
我的一位同事建议使用 InstanceConfigTrait
作为一种可以在另一点覆盖的默认配置的方法。
示例 InstanceConfigTrait 配置:
protected $_defaultConfig = [
'protocol' => '',
'domain' => '',
'basedn' => '',
];
我理解他为什么建议使用 InstanceConfigTrait,但实际上没有默认配置,因为 LDAP 只有在您拥有正确信息的情况下才能使用。
有什么想法吗?
Auth 适配器应该以相同的方式工作,所以当您 create them . BaseAuthenticate and Authorize are already using the instance config trait. When you configure them 配置数据被传递到那里。
我会留给应用程序的开发人员(并将 LDAP 作为插件)如何将他的配置传递给适配器。当像在提供的链接中那样配置身份验证时,这可以在 AppController::initialize() 中轻松完成。
public function initialize()
{
parent::initialize();
$this->loadComponent('Auth', [
'authenticate' => [
'Ldap.Ldap' => [
'protocol' => 'ldap://',
'domain' => 'example.net',
'basedn' => 'dc=example,dc=net',
]
]
]);
}
要么在那里硬编码,要么简单地使用 Configure::read()
public function initialize()
{
parent::initialize();
$this->loadComponent('Auth', [
'authenticate' => [
'Ldap.Ldap' => Configure::read('Ldap.connection')
]
]);
}
我正在创建可以使用 LDAP 或回退到自定义解决方案的用户身份验证插件。
LDAP需要域、协议、baseDN等一系列信息。
我想知道对于这样的插件最好的配置方法是什么?
我认为使用 bootstrap.php
文件是最好的,因为这是大多数插件使用的类似方式。
示例 bootstrap 配置:
Configure::write('UserAuth.config', [
'protocol' => 'ldap://',
'domain' => 'example.net',
'basedn' => 'dc=example,dc=net',
]);
我的一位同事建议使用 InstanceConfigTrait
作为一种可以在另一点覆盖的默认配置的方法。
示例 InstanceConfigTrait 配置:
protected $_defaultConfig = [
'protocol' => '',
'domain' => '',
'basedn' => '',
];
我理解他为什么建议使用 InstanceConfigTrait,但实际上没有默认配置,因为 LDAP 只有在您拥有正确信息的情况下才能使用。
有什么想法吗?
Auth 适配器应该以相同的方式工作,所以当您 create them . BaseAuthenticate and Authorize are already using the instance config trait. When you configure them 配置数据被传递到那里。
我会留给应用程序的开发人员(并将 LDAP 作为插件)如何将他的配置传递给适配器。当像在提供的链接中那样配置身份验证时,这可以在 AppController::initialize() 中轻松完成。
public function initialize()
{
parent::initialize();
$this->loadComponent('Auth', [
'authenticate' => [
'Ldap.Ldap' => [
'protocol' => 'ldap://',
'domain' => 'example.net',
'basedn' => 'dc=example,dc=net',
]
]
]);
}
要么在那里硬编码,要么简单地使用 Configure::read()
public function initialize()
{
parent::initialize();
$this->loadComponent('Auth', [
'authenticate' => [
'Ldap.Ldap' => Configure::read('Ldap.connection')
]
]);
}