golenishev / yii2-ldap
LDAP
v0.4.0
2019-04-15 19:27 UTC
Requires
- php: >=7.0
- ext-ldap: *
- yiisoft/yii2: ~2.0.14
Requires (Dev)
This package is not auto-updated.
Last update: 2024-10-02 07:24:44 UTC
README
本扩展为 Yii 2.0 框架提供 LDAP 集成。它包括基本的查询/搜索支持,并实现了 ActiveRecord 模式,允许您在 Active Directory 或 OpenLDAP 中存储活动记录。
需求
要使用 yii2-ldap,您的服务器必须支持
PHP LDAP 扩展
安装
安装此扩展的首选方式是通过 composer。
运行以下命令之一:
php composer.phar require --prefer-dist chrmorandi/yii2-ldap
或将其添加到您的 composer.json 文件的 require 部分:
"chrmorandi/yii2-ldap": "*"
配置
return [ //.... 'components' => [ 'ldap' => [ 'class' => 'chrmorandi\ldap\Connection', // Mandatory Configuration Options 'dc' => [ '192.168.1.1', 'ad.com' ], 'baseDn' => 'dc=ad,dc=com', 'username' => 'administrator@ad.com', 'password' => 'password', // Optional Configuration Options 'port' => 389, 'followReferrals' => false, 'useTLS' => true, // Change pageSize (e.g. to 1000) if you are getting the following message // with large result sets: // ldap_search(): Partial search results returned: Sizelimit exceeded 'pageSize' => -1, ], ] ];
用户认证
要使用您的 AD 服务器进行用户认证,请调用您的提供者上的 Yii::$app->ldap->auth()
方法
try { if (Yii::$app->ldap->auth($this->username, $password)) { // Credentials were correct. } else { // Credentials were incorrect. } } catch (Exception $e) { // error }