line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Authentication::Credential::MultiFactor; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
21537
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
5
|
1
|
|
|
1
|
|
12
|
use 5.01.102; |
|
1
|
|
|
|
|
7
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
961
|
use Moose; |
|
1
|
|
|
|
|
511378
|
|
|
1
|
|
|
|
|
7
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '1.2'; |
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
|
|
|
|
|
|
|
=head VERSION |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Version 1.2 |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 DESCRIPTION |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Provides multi-factor authentication to your Catalyst app |
70
|
|
|
|
|
|
|
Uses the Catalyst::Plugin::Authentication system. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 SYNOPSIS |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
use Catalyst qw( |
75
|
|
|
|
|
|
|
... |
76
|
|
|
|
|
|
|
Authentication |
77
|
|
|
|
|
|
|
... |
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__PACKAGE__->config( |
81
|
|
|
|
|
|
|
name => 'myApp', |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
.... |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
'Plugin::Authentication' => { |
86
|
|
|
|
|
|
|
... |
87
|
|
|
|
|
|
|
default => { |
88
|
|
|
|
|
|
|
credential => { |
89
|
|
|
|
|
|
|
class => 'MultiFactor', |
90
|
|
|
|
|
|
|
factors => [ |
91
|
|
|
|
|
|
|
{ |
92
|
|
|
|
|
|
|
class => 'YubiKey', |
93
|
|
|
|
|
|
|
api_id => 1337, |
94
|
|
|
|
|
|
|
api_key => 'foo/BAr/baz818=', |
95
|
|
|
|
|
|
|
}, |
96
|
|
|
|
|
|
|
{ |
97
|
|
|
|
|
|
|
class => 'Password', |
98
|
|
|
|
|
|
|
user_model => 'DB::login', |
99
|
|
|
|
|
|
|
password_type => 'self_check', |
100
|
|
|
|
|
|
|
}, |
101
|
|
|
|
|
|
|
.... add more plugins! |
102
|
|
|
|
|
|
|
], |
103
|
|
|
|
|
|
|
}, |
104
|
|
|
|
|
|
|
}, |
105
|
|
|
|
|
|
|
}, |
106
|
|
|
|
|
|
|
); |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 INSTALLATION |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
To install this module type the following: |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
perl Makefile.PL |
113
|
|
|
|
|
|
|
make |
114
|
|
|
|
|
|
|
make test |
115
|
|
|
|
|
|
|
make install |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
This module requires these other modules and libraries: |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Moose |
122
|
|
|
|
|
|
|
namespace::autoclean |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head 1COPYRIGHT 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 |