Captive-Portal

 view release on metacpan or  search on metacpan

lib/Captive/Portal/Role/AuthenSimple.pm  view on Meta::CPAN

package Captive::Portal::Role::AuthenSimple;

use strict;
use warnings;

=head1 NAME

Captive::Portal::Role::AuthenSimple - Authen::Simple adapter for Captive::Portal

=cut

our $VERSION = '4.10';

use Log::Log4perl qw(:easy);
use Authen::Simple qw();
use Try::Tiny;

use Role::Basic;
requires qw(cfg);

my $authen_singleton;

=head1 DESCRIPTION

CaPo authentication is based on the pluggable Authen::Simple framework.

=head1 ROLES

=over

=item $capo->build_authenticator()

Load the Authen::Simple Plugins as specified in config file and create the authenticator object. Die on error.

=cut

sub build_authenticator {
    my $self = shift;

    return 1 if $self->cfg->{MOCK_AUTHEN};

    my $authen_modules = $self->cfg->{AUTHEN_SIMPLE_MODULES} || {};

    LOGDIE "missing Authen::Simple modules in config file\n"
      unless %$authen_modules;

    ### use Authen::Simple::... modules
    #
    my @authen_simple_objects;
    foreach my $module ( keys %$authen_modules ) {
        DEBUG("use $module");

        my $error;
        try { eval "use $module" } catch { $error = $_ };
        LOGDIE $error if $error;

        # create authen_simple_obj and push it to the modules array
        my $authen_obj = $module->new( $authen_modules->{$module} )
          or LOGDIE "Couldn't create $module object\n";

        push @authen_simple_objects, $authen_obj;
    }

    # and make the authen_simple object, see perldoc Authen::Simple

    DEBUG('build the authenticator object');

    $authen_singleton = Authen::Simple->new(@authen_simple_objects)
      or LOGDIE "Couldn't create the Authen::Simple object\n";

    return 1;
}

=item $capo->authenticate($username, $password)

Call the authenticator object with credentials. Returns true on success and false on failure.



( run in 1.096 second using v1.01-cache-2.11-cpan-d7f47b0818f )