1Authen::Simple::AdapterU(s3e)r Contributed Perl DocumentaAtuitohnen::Simple::Adapter(3)
2
3
4

NAME

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

SYNOPSIS

9           package Authenticate::Simple::Larry;
10
11           use strict;
12           use base 'Authen::Simple::Adapter';
13
14           __PACKAGE__->options({
15               secret => {
16                   type     => Params::Validate::SCALAR,
17                   default  => 'wall',
18                   optional => 1
19               }
20           });
21
22           sub check {
23               my ( $self, $username, $password ) = @_;
24
25               if ( $username eq 'larry' && $password eq $self->secret ) {
26
27                   $self->log->debug( qq/Successfully authenticated user '$username'./ )
28                     if $self->log;
29
30                   return 1;
31               }
32
33               $self->log->debug( qq/Failed to authenticate user '$username'. Reason: 'Invalid credentials'/ )
34                 if $self->log;
35
36               return 0;
37           }
38
39           1;
40

DESCRIPTION

42       Adapter class for implementations.
43

METHODS

45       •   new ( %parameters )
46
47           If overloaded, this method should take a hash of parameters. The
48           following options should be valid:
49
50           •       cache ( $ )
51
52                   Any object that supports "get", "set". Only successful
53                   authentications are cached.
54
55                       cache => Cache::FastMmap->new
56
57           •       callback ( \& )
58
59                   A subref that gets called with two scalar references,
60                   username and password.
61
62                       callback = sub {
63                           my ( $username, $password ) = @_;
64
65                           if ( length($$password) < 6 ) {
66                               return 0; # abort, invalid credintials
67                           }
68
69                           if ( $$password eq 'secret' ) {
70                               return 1; # abort, successful authentication
71                           }
72
73                           return; # proceed;
74                       }
75
76           •       log ( $ )
77
78                   Any object that supports "debug", "info", "error" and
79                   "warn".
80
81                       log => Log::Log4perl->get_logger('Authen::Simple')
82                       log => $r->log
83                       log => $r->server->log
84
85       •   init ( \%parameters )
86
87           This method is called after construction. It should assign
88           parameters and return the instance.
89
90               sub init {
91                   my ( $self, $parameters ) = @_;
92
93                   # mock with parameters
94
95                   return $self->SUPER::init($parameters);
96               }
97
98       •   authenticate ( $username, $password )
99
100           End user method. Applies callback, checks cache and calls "check"
101           unless aborted by callback or a cache hit.
102
103       •   check ( $username, $password )
104
105           Must be implemented in sublcass, should return true on success and
106           false on failure.
107
108       •   check_password( $password, $encrypted )
109
110       •   options ( \%options )
111
112           Must be set in subclass, should be a valid Params::Validate
113           specification.  Accessors for options will be created unless
114           defined in sublcass.
115
116               __PACKAGE__->options({
117                   host => {
118                       type     => Params::Validate::SCALAR,
119                       optional => 0
120                   },
121                   port => {
122                       type     => Params::Validate::SCALAR,
123                       default  => 80,
124                       optional => 1
125                   }
126               });
127

SEE ALSO

129       Authen::Simple
130
131       Authen::Simple::Password
132
133       Params::Validate
134

AUTHOR

136       Christian Hansen "chansen@cpan.org"
137
139       This program is free software, you can redistribute it and/or modify it
140       under the same terms as Perl itself.
141
142
143
144perl v5.34.0                      2021-07-22        Authen::Simple::Adapter(3)
Impressum