factorenergia/yii2-ldap

LDAP

安装次数: 12,281

依赖: 0

建议者: 0

安全性: 0

星标: 1

关注者: 1

分支: 12

类型:yii2-extension

2.0.0 2020-05-05 09:07 UTC

This package is auto-updated.

Last update: 2024-09-05 18:36:18 UTC


README

本扩展为 Yii 框架 2.0 提供LDAP集成功能。它包括基本的查询/搜索支持和实现了ActiveRecord模式,允许您将活动记录存储在Active Directory或OpenLDAP中。

要求

要使用yii2-ldap,您的服务器必须支持

PHP LDAP 扩展

安装

安装此扩展的首选方式是通过 Composer

运行以下命令之一

php composer.phar require --prefer-dist factorenergia/yii2-ldap

或者

"factorenergia/yii2-ldap": "*"

将以下内容添加到您的composer.json文件的require部分。

配置

return [
    //....
    'components' => [
        'ldap' => [
            'class' => 'factorenergia\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
}