line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Authentication::Credential::MultiFactor; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
25909
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
39
|
|
4
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
33
|
|
5
|
1
|
|
|
1
|
|
21
|
use 5.014002; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
44
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
519
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '1.0'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has config => (is => 'ro', required => 1); |
12
|
|
|
|
|
|
|
has factors => (is => 'ro', default => sub { [] }); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub BUILDARGS { |
15
|
|
|
|
|
|
|
my ($class, $config, $app, $realm) = @_; |
16
|
|
|
|
|
|
|
{ config => $config, app => $app, realm => $realm }; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub BUILD { |
20
|
|
|
|
|
|
|
my ($self, $args) = @_; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my ($app, $realm) = @{$args}{qw(app realm)}; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
foreach my $factor (@{$self->config->{'factors'}}) { |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $credential_class = $factor->{'class'}; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
if ($credential_class !~ /^\+(.*)$/ ) { |
29
|
|
|
|
|
|
|
$credential_class = "Catalyst::Authentication::Credential::${credential_class}"; |
30
|
|
|
|
|
|
|
} else { |
31
|
|
|
|
|
|
|
$credential_class = $1; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Catalyst::Utils::ensure_class_loaded( $credential_class ); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
$app->log->debug('LOADED class: '.$credential_class) if $app->debug; |
37
|
|
|
|
|
|
|
push @{$self->factors}, $credential_class->new($factor, $app, $realm); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub authenticate { |
43
|
|
|
|
|
|
|
my ($self, $c, $realm, $authinfo) = @_; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $user_obj; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
foreach my $factor (@{$self->factors}) { |
48
|
|
|
|
|
|
|
$c->log->debug('Trying to authenticate agains '.$factor) if $c->debug; |
49
|
|
|
|
|
|
|
return unless eval { $user_obj = $factor->authenticate($c, $realm, $authinfo) }; |
50
|
|
|
|
|
|
|
$c->log->debug('Authentication successful against '.$factor) if $c->debug; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
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.0 |
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 |