fawno / ntlm-authentication
为 CakePHP 4.3 提供的 NTLM 认证器
1.0.0
2022-04-25 23:45 UTC
Requires
- php: >=7.2
- cakephp/authentication: 2.*
- cakephp/cakephp: ^4.3
Requires (Dev)
- phpunit/phpunit: ~8.5.0 || ^9.3
Suggests
- ext-ldap: *
This package is auto-updated.
Last update: 2024-08-26 08:13:04 UTC
README
为 CakePHP 4 认证插件提供的 NTLM 认证器
此插件为 CakePHP 4 认证插件提供了一个 NTLM 认证器。
目录
需求
- PHP >= 7.2.0
- Apache 2.4 基于 SSPI NTLM 的认证模块(mod_authn_ntlm)
- CakePHP >= 4.3.0
- CakePHP 认证 >= 2.0
可选
- ext-ldap (LDAP php 扩展)
安装
使用 composer 将此插件安装到您的应用程序中
- 将
fawno/ntlm-authentication
包添加到您的项目中composer require fawno/ntlm-authentication
- 在您的
Application.php
中加载 NTLMAuthenticatoruse Fawno\NTLM\Authenticator\NTLMAuthenticator;
- 在您的认证服务(
Application.php
)中加载 NTLMAuthenticator// Load the authenticators. Session should be first. $service->loadAuthenticator('Authentication.Session'); $service->loadAuthenticator(NTLMAuthenticator::class, [ 'domains' => [], ]);
配置
exampledomain
短域名
example.com
完整域名
基于 SSPI NTLM 的 Apache 认证模块(mod_authn_ntlm)
只有带有 /login
的路由才会使用 NTLM 进行认证
webroot\.htaccess
:
<If "%{THE_REQUEST} =~ m#GET .*/login(\?.*)? HTTP.*#"> AuthName "Example App" AuthType SSPI NTLMAuth On NTLMAuthoritative On NTLMDomain exampledomain NTLMOmitDomain Off # keep domain name in userid string NTLMOfferBasic On # let non-IE clients authenticate NTLMBasicPreferred Off # should basic authentication have higher priority NTLMUsernameCase lower Require valid-user </If> <Else> AuthType None Require all granted </Else> #Order allow,deny #Allow from 192.168.0.0/16 Satisfy all
NTLMAuthenticator
NTLM 认证器可以通过 LDAP 查询用户成员资格。这些信息存储在会话中,可用于授权(ACL)。
$service->loadAuthenticator(NTLMAuthenticator::class, [ 'domains' => [ 'exampledomain' => [ 'ldap' => [ 'srv' => 'active-directory.example.com', 'user' => base64_encode('user@example.com'), 'pass' => base64_encode('UserPassword'), 'dn' => 'OU=Departaments, DC=example, DC=com', 'dn_users' => 'CN=Users, DC=example, DC=com', ], 'config' => [ 'some_key' => 'some_data', ], ], 'exampledomain2' => [ 'ldap' => [ 'srv' => 'active-directory.example2.com', 'user' => base64_encode('user@example2.com'), 'pass' => base64_encode('UserPassword2'), 'dn' => 'OU=Departaments, DC=example2, DC=com', 'dn_users' => 'CN=Users, DC=example2, DC=com', ], 'config' => [ 'some_key' => 'some_data', ], ], ], ]);
配置的凭据应该只有查询访问 LDAP 服务的权限,而在域内没有其他权限。
config
数组是可选的,可以存储在会话认证数据中。它允许配置组织的标志以及其他应用需要使用域的用户的通用数据。
应用程序无法访问验证过的用户密码,所有 NTLM 认证都是在 Apache 服务器和浏览器之间协商的。