yetopen / yii2-usuario-ldap
为yii2-usuario添加LDAP认证(和同步)的Yii2扩展
v1.3.11
2024-05-20 10:03 UTC
Requires
- 2amigos/yii2-usuario: ^1.6.0
- adldap2/adldap2: ^10.4.3
- kartik-v/yii2-krajee-base: *
- yiisoft/yii2: ~2.0.0
README
为2amigos/yii2-usuario提供认证和/或同步用户的yii2扩展。
安装
通过composer安装此扩展是首选方式。
运行
php composer.phar require --prefer-dist yetopen/yii2-usuario-ldap "*"
或在您的composer.json
文件的require部分添加
"yetopen/yii2-usuario-ldap": "*"
。
配置
在您的配置文件中添加(对于基本应用是config/web.php
),调整参数以适应您的设置。
//... 'bootstrap' => ['log', 'usuarioLdap'], //... 'components' => [ //... 'usuarioLdap' => [ 'class' => 'yetopen\usuarioLdap\UsuarioLdapComponent', 'ldapConfig' => [ 'hosts' => ['host.example.com'], 'base_dn' => 'dc=mydomain,dc=local', 'account_prefix' => 'cn=', 'account_suffix' => ',ou=Users,dc=mydomain,dc=local', 'use_ssl' => true, 'username' => 'bind_username', 'password' => 'bind_password', ], 'createLocalUsers' => TRUE, 'defaultRoles' => ['standardUser'], 'syncUsersToLdap' => TRUE, 'secondLdapConfig' => [ 'hosts' => ['host.example.com'], 'base_dn' => 'dc=mydomain,dc=local', 'account_prefix' => 'cn=', 'account_suffix' => ',ou=Users,dc=mydomain,dc=local', 'username' => 'bind_username', 'password' => 'bind_password', ], 'allowPasswordRecovery' => FALSE, 'passwordRecoveryRedirect' => ['/controller/action'] ], //... ]
配置选项
- ldapConfig: 连接到LDAP服务器所需的所有参数,如Adldap2中所述
- createLocalUsers: 如果为TRUE,当用户成功验证第一个LDAP服务器时,将在Yii数据库中本地创建用户。如果为FALSE,则使用在
defaultUserId
中指定的ID使用默认用户进行会话 - defaultRoles: 如果指定,则将角色分配给由扩展创建的用户。可以是数组。默认为FALSE
- secondLdapConfig: 如果指定,则用作同步本地用户的LDAP服务器。如果没有指定,则等于ldapConfig
- syncUsersToLdap: 如果为TRUE,则将本地用户的变化同步到第二个LDAP服务器。这包括创建和删除用户
- defaultUserId: 如果
createLocalUsers
设置为FALSE,则必须包含用于本地的用户ID。默认为-1
- allowPasswordRecovery: 如果为TRUE,则将启用密码恢复过程,否则将重定向LDAP用户到在
passwrdRecoveryRedirect
中指定的URL。默认为FALSE。 - passwordRecoveryRedirect: 当
allowPasswordRecovery
设置为FALSE时,指定用户在尝试恢复密码时将被重定向到的URL。此参数将由yii\helpers\Url::to()处理。 - logCategory: 这是当模块记录某些内容时传递的日志分类,默认为YII2_USUARIO_LDAP
日志配置
要在一个单独的文件中记录有关模块的所有消息,请在日志配置文件的targets
下进行配置。
[ 'class' => 'yii\log\FileTarget', // or another target if you prefer // Gets all the log and exceptions messages of the module 'categories' => [ 'YII2_USUARIO_LDAP', 'yetopen\usuarioLdap\NoLdapUserException', 'yetopen\usuarioLdap\LdapConfigurationErrorException', 'yetopen\usuarioLdap\MultipleUsersFoundException', 'yetopen\usuarioLdap\RoleNotFoundException', ], 'logFile' => '@runtime/logs/usuario_ldap.log', // or the log file destination that you prefer ]