Authen-Simple

 view release on metacpan or  search on metacpan

lib/Authen/Simple/Adapter.pm  view on Meta::CPAN

        }

        $options->{cache} ||= {
            type     => Params::Validate::OBJECT,
            can      => [ qw[get set] ],
            optional => 1
        };

        $options->{callback} ||= {
            type     => Params::Validate::CODEREF,
            optional => 1
        };

        $options->{log} ||= {
            type     => Params::Validate::OBJECT,
            can      => [ qw[debug info error warn] ],
            default  => Authen::Simple::Log->new,
            optional => 1
        };

        $class->_options($options);
    }

    return $class->_options;
}

1;

__END__

=head1 NAME

Authen::Simple::Adapter - Adapter class for implementations

=head1 SYNOPSIS

    package Authenticate::Simple::Larry;
    
    use strict;
    use base 'Authen::Simple::Adapter';
    
    __PACKAGE__->options({
        secret => {
            type     => Params::Validate::SCALAR,
            default  => 'wall',
            optional => 1
        }
    });
    
    sub check {
        my ( $self, $username, $password ) = @_;
        
        if ( $username eq 'larry' && $password eq $self->secret ) {
            
            $self->log->debug( qq/Successfully authenticated user '$username'./ )
              if $self->log;
            
            return 1;
        }
        
        $self->log->debug( qq/Failed to authenticate user '$username'. Reason: 'Invalid credentials'/ )
          if $self->log;
        
        return 0;
    }
    
    1;

=head1 DESCRIPTION

Adapter class for implementations.

=head1 METHODS

=over 4

=item * new ( %parameters )

If overloaded, this method should take a hash of parameters. The following 
options should be valid:

=over 8

=item * cache ( $ )

Any object that supports C<get>, C<set>. Only successful authentications are cached.

    cache => Cache::FastMmap->new

=item * callback ( \& )

A subref that gets called with two scalar references, username and password.

    callback = sub {
        my ( $username, $password ) = @_;
        
        if ( length($$password) < 6 ) {
            return 0; # abort, invalid credintials
        }
        
        if ( $$password eq 'secret' ) {
            return 1; # abort, successful authentication
        }
        
        return; # proceed;
    }
    
=item * log ( $ )

Any object that supports C<debug>, C<info>, C<error> and C<warn>.

    log => Log::Log4perl->get_logger('Authen::Simple')
    log => $r->log
    log => $r->server->log

=back

=item * init ( \%parameters )

This method is called after construction. It should assign parameters and return 
the instance.



( run in 0.763 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )