Hi all,
Huge thanks to everyone for your replies on this. I’ve now been able to work
through everything, and I thought I’d post a quick update with some additional
notes in case there’s anyone else in the same boat searching the archives in
the future!
1. I was able to use the following as a way of determining which version of
Apache is in use at runtime:
my $server_version = Apache2::ServerUtil::get_server_banner();
my $is_old_apache = ($server_version =~ /Apache\/2\.2/) ? 1 : 0;
2. My app sets up authen and authz handlers dynamically, from a trans handler.
André was right, this was by far the biggest pain point!
My before code looked like this:
$r->push_handlers(PerlMapToStorageHandler => sub {
$r->add_config(['Require valid-user']);
$r->add_config(['AuthType cookie']);
});
$r->set_handlers(PerlAuthenHandler => [MyApp::Authen]);
$r->set_handlers(PerlAuthzHandler => [MyApp::Authz]);
As far as I can tell, I have to pre-declare the new Authz provider in my server
config:
PerlAddAuthzProvider myapp MyApp::Authz
I didn’t find a way of doing that bit dynamically at runtime.
But I can still conditionally trigger the provider for individual requests from
my trans handler, like this:
$r->push_handlers(PerlMapToStorageHandler => sub {
$r->add_config(['Require myapp']);
});
$r->set_handlers(PerlAuthenHandler => [MyApp::Authen]);
3. Combining #1 and #2 meant I’m able to have the same trans handler run under
both Apache 2.2 and 2.4. I was also able to get my authz handler to run under
both by:
a. Having the call to Apache2::Compat -compile happen in the server startup.pl,
and not in my module.
b. Wrapping the return value like this:
sub authz_granted {
my $self = shift;
# So this compiles under old Apache
no strict 'subs';
if ($self->is_old_apache) {
return Apache2::Const::OK;
} else {
return Apache2::Const::AUTHZ_GRANTED;
}
}
Thanks again to you all for your help.
Cheers,
Andrew.
--
Andrew Green
Article Seven Limited
http://www.article7.co.uk/ <http://www.article7.co.uk/>
Article Seven Limited is a registered company in England and Wales. Registered
number: 5703656. Registered office: 10 Hamilton Road, Sidcup, Kent, DA15 7HB.