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