fawno/ntlm-authentication

为 CakePHP 4.3 提供的 NTLM 认证器

安装: 4

依赖: 0

建议者: 0

安全: 0

星星: 0

关注者: 2

分支: 0

开放问题: 0

类型:cakephp-plugin

1.0.0 2022-04-25 23:45 UTC

This package is auto-updated.

Last update: 2024-08-26 08:13:04 UTC


README

GitHub license GitHub release Packagist Packagist Downloads GitHub issues GitHub forks GitHub stars

为 CakePHP 4 认证插件提供的 NTLM 认证器

此插件为 CakePHP 4 认证插件提供了一个 NTLM 认证器。

目录

需求

可选

目录

安装

使用 composer 将此插件安装到您的应用程序中

  • fawno/ntlm-authentication 包添加到您的项目中
      composer require fawno/ntlm-authentication
  • 在您的 Application.php 中加载 NTLMAuthenticator
    use 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 服务器和浏览器之间协商的。

目录