On this page
Apache 模块 mod_authn_core
Description: | Core Authentication |
---|---|
Status: | Base |
Module Identifier: | authn_core_module |
Source File: | mod_authn_core.c |
Compatibility: | 在 Apache 2.3 和更高版本中可用 |
Summary
该模块提供核心身份验证功能,以允许或拒绝访问网站的某些部分。 mod_authn_core提供了所有身份验证提供程序都通用的指令。
创建身份验证提供程序别名
可以在配置文件中创建扩展身份验证提供程序,并为其分配别名。然后可以通过伪指令AuthBasicProvider或AuthDigestProvider引用别名提供程序,其方式与基本身份验证提供程序相同。除了具有创建扩展提供者并为其别名的功能外,它还允许多个位置引用同一扩展身份验证提供者。
Examples
本示例检查两个不同文本文件中的密码。
检查多个文本密码文件
# Check here first
<AuthnProviderAlias file file1>
AuthUserFile "/www/conf/passwords1"
</AuthnProviderAlias>
# Then check here
<AuthnProviderAlias file file2>
AuthUserFile "/www/conf/passwords2"
</AuthnProviderAlias>
<Directory "/var/web/pages/secure">
AuthBasicProvider file1 file2
AuthType Basic
AuthName "Protected Area"
Require valid-user
</Directory>
下面的示例基于 ldap 提供程序创建两个不同的 ldap 身份验证提供程序别名。这允许多个 ldap 主机为一个经过身份验证的位置提供服务:
检查多个 LDAP 服务器
<AuthnProviderAlias ldap ldap-alias1>
AuthLDAPBindDN cn=youruser,o=ctx
AuthLDAPBindPassword yourpassword
AuthLDAPURL ldap://ldap.host/o=ctx
</AuthnProviderAlias>
<AuthnProviderAlias ldap ldap-other-alias>
AuthLDAPBindDN cn=yourotheruser,o=dev
AuthLDAPBindPassword yourotherpassword
AuthLDAPURL ldap://other.ldap.host/o=dev?cn
</AuthnProviderAlias>
Alias "/secure" "/webpages/secure"
<Directory "/webpages/secure">
AuthBasicProvider ldap-other-alias ldap-alias1
AuthType Basic
AuthName "LDAP Protected Place"
Require valid-user
# Note that Require ldap-* would not work here, since the
# AuthnProviderAlias does not provide the config to authorization providers
# that are implemented in the same module as the authentication provider.
</Directory>
AuthName Directive
Description: | 用于 HTTP 身份验证的授权领域 |
---|---|
Syntax: | AuthName auth-domain |
Context: | directory, .htaccess |
Override: | AuthConfig |
Status: | Base |
Module: | mod_authn_core |
该伪指令设置目录的授权领域的名称。该领域被提供给 Client 端,以便用户知道要发送的用户名和密码。 AuthName
接受一个参数;如果领域名称包含空格,则必须将其用引号引起来。它必须带有AuthType和Require指令以及AuthUserFile和AuthGroupFile之类的指令才能起作用。
For example:
AuthName "Top Secret"
为AuthName
提供的字符串将出现在大多数浏览器提供的密码对话框中。
See also
Directive
Description: | 包含一组指令,这些指令代表基本身份验证提供程序的扩展,并由指定的别名引用 |
---|---|
Syntax: | <AuthnProviderAlias baseProvider Alias> ... </AuthnProviderAlias> |
Context: | server config |
Status: | Base |
Module: | mod_authn_core |
<AuthnProviderAlias>
和</AuthnProviderAlias>
用于封装一组身份验证指令,可以使用指令AuthBasicProvider或AuthDigestProvider中的一个由别名来引用该指令。
Note
该指令对授权没有影响,即使对于同时提供身份验证和授权的模块也是如此。
AuthType Directive
Description: | 用户认证类型 |
---|---|
Syntax: | AuthType None|Basic|Digest|Form |
Context: | directory, .htaccess |
Override: | AuthConfig |
Status: | Base |
Module: | mod_authn_core |
该伪指令选择目录的用户认证类型。可用的身份验证类型为None
,Basic
(由mod_auth_basic实现),Digest
(由mod_auth_digest实现)和Form
(由mod_auth_form实现)。
要实现身份验证,还必须使用AuthName和Require指令。另外,服务器必须具有诸如mod_authn_file之类的身份验证提供程序模块和诸如mod_authz_user之类的授权模块。
身份验证类型None
禁用身份验证。启用身份验证后,除非指定了其他身份验证类型,否则通常由每个后续configuration section继承。如果不需要对已认证部分的子部分进行认证,则可以使用认证类型None
;否则,可以使用认证类型None
。在以下示例中,Client 端无需身份验证即可访问/www/docs/public
目录:
<Directory "/www/docs">
AuthType Basic
AuthName Documents
AuthBasicProvider file
AuthUserFile "/usr/local/apache/passwd/passwords"
Require valid-user
</Directory>
<Directory "/www/docs/public">
AuthType None
Require all granted
</Directory>
Note
禁用身份验证时,请注意,已针对服务器文档树的另一部分进行身份验证的 Client 端通常将 continue 与每个请求一起发送身份验证 HTTP Headers 或 cookie,而不管服务器是否实际上要求对每个资源进行身份验证。