aravind-zrx / cakephp-ldap
cakephp 的 LDAP 工具插件
0.1
2017-11-22 07:51 UTC
Requires
- cakephp/cakephp: >3.1
This package is auto-updated.
Last update: 2024-09-23 02:41:14 UTC
README
需求
- CakePHP 3.1+
安装
您可以使用 composer 将此插件安装到您的 CakePHP 应用程序中。
安装 composer 包的推荐方法是
composer require aravind-zrx/Cakephp-ldap
使用方法
在您的应用程序的 config/bootstrap.php 中添加
// In config/bootstrap.php Plugin::load('LdapUtility');
或者使用 cake 的控制台
./bin/cake plugin load LdapUtility
配置
创建 ldap 处理器实例的基本配置
$config = [ 'host' => 'ldap.example.com', 'port' => 389, 'baseDn' => 'dc=example,dc=com', 'startTLS' => true, 'hideErrors' => true, 'commonBindDn' => 'cn=readonly.user,ou=people,dc=example,dc=com', 'commonBindPassword' => 'secret' ] $ldapHandler = new LdapUtility\Ldap($config);
配置参数
在控制器中设置 Ldap 认证配置
设置 LDAP 认证的参数包括 LDAP 处理器连接的所有参数,除了 commonBindDn 和 commonBindPassowrd
// In your controller, for e.g. src/Api/UsersController.php public function initialize() { parent::initialize(); $this->loadComponent('Auth', [ 'storage' => 'Memory', 'authenticate', [ LdapUtility/Ldap => [ 'host' => 'ldap.example.com', 'port' => 389, 'baseDn' => 'dc=example,dc=com', 'startTLS' => true, 'hideErrors' => true, 'queryDatasource' => true, 'userModel' => 'Users', 'fields' => ['username' => 'email'], 'auth' => [ 'searchFilter' => '(cn={username})', 'bindDn' => 'cn={username},ou=people,dc=example,dc=com' ] ] ], 'unauthorizedRedirect' => false, 'checkAuthIn' => 'Controller.initialize', ]); }
认证特定配置
示例
搜索以 cn 开头的条目
$ldapHandler->find('search', [ 'baseDn' => 'ou=people,dc=example,dc=com', 'filter' => 'cn=test*', 'attributes' => ['cn', 'sn', 'mail'] ]);
读取特定的条目,cn=test.user
$ldapHandler->find('read', [ 'baseDn' => 'ou=people,dc=example,dc=com', 'filter' => 'cn=test.user', 'attributes' => ['cn', 'sn', 'mail'] ]);
开发环境中的 TLS 连接
To connect an LDAP server over TLS connection, check ldap.conf file
* For mac, conf file is located in /etc/openldap/ldap.conf
* For unix, conf file is located in /etc/ldap/ldap.conf
To disable certificate verification change TLS_REQCERT to 'never' in ldap.conf file