title: Debug Apache 2.4 PerlAuthenHandler
body: <p>I am trying to debug a problem that occured after an apache upgrade. I want to integrate redmine into my apache authentification/access control. </p>
  
  <p>Here is my apache config:</p>
  
  <pre><code>&lt;Location "/git/"&gt;                                         
  
    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 
    ...
  </code></pre>
  
  <p>And this is the access/authen handler:</p>
  
  <pre><code>sub access_handler {                                                                                                       
    my $r = shift;                                                                                                           
  
    unless ($r-&gt;some_auth_required) {                                                                                        
        $r-&gt;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-&gt;log_error("Setting Auth to OK") if is_public_project($project_id, $r) &amp;&amp; anonymous_role_allows_browse_repository($r);
    $r-&gt;log_error("Content: " . $r-&gt;get_handlers("PerlAuthenHandler"));                                                      
  
    $r-&gt;set_handlers(PerlAuthenHandler =&gt; [\&amp;ok_authen_handler])                                                             
        if is_public_project($project_id, $r) &amp;&amp; anonymous_role_allows_browse_repository($r);                                
  
    return OK                                                                                                                
  }                                                                                                                          
  
  sub ok_authen_handler {                                                                                                    
    my $r = shift;                                                                                                           
    $r-&gt;log_error("ok_authen_handler()...");                                                                                 
  
    my ($res, $redmine_pass) =  $r-&gt;get_basic_auth_pw();                                                                     
  
    return OK;                                                                                                               
  }                                                                                                                          
  
  sub authen_handler {                                                                                                       
    my $r = shift;                                                                                                           
    $r-&gt;log_error("authen_handler() ...");                                                                                   
    my ($res, $redmine_pass) =  $r-&gt;get_basic_auth_pw();                                                                     
    return $res unless $res == OK;                                                                                           
  
    if (is_member($r-&gt;user, $redmine_pass, $r)) {                                                                            
        $r-&gt;log_error("Auth succeeded");                                                                                     
        return OK;                                                                                                           
    } else {                                                                                                                 
        $r-&gt;log_error("Auth failed...");                                                                                     
        $r-&gt;note_auth_failure();                                                                                             
        return DECLINED;                                                                                                     
    }                                                                                                                        
  }  
  </code></pre>
  
  <p>As you can see, the access handler resets the auth handler to some dummy method in case the authentication is not needed. In theory, this allows for selective anonymous access. </p>
  
  <p>In practice, though apache 2.4 yields an error:</p>
  
  <pre><code>AH00027: No authentication done but request not allowed without authentication for $PATH. Authentication not configured?
  </code></pre>
  
  <p>I already nailed the problem to the hack in the access handler, if I uncomment the set_handlers statement, I can authenticate against redmine. So I guess there is something wrong in this "hack". Unfortunately I am not really a perl guy, so I have no idea how to investigate the issue any further. </p>
  
  <p>Is there any way to figure out what is the important difference between the "hacked" control flow (i.e. setting the auth handler programmatically) and the normal one?</p>