ccovey / ldap-auth
Requires
- php: >=5.3.0
- adldap/adldap: 4.0.x
- illuminate/auth: 4.1.x
- illuminate/config: 4.1.x
- illuminate/support: 4.1.x
Requires (Dev)
- mockery/mockery: dev-master
This package is not auto-updated.
Last update: 2022-02-01 12:24:12 UTC
README
Laravel 4 Active Directory LDAP 认证驱动程序。
安装
这将遵循与 Laravel 本身管理版本类似的方式。当 Laravel 移动到 4.1 时,此包将移动到 1.1,其中小版本表示错误修复等。要安装此包,请将以下内容添加到您的 composer.json 中
require { "ccovey/ldap-auth": "1.1.*", }
然后运行
composer install 或 composer update,具体取决于情况
一旦您从 Packagist.org 下载了包,您需要通知您的应用程序使用 LDAP 服务提供商。
打开 config/app.php 并找到
Illuminate\Auth\AuthServiceProvider
并将其替换为
Ccovey\LdapAuth\LdapAuthServiceProvider
这告诉 Laravel 4 使用来自 vendor 文件夹的服务提供程序。
您还需要将 Auth 指向使用 ldap 驱动程序而不是 Eloquent 或数据库,编辑 config/auth.php 并将驱动程序更改为 ldap
配置
要在 app/config/auth.php 中指定要使用的用户名字段,请设置一个键/值对 'username_field' => 'fieldname'。如果您不提供,则默认为 username。
要设置您的 adLDAP 以连接到您的域控制器,创建一个名为 app/config/adldap.php 的文件。这将提供连接的所有配置值。对于所有配置选项,应提供一个类似于下面的数组。
请注意,唯一必需的选项是 account_suffix、base_dn 和 domain_controllers。其他选项提供安全或更多信息。如果您不想使用其他选项,只需删除它们。
return array( 'account_suffix' => "@domain.local", 'domain_controllers' => array("dc1.domain.local", "dc2.domain.local"), // An array of domains may be provided for load balancing. 'base_dn' => 'DC=domain,DC=local', 'admin_username' => 'user', 'admin_password' => 'password', 'real_primary_group' => true, // Returns the primary group (an educated guess). 'use_ssl' => true, // If TLS is true this MUST be false. 'use_tls' => false, // If SSL is true this MUST be false. 'recursive_groups' => true, );
使用
$guarded 现在默认为所有,因此要使用模型,您必须将其更改为 $guarded = array()。如果您存储角色或类似敏感信息,请确保将其添加到 guarded 数组中。
Auth 的使用方式与默认服务提供程序相同。
默认情况下,这将包含 username (samaccountname)、displayname、primary group 以及用户所属的所有组
要编辑返回的内容,您可以在 config/auth.php 中的 fields 键中指定。
有关 AD 中可用字段的更多信息,请访问 http://goo.gl/6jL4V
您还可以通过定义 userList 键并将其设置为 true 来获取特定 OU 的完整用户列表。您还必须设置 group 键,该键定义了要查看的 OU。请注意,在大型 AD 中,这可能会减慢应用程序的运行速度。
模型使用
如果您愿意,仍然可以使用此实现中的模型。ldap-auth将从ldap获取您的字段并将其附加到模型中,允许您访问例如角色/权限等信息,如果账户在Active Directory中有效。还需要注意的是,所有认证都在模型之外进行。所有的认证都是在Active Directory中完成的,如果它们被从AD中移除但仍然在用户表中,它们将无法登录。