我正在尝试调试 Apache 升级后出现的问题。我想将 redmine 集成到我的 apache 身份验证/访问控制中。
这是我的 apache 配置:
<Location "/git/">
AuthType Basic
AuthName "Git Access"
Require valid-user
Order deny,allow
Allow from all
PerlAccessHandler Apache::Authn::Redmine::access_handler
PerlAuthenHandler Apache::Authn::Redmine::authen_handler
...
这是访问/验证处理程序:
sub access_handler {
my $r = shift;
unless ($r->some_auth_required) {
$r->log_reason("No authentication has been configured");
return FORBIDDEN;
}
return OK unless request_is_read_only($r);
my $project_id = get_project_identifier($r);
$r->log_error("Setting Auth to OK") if is_public_project($project_id, $r) && anonymous_role_allows_browse_repository($r);
$r->log_error("Content: " . $r->get_handlers("PerlAuthenHandler"));
$r->set_handlers(PerlAuthenHandler => [\&ok_authen_handler])
if is_public_project($project_id, $r) && anonymous_role_allows_browse_repository($r);
return OK
}
sub ok_authen_handler {
my $r = shift;
$r->log_error("ok_authen_handler()...");
my ($res, $redmine_pass) = $r->get_basic_auth_pw();
return OK;
}
sub authen_handler {
my $r = shift;
$r->log_error("authen_handler() ...");
my ($res, $redmine_pass) = $r->get_basic_auth_pw();
return $res unless $res == OK;
if (is_member($r->user, $redmine_pass, $r)) {
$r->log_error("Auth succeeded");
return OK;
} else {
$r->log_error("Auth failed...");
$r->note_auth_failure();
return DECLINED;
}
}
如您所见,访问处理程序将身份验证处理程序重置为某个虚拟方法,以防不需要身份验证。理论上,这允许选择性匿名访问。
在实践中,尽管 apache 2.4 会产生错误:
AH00027: No authentication done but request not allowed without authentication for $PATH. Authentication not configured?
我已经将问题确定为访问处理程序中的 hack,如果我取消注释 set_handlers 语句,我可以针对 redmine 进行身份验证。所以我猜这个“hack”有问题。不幸的是,我不是一个真正的 perl 人,所以我不知道如何进一步调查这个问题。
有什么方法可以弄清楚“被黑”的控制流(即以编程方式设置身份验证处理程序)与正常控制流之间的重要区别是什么?
最佳答案
一个有点肮脏的解决方法是即使在匿名模式下也总是设置“用户”(REMOTE_USER)变量,所以“需要有效用户”似乎很高兴,
$r->user("");
return Apache2::Const::OK;
我们在实现惰性身份验证(Shibboleth 样式)时遇到了这个问题。
关于apache - 调试 Apache 2.4 PerlAuthenHandler,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22638972/