line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Captive::Portal::Role::AuthenSimple; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
22619
|
use strict; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
271
|
|
4
|
6
|
|
|
6
|
|
35
|
use warnings; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
368
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Captive::Portal::Role::AuthenSimple - Authen::Simple adapter for Captive::Portal |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=cut |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '4.10'; |
13
|
|
|
|
|
|
|
|
14
|
6
|
|
|
6
|
|
37
|
use Log::Log4perl qw(:easy); |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
61
|
|
15
|
6
|
|
|
6
|
|
11021
|
use Authen::Simple qw(); |
|
6
|
|
|
|
|
73783
|
|
|
6
|
|
|
|
|
206
|
|
16
|
6
|
|
|
6
|
|
67
|
use Try::Tiny; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
428
|
|
17
|
|
|
|
|
|
|
|
18
|
6
|
|
|
6
|
|
35
|
use Role::Basic; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
144
|
|
19
|
|
|
|
|
|
|
requires qw(cfg); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $authen_singleton; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 DESCRIPTION |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
CaPo authentication is based on the pluggable Authen::Simple framework. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 ROLES |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=over |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=item $capo->build_authenticator() |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Load the Authen::Simple Plugins as specified in config file and create the authenticator object. Die on error. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub build_authenticator { |
38
|
5
|
|
|
5
|
1
|
15
|
my $self = shift; |
39
|
|
|
|
|
|
|
|
40
|
5
|
50
|
|
|
|
43
|
return 1 if $self->cfg->{MOCK_AUTHEN}; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
0
|
|
|
0
|
my $authen_modules = $self->cfg->{AUTHEN_SIMPLE_MODULES} || {}; |
43
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
0
|
LOGDIE "missing Authen::Simple modules in config file\n" |
45
|
|
|
|
|
|
|
unless %$authen_modules; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
### use Authen::Simple::... modules |
48
|
|
|
|
|
|
|
# |
49
|
0
|
|
|
|
|
0
|
my @authen_simple_objects; |
50
|
0
|
|
|
|
|
0
|
foreach my $module ( keys %$authen_modules ) { |
51
|
0
|
|
|
|
|
0
|
DEBUG("use $module"); |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
0
|
my $error; |
54
|
0
|
|
|
0
|
|
0
|
try { eval "use $module" } catch { $error = $_ }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
55
|
0
|
0
|
|
|
|
0
|
LOGDIE $error if $error; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# create authen_simple_obj and push it to the modules array |
58
|
0
|
0
|
|
|
|
0
|
my $authen_obj = $module->new( $authen_modules->{$module} ) |
59
|
|
|
|
|
|
|
or LOGDIE "Couldn't create $module object\n"; |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
0
|
push @authen_simple_objects, $authen_obj; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# and make the authen_simple object, see perldoc Authen::Simple |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
0
|
DEBUG('build the authenticator object'); |
67
|
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
0
|
$authen_singleton = Authen::Simple->new(@authen_simple_objects) |
69
|
|
|
|
|
|
|
or LOGDIE "Couldn't create the Authen::Simple object\n"; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
0
|
return 1; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item $capo->authenticate($username, $password) |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Call the authenticator object with credentials. Returns true on success and false on failure. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub authenticate { |
81
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
82
|
|
|
|
|
|
|
|
83
|
1
|
|
|
|
|
4
|
my $username = $_[0]; |
84
|
|
|
|
|
|
|
|
85
|
1
|
|
|
|
|
7
|
DEBUG("try to authenticate user $username"); |
86
|
|
|
|
|
|
|
|
87
|
1
|
50
|
|
|
|
14
|
if ( $self->cfg->{MOCK_AUTHEN} ) { |
88
|
|
|
|
|
|
|
|
89
|
1
|
|
|
|
|
7
|
DEBUG("mock authentication for user $username"); |
90
|
|
|
|
|
|
|
|
91
|
1
|
50
|
|
|
|
18
|
return 1 if $username =~ m/^(mock|fake|foo|bar|baz)/i; |
92
|
0
|
|
|
|
|
|
return; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
return $authen_singleton->authenticate(@_); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=back |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 SEE ALSO |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
L |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 AUTHOR |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Karl Gaissmaier, C<< >> |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Copyright 2010-2013 Karl Gaissmaier, all rights reserved. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This distribution is free software; you can redistribute it and/or modify it |
115
|
|
|
|
|
|
|
under the terms of either: |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
a) the GNU General Public License as published by the Free Software |
118
|
|
|
|
|
|
|
Foundation; either version 2, or (at your option) any later version, or |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
b) the Artistic License version 2.0. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=cut |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# vim: sw=4 |