Apache-AppSamurai
view release on metacpan or search on metacpan
lib/Apache/AppSamurai/AuthBase.pm view on Meta::CPAN
If all conditions are met, the validated and cleaned password is returned.
C<CheckInputPass()> should not generally need to be overridden unless an
authentication module needs more extensive filtering.
=head2 AddError()
Adds a new log message to the C<< @{$self->{errors}} >> array, which is
returned to a then processed by Apache::AppSamurai.
C<AddError()> is called using an object reference and expects one of
two types of calls:
=over 4
=item *
One argument - This should be a single scalar containing the text to be
logged. It will be added to the errors using the log level defined in
the I<DefaultLogLevel> configuration option.
=item *
Two arguments - This should be scalar containing the log level to use,
followed by a scalar with the message to be logged.
=back
C<AddError()> should not generally need to be overridden.
=head2 Errors()
Called using an object reference and returns an array of anonymous
arrays containing C<loglevel>, C<logmessage> pairs. If no log messages
exist, undef is returned.
C<Errors()> is called by Apache::AppSamurai after using the authentication
module's C<Authenticate()> method. It generally does not need to be
overridden.
=head1 EXAMPLES
Here is an example authentication module based on Auth::Base. Let's call
it Apache::AppSamurai::AuthGarbage and have it use the fictitious module
Junk::Dumpster to check credentials.
package Apache::AppSamurai::AuthGarbage;
use Apache::AppSamurai::AuthBase;
use Junk::Dumpster; # Kids, don't try this at home
# Inherit the AuthBase wind...
@ISA = qw( Apache::AppSamurai::AuthBase );
# Override the Configure method to add special config options
sub Configure {
my $self = shift;
# Pull defaults from AuthBase and save.
$self->SUPER::Configure();
my $conft = $self->{conf};
# Initial configuration. Put defaults here before the @_ args are
# pulled in.
$self->{conf} = { %{$conft},
Crud => 1,
Dumpster => 'supadumpy',
@_,
};
return 1;
}
# Set an Initiate function to do any required setup and initialization
# (Creating object instances, pre-flight checks, etc.)
sub Initialize {
my $self = shift;
# Create Junk::Dumpster instance
$self->{client} = new Junk::Dumpster(crud => $self->{conf}{Crud});
# Set init flag
$self->{init} = 1;
return 1;
}
# Make authentication check
sub Authenticator {
my $self = shift;
my $user = shift;
my $pass = shift;
my ($response, $error, @tmp, $check, $realm);
# This is silly. There is no Junk::Dumpster....
$response = $self->{client}->IsItInDere($user,$pass);
if ($response) {
# You passed the test!
return 1;
} elsif ($!) {
# An abnormal failure: Log an error
$self->AddError('error', "Failure from Junk:Garbage: $!");
return 0;
}
# Normal failure fall through. Log the failure and kick back
$self->AddError('warn', "Junk::Garbage login failure for \"$user\"");
return 0;
}
=head1 SEE ALSO
L<Apache::AppSamurai>, L<Apache::AppSamurai::AuthBasic>
=head1 AUTHOR
Paul M. Hirsch, C<< <paul at voltagenoir.org> >>
=head1 BUGS
( run in 0.748 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )