apache - 调试 Apache 2.4 PerlAuthenHandler

标签 apache perl authentication redmine mod-perl2

我正在尝试调试 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/

相关文章:

python - Django:使用 mod_wsgi 创建的 SOCK 文件的权限错误

php - apache 服务器 CentOS 中的访问权限

php - 如何在wordpress中进行 session 登录

perl - 如何通过 Excel::Writer::XLSX 添加硬返回?

Perl 中的 XML 解析问题

windows - Windows Azure 上的 IIS 7 默认配置未通过自定义身份验证 header 传递到正在运行的服务

php - 结合 SSL/TLS (HTTPS) 的 HTTP 基本身份验证将用于对用户进行身份验证

apache - 安装 mod_jk.so 后配置 http 未运行

java - Apache Flink-Java> 8支持路线图?

regex - Perl 正则表达式指定捕获的最大长度