line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Authen::Simple::Adapter; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
11474
|
use strict; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
160
|
|
4
|
5
|
|
|
5
|
|
27
|
use warnings; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
137
|
|
5
|
5
|
|
|
5
|
|
23
|
use base qw[Class::Accessor::Fast Class::Data::Inheritable]; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
5276
|
|
6
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
37459
|
use Authen::Simple::Log qw[]; |
|
5
|
|
|
|
|
16
|
|
|
5
|
|
|
|
|
108
|
|
8
|
5
|
|
|
5
|
|
3206
|
use Authen::Simple::Password qw[]; |
|
5
|
|
|
|
|
19
|
|
|
5
|
|
|
|
|
120
|
|
9
|
5
|
|
|
5
|
|
35
|
use Carp qw[]; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
81
|
|
10
|
5
|
|
|
5
|
|
3020
|
use Params::Validate qw[]; |
|
5
|
|
|
|
|
34604
|
|
|
5
|
|
|
|
|
4489
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
__PACKAGE__->mk_classdata( _options => { } ); |
13
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors( qw[ cache callback log ] ); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
5
|
|
|
5
|
1
|
139
|
my $proto = shift; |
17
|
5
|
|
33
|
|
|
39
|
my $class = ref($proto) || $proto; |
18
|
|
|
|
|
|
|
|
19
|
5
|
|
|
|
|
39
|
my $params = Params::Validate::validate_with( |
20
|
|
|
|
|
|
|
params => \@_, |
21
|
|
|
|
|
|
|
spec => $class->options, |
22
|
|
|
|
|
|
|
called => "$class\::new" |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
5
|
|
|
|
|
518
|
return $class->SUPER::new->init($params); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub init { |
29
|
5
|
|
|
5
|
1
|
82
|
my ( $self, $params ) = @_; |
30
|
|
|
|
|
|
|
|
31
|
5
|
|
|
|
|
10
|
while ( my ( $method, $value ) = each( %{ $params } ) ) { |
|
16
|
|
|
|
|
165
|
|
32
|
11
|
|
|
|
|
63
|
$self->$method($value); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
5
|
|
|
|
|
33
|
return $self; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub authenticate { |
39
|
13
|
|
|
13
|
1
|
7305
|
my $self = shift; |
40
|
13
|
|
33
|
|
|
46
|
my $class = ref($self) || $self; |
41
|
|
|
|
|
|
|
|
42
|
13
|
|
|
|
|
308
|
my ( $username, $password ) = Params::Validate::validate_with( |
43
|
|
|
|
|
|
|
params => \@_, |
44
|
|
|
|
|
|
|
spec => [ |
45
|
|
|
|
|
|
|
{ |
46
|
|
|
|
|
|
|
type => Params::Validate::SCALAR |
47
|
|
|
|
|
|
|
}, |
48
|
|
|
|
|
|
|
{ |
49
|
|
|
|
|
|
|
type => Params::Validate::SCALAR |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
], |
52
|
|
|
|
|
|
|
called => "$class\::authenticate" |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
|
55
|
13
|
|
|
|
|
63
|
my $status; |
56
|
|
|
|
|
|
|
|
57
|
13
|
100
|
|
|
|
52
|
if ( $self->callback ) { |
58
|
|
|
|
|
|
|
|
59
|
3
|
|
|
|
|
21
|
$status = $self->callback->( \$username, \$password ); |
60
|
|
|
|
|
|
|
|
61
|
3
|
100
|
|
|
|
21
|
if ( defined $status ) { |
62
|
|
|
|
|
|
|
|
63
|
2
|
100
|
|
|
|
5
|
my $boolean = $status ? 'true' : 'false'; |
64
|
|
|
|
|
|
|
|
65
|
2
|
50
|
|
|
|
8
|
$self->log->debug( qq/Callback returned a $boolean value '$status' for user '$username'./ ) |
66
|
|
|
|
|
|
|
if $self->log; |
67
|
|
|
|
|
|
|
|
68
|
2
|
|
|
|
|
20
|
return $status; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
11
|
100
|
|
|
|
89
|
if ( $self->cache ) { |
73
|
|
|
|
|
|
|
|
74
|
4
|
|
|
|
|
26
|
$status = $self->cache->get("$username:$password"); |
75
|
|
|
|
|
|
|
|
76
|
4
|
100
|
|
|
|
43
|
if ( defined $status ) { |
77
|
|
|
|
|
|
|
|
78
|
1
|
50
|
|
|
|
4
|
$self->log->debug( qq/Successfully authenticated user '$username' from cache./ ) |
79
|
|
|
|
|
|
|
if $self->log; |
80
|
|
|
|
|
|
|
|
81
|
1
|
|
|
|
|
13
|
return $status; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
10
|
|
|
|
|
65
|
$status = $self->check( $username, $password ); |
86
|
|
|
|
|
|
|
|
87
|
10
|
100
|
100
|
|
|
116
|
if ( $self->cache && $status ) { |
88
|
|
|
|
|
|
|
|
89
|
1
|
|
|
|
|
14
|
$self->cache->set( "$username:$password" => $status ); |
90
|
|
|
|
|
|
|
|
91
|
1
|
50
|
|
|
|
13
|
$self->log->debug( qq/Caching successful authentication status '$status' for user '$username'./ ) |
92
|
|
|
|
|
|
|
if $self->log; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
10
|
|
|
|
|
112
|
return $status; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub check { |
99
|
0
|
|
|
0
|
1
|
0
|
Carp::croak( __PACKAGE__ . qq/->check is an abstract method/ ); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub check_password { |
103
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
104
|
0
|
|
|
|
|
0
|
return Authen::Simple::Password->check(@_); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub options { |
108
|
9
|
|
|
9
|
1
|
82
|
my $proto = shift; |
109
|
9
|
|
33
|
|
|
62
|
my $class = ref($proto) || $proto; |
110
|
|
|
|
|
|
|
|
111
|
9
|
100
|
|
|
|
34
|
if ( @_ ) { |
112
|
|
|
|
|
|
|
|
113
|
4
|
|
|
|
|
130
|
my ($options) = Params::Validate::validate_pos( @_, { type => Params::Validate::HASHREF } ); |
114
|
|
|
|
|
|
|
|
115
|
4
|
50
|
|
|
|
17
|
if ( my @create = grep { ! $class->can($_) } keys %{ $options } ) { |
|
4
|
|
|
|
|
84
|
|
|
4
|
|
|
|
|
17
|
|
116
|
4
|
|
|
|
|
38
|
$class->mk_accessors(@create); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
4
|
|
50
|
|
|
293
|
$options->{cache} ||= { |
120
|
|
|
|
|
|
|
type => Params::Validate::OBJECT, |
121
|
|
|
|
|
|
|
can => [ qw[get set] ], |
122
|
|
|
|
|
|
|
optional => 1 |
123
|
|
|
|
|
|
|
}; |
124
|
|
|
|
|
|
|
|
125
|
4
|
|
50
|
|
|
26
|
$options->{callback} ||= { |
126
|
|
|
|
|
|
|
type => Params::Validate::CODEREF, |
127
|
|
|
|
|
|
|
optional => 1 |
128
|
|
|
|
|
|
|
}; |
129
|
|
|
|
|
|
|
|
130
|
4
|
|
50
|
|
|
55
|
$options->{log} ||= { |
131
|
|
|
|
|
|
|
type => Params::Validate::OBJECT, |
132
|
|
|
|
|
|
|
can => [ qw[debug info error warn] ], |
133
|
|
|
|
|
|
|
default => Authen::Simple::Log->new, |
134
|
|
|
|
|
|
|
optional => 1 |
135
|
|
|
|
|
|
|
}; |
136
|
|
|
|
|
|
|
|
137
|
4
|
|
|
|
|
26
|
$class->_options($options); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
9
|
|
|
|
|
173
|
return $class->_options; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
__END__ |