| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Articulate::Authentication; |
|
2
|
6
|
|
|
6
|
|
2886
|
use strict; |
|
|
6
|
|
|
|
|
9
|
|
|
|
6
|
|
|
|
|
195
|
|
|
3
|
6
|
|
|
6
|
|
72
|
use warnings; |
|
|
6
|
|
|
|
|
8
|
|
|
|
6
|
|
|
|
|
219
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
6
|
|
|
6
|
|
23
|
use Moo; |
|
|
6
|
|
|
|
|
8
|
|
|
|
6
|
|
|
|
|
31
|
|
|
6
|
|
|
|
|
|
|
with 'Articulate::Role::Component'; |
|
7
|
|
|
|
|
|
|
|
|
8
|
6
|
|
|
6
|
|
1498
|
use Articulate::Syntax qw(new_credentials instantiate_array); |
|
|
6
|
|
|
|
|
11
|
|
|
|
6
|
|
|
|
|
54
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Articulate::Authentication - determine if a user who they claim to be |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# in config: |
|
17
|
|
|
|
|
|
|
components: |
|
18
|
|
|
|
|
|
|
authentication: |
|
19
|
|
|
|
|
|
|
Articulate::Authentication: |
|
20
|
|
|
|
|
|
|
providers: |
|
21
|
|
|
|
|
|
|
- Articulate::Authentication::AlwaysAllow |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# then any component can dp |
|
24
|
|
|
|
|
|
|
$component->authentication->login($credentials); |
|
25
|
|
|
|
|
|
|
$component->authentication->login($user_id, $password); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 ATTRIBUTE |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head3 providers |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
A list of providers which can respond to C. |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has providers => ( |
|
36
|
|
|
|
|
|
|
is => 'rw', |
|
37
|
|
|
|
|
|
|
default => sub { [] }, |
|
38
|
|
|
|
|
|
|
coerce => sub { instantiate_array(@_) }, |
|
39
|
|
|
|
|
|
|
); |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head3 login |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$authentication->login($credentials); |
|
44
|
|
|
|
|
|
|
$authentication->login( $user_id, $password ); |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Asks each provider if the credentials supplied match a known user. |
|
47
|
|
|
|
|
|
|
Credentials may be in whatever form will satisfy the C |
|
48
|
|
|
|
|
|
|
function in L (username and password, hashref |
|
49
|
|
|
|
|
|
|
or credentials object). |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Each provider must respond true, false, or undef. A true value means |
|
52
|
|
|
|
|
|
|
the user is authenticated. A false value means that the user exists but |
|
53
|
|
|
|
|
|
|
is explicitly refused access (this should only be used in exceptional |
|
54
|
|
|
|
|
|
|
circumstances) and an undef value means the user cannot be |
|
55
|
|
|
|
|
|
|
authenticated by the provider (but could be authenticated by some other |
|
56
|
|
|
|
|
|
|
provider). |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub login { |
|
61
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
62
|
0
|
|
|
|
|
|
my $credentials = new_credentials @_; |
|
63
|
0
|
|
|
|
|
|
foreach my $provider ( @{ $self->providers } ) { |
|
|
0
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
|
return $credentials if $provider->authenticate($credentials); |
|
65
|
0
|
0
|
|
|
|
|
return $credentials if $credentials->rejected; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
0
|
|
|
|
|
|
return $credentials->deny('No provider authenticated these credentials'); |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head3 create_user |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
$authentication->create_user( $user_id, $password ); |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Requests that a new user is created. Each provider must respond true, |
|
75
|
|
|
|
|
|
|
false, or undef. |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub create_user { |
|
80
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
81
|
0
|
|
|
|
|
|
my $user_id = shift; |
|
82
|
0
|
|
|
|
|
|
my $password = shift; |
|
83
|
0
|
|
|
|
|
|
foreach my $provider ( @{ $self->providers } ) { |
|
|
0
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
if ( defined( $provider->create_user( $user_id, $password ) ) ) { |
|
85
|
0
|
|
|
|
|
|
return ($user_id); |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
} |
|
88
|
0
|
|
|
|
|
|
return (undef); |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=over |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=item * L |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item * L |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=back |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=cut |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
1; |