我想通过用户名授权用户,忽略任何密码。 用户名是一个许可证ID。 如果你有它,你可以访问网站,否则不。
通过设置AuthMySQLNoPasswd On
,系统现在可以在Apache 2.2上使用mod_auth_mysql 。
现在我正在尝试升级到Apache 2.4并使用mod_authz_dbd 。 我不想做任何dbd身份validation,所以我想过使用mod_authn_anon来validation任何用户,然后使用dbd进行授权。 这是configuration:
AuthType basic AuthName "Please use license ID as user name, password is irrelevant" AuthBasicProvider anon Anonymous_NoUserID on # "authorized" is the name of an imaginary group that is returned by AuthzDBDQuery # when username matches license ID in the database Require dbd-group authorized AuthzDBDQuery "select 'authorized' from user_info where user_name = %s"
这里是日志的相关部分:
mod_authz_core.c(809): AH01626: authorization result of Require dbd-group authorized: denied (no authenticated user yet) mod_authz_core.c(809): AH01626: authorization result of <RequireAny>: denied (no authenticated user yet) auth_basic:error] AH01618: user id not found: /protected/
看起来, anon实际上不authentication用户可用于dbd授权。
我知道关于mod_wsgi,但我想要一个标准的apache2模块的解决scheme。 我不想安装Python。
AFAIK这个function在目前的标准模块中是不可用的。
所以,如果你不想安装python,你很可能不得不改变一下代码。
如果你只想通过用户名authentication用户,你可以通过编辑mod_authn_dbd.c来完成。
这个文件在Apache Github账户上是可用的,这里是它的链接: mod_authn_dbd.c 。
应该突出显示183-187行:
rv = apr_password_validate(password, dbd_password); if (rv != APR_SUCCESS) { return AUTH_DENIED; }
您将要评论/删除所有。 允许您使用任何密码(包括留空框)进行authentication。
所以一旦你保存并将这些更改应用到文件。 你将需要编译它。
这是在unix上使用: apxs2
命令完成的。
sudo apxs2 -iac mod_authn_dbd.c
它会编译它,然后自动激活它。
如果您在运行此命令时遇到问题,可能是缺lesshttpd-devel(centos)或apache2-dev(ubuntu)。
现在在你的configuration文件中,删除:
AuthBasicProvider anon Anonymous_NoUserID on
加:
AuthBasicProvider dbd Require valid-user # mod_authn_dbd SQL query to authenticate a user AuthDBDUserPWQuery "select user_name from user_info where user_name = %s"
所以你在上面发布的configuration应该是这样的:
AuthType basic AuthName "Please use license ID as user name, password is irrelevant" AuthBasicProvider dbd Require valid-user # mod_authn_dbd SQL query to authenticate a user AuthDBDUserPWQuery "select user_name from user_info where user_name = %s" # "authorized" is the name of an imaginary group that is returned by AuthzDBDQuery # when username matches license ID in the database Require dbd-group authorized AuthzDBDQuery "select 'authorized' from user_info where user_name = %s"
然后,您将只能使用其许可证号码对用户进行身份validation,然后执行authz所需的任何操作。
不过,我真的希望有另一个更简单,更简单的解决scheme。
请记住,通过这样做,如果您需要此模块正常工作,您将再次遇到另一个或同样的问题。
祝你好运!
我会假设你也需要这样的话:
AuthDBDUserPWQuery "SELECT '' FROM authn WHERE user = %s AND login = 'true'" Require dbd-login AuthzDBDQuery "UPDATE authn SET login = 'true' WHERE user = %s"