Apache2-AUS
view release on metacpan or search on metacpan
lib/Apache2/AUS.pm view on Meta::CPAN
sub Authen {
my($class, $r) = @_;
my $requires = $r->requires;
if($requires && scalar(@$requires)) {
my $session = $r->aus_session;
my $user = $session->user;
foreach (
map { [ split(" ", $_->{requirement}) ] } (@$requires)
) {
unless(check_requirement($r, $_)) {
$r->log_reason(sprintf(
qq{[%s] %d(%s) does not satisfy requirement "%s"},
$r->connection->remote_ip,
($user ? $user->{id} : 0), ($user ? $user->{name} : ""),
join(" ", @$_), $r->uri
));
return FORBIDDEN;
}
}
return OK;
} else {
return OK;
}
}
=pod
=head1 NAME
Apache2::AUS - Authorization, Users, and Sessions for Apache2.
=head1 SYNOPSIS
In httpd.conf:
PerlModule Apache2::AUS
PerlInitHandler Apache2::AUS->Init
Then in a mod_perl handler:
my $session = $r->aus_session;
if($session->param('foo')) {
...
}
=head1 DESCRIPTION
B<Note:> I<This is an alpha release. The interface is somewhat stable and
well-tested, but other changes may come as I work in implementing this on
my website.>
C<Apache2::AUS> is a mod_perl package that provides access to
C<Schema::RDBMS::AUS> sessions and users from Apache2. For a more
detailed description of Authentication, Users, and Sessions with
Schema::RDBMS::AUS, see L<it's documentation|Schema::RDBMS::AUS>.
Environment variables and some other required settings are documented
there.
This document focuses on how to use the apache2 bindings to access
(or restrict access based upon) Schema::RDBMS::AUs's
users, groups, and sessions:
=head1 ACCESS TO THE SESSION OBJECT
The C<AUS_SESSION_ID> envrionment variable is set by the
L<Schema::RDBMS::AUS|Schema::RDBMS::AUS> package for each request,
so you can look up the session data manually in the database if you
want, or initialize your own L<CGI::Session::AUS|CGI::Session::AUS>
object to manipulate it. Apache2::AUS will flush all of it's changes
to the session object just before apache's C<HTTP Response> phase,
so you should always have the most current information and be able
to save your changes safely. Here's an example of how to obtain the
session from a CGI script:
#!perl
use strict;
use warnings;
use CGI;
use CGI::Session::AUS;
my $cgi = CGI->new;
my $session = CGI::Session::AUS->new
or die "I need a session object to continue!";
if($session->param("has_cheese")) {
print $cgi->header, "You have cheese!\n";
exit;
}
When operating under mod_perl, it's usually more efficient to pick up
the existing session object yourself. L<Apache2::AUS|Apache2::AUS> makes
this convienent for you by adding an "aus_session" method which you can
use in your own mod_perl handlers:
sub handler {
my $r = shift;
my $session = $r->aus_session
or die "I need a session to continue!";
if($session->user) {
...
}
}
See L<CGI::Session::AUS|CGI::Session::AUS> and L<CGI::Session|CGI::Session>
for more information about the session object.
=head1 HANDLERS
All handlers should be called as "class methods" in your C<httpd.conf>, eg:
<Location /login>
PerlResponseHandler Apache2::AUS->Response
</Location>
=over
( run in 1.733 second using v1.01-cache-2.11-cpan-2398b32b56e )