line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Authentication::Credential::MultiFactor; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
20783
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
5
|
1
|
|
|
1
|
|
12
|
use 5.01.102; |
|
1
|
|
|
|
|
6
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
912
|
use Moose; |
|
1
|
|
|
|
|
529018
|
|
|
1
|
|
|
|
|
7
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '1.2_1'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has config => (is => 'ro', required => 1); |
12
|
|
|
|
|
|
|
has factors => (is => 'ro', default => sub { [] }); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub BUILDARGS { |
15
|
0
|
|
|
0
|
1
|
|
my ($class, $config, $app, $realm) = @_; |
16
|
0
|
|
|
|
|
|
{ config => $config, app => $app, realm => $realm }; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub BUILD { |
20
|
0
|
|
|
0
|
0
|
|
my ($self, $args) = @_; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
my ($app, $realm) = @{$args}{qw(app realm)}; |
|
0
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
foreach my $factor (@{$self->config->{'factors'}}) { |
|
0
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
my $credential_class = $factor->{'class'}; |
27
|
|
|
|
|
|
|
|
28
|
0
|
0
|
|
|
|
|
if ($credential_class !~ /^\+(.*)$/ ) { |
29
|
0
|
|
|
|
|
|
$credential_class = "Catalyst::Authentication::Credential::${credential_class}"; |
30
|
|
|
|
|
|
|
} else { |
31
|
0
|
|
|
|
|
|
$credential_class = $1; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
Catalyst::Utils::ensure_class_loaded( $credential_class ); |
35
|
|
|
|
|
|
|
|
36
|
0
|
0
|
|
|
|
|
$app->log->debug('LOADED class: '.$credential_class) if $app->debug; |
37
|
0
|
|
|
|
|
|
push @{$self->factors}, $credential_class->new($factor, $app, $realm); |
|
0
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub authenticate { |
43
|
0
|
|
|
0
|
0
|
|
my ($self, $c, $realm, $authinfo) = @_; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my $user_obj; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
foreach my $factor (@{$self->factors}) { |
|
0
|
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
|
$c->log->debug('Trying to authenticate agains '.$factor) if $c->debug; |
49
|
0
|
0
|
|
|
|
|
return unless eval { $user_obj = $factor->authenticate($c, $realm, $authinfo) }; |
|
0
|
|
|
|
|
|
|
50
|
0
|
0
|
|
|
|
|
$c->log->debug('Authentication successful against '.$factor) if $c->debug; |
51
|
|
|
|
|
|
|
} |
52
|
0
|
|
|
|
|
|
return $user_obj; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |
56
|
|
|
|
|
|
|
__END__ |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 NAME |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Catalyst::Authentication::Credential::MultiFactor |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 DESCRIPTION |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Provides multi-factor authentication to your Catalyst app |
66
|
|
|
|
|
|
|
Uses the Catalyst::Plugin::Authentication system. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 SYNOPSIS |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
use Catalyst qw( |
71
|
|
|
|
|
|
|
... |
72
|
|
|
|
|
|
|
Authentication |
73
|
|
|
|
|
|
|
... |
74
|
|
|
|
|
|
|
); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__PACKAGE__->config( |
77
|
|
|
|
|
|
|
name => 'myApp', |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
.... |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
'Plugin::Authentication' => { |
82
|
|
|
|
|
|
|
... |
83
|
|
|
|
|
|
|
default => { |
84
|
|
|
|
|
|
|
credential => { |
85
|
|
|
|
|
|
|
class => 'MultiFactor', |
86
|
|
|
|
|
|
|
factors => [ |
87
|
|
|
|
|
|
|
{ |
88
|
|
|
|
|
|
|
class => 'YubiKey', |
89
|
|
|
|
|
|
|
api_id => 1337, |
90
|
|
|
|
|
|
|
api_key => 'foo/BAr/baz818=', |
91
|
|
|
|
|
|
|
}, |
92
|
|
|
|
|
|
|
{ |
93
|
|
|
|
|
|
|
class => 'Password', |
94
|
|
|
|
|
|
|
user_model => 'DB::login', |
95
|
|
|
|
|
|
|
password_type => 'self_check', |
96
|
|
|
|
|
|
|
}, |
97
|
|
|
|
|
|
|
.... add more plugins! |
98
|
|
|
|
|
|
|
], |
99
|
|
|
|
|
|
|
}, |
100
|
|
|
|
|
|
|
}, |
101
|
|
|
|
|
|
|
}, |
102
|
|
|
|
|
|
|
); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 INSTALLATION |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
To install this module type the following: |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
perl Makefile.PL |
109
|
|
|
|
|
|
|
make |
110
|
|
|
|
|
|
|
make test |
111
|
|
|
|
|
|
|
make install |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 SEE ALSO |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
L<Catalyst::Plugin::Authentication> |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
This module requires these other modules and libraries: |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Moose |
122
|
|
|
|
|
|
|
namespace::autoclean |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENCE |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Copyright (C) 2012 by Cédric Jeanneret |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
129
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.14.2 or, |
130
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=cut |