line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dancer::Plugin::Auth::Extensible::Provider::Config; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
522
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
4
|
use base "Dancer::Plugin::Auth::Extensible::Provider::Base"; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
389
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Dancer::Plugin::Auth::Extensible::Config - example auth provider using app config |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
This is a simple authentication provider which authenticates based on a list of |
16
|
|
|
|
|
|
|
usernames, passwords (crypted, preferably - see below) and role specifications |
17
|
|
|
|
|
|
|
provided in the realm definition in your app's config file. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
This class is primarily intended as an example of what an authentication |
20
|
|
|
|
|
|
|
provider class should do; however, if you just want simple user authentication |
21
|
|
|
|
|
|
|
with user details stored in your app's config file, it may well suit your needs. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
See L for details on how to use the |
24
|
|
|
|
|
|
|
authentication framework. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SYNOPSIS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
In your app's C: |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
plugins: |
31
|
|
|
|
|
|
|
Auth::Extensible: |
32
|
|
|
|
|
|
|
realms: |
33
|
|
|
|
|
|
|
config: |
34
|
|
|
|
|
|
|
provider: Config |
35
|
|
|
|
|
|
|
users: |
36
|
|
|
|
|
|
|
- user: dave |
37
|
|
|
|
|
|
|
pass: supersecret |
38
|
|
|
|
|
|
|
roles: |
39
|
|
|
|
|
|
|
- Developer |
40
|
|
|
|
|
|
|
- Manager |
41
|
|
|
|
|
|
|
- BeerDrinker |
42
|
|
|
|
|
|
|
- user: bob |
43
|
|
|
|
|
|
|
pass: '{SSHA}+2u1HpOU7ak6iBR6JlpICpAUvSpA/zBM' |
44
|
|
|
|
|
|
|
roles: |
45
|
|
|
|
|
|
|
- Tester |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
As you can see, you can define the usernames, passwords (please use crypted |
48
|
|
|
|
|
|
|
passwords, RFC2307-style, not plain text (although plain text *is* supported, |
49
|
|
|
|
|
|
|
but really not a good idea), and the roles for each user (if you're |
50
|
|
|
|
|
|
|
not planning to use roles, omit the roles section from each user entirely). |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub authenticate_user { |
55
|
8
|
|
|
8
|
0
|
12
|
my ($self, $username, $password) = @_; |
56
|
8
|
100
|
|
|
|
18
|
my $user_details = $self->get_user_details($username) or return; |
57
|
4
|
|
|
|
|
23
|
return $self->match_password($password, $user_details->{pass}); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# Just return the whole user definition from the config; this way any additional |
61
|
|
|
|
|
|
|
# fields defined for users will just get passed through. |
62
|
|
|
|
|
|
|
sub get_user_details { |
63
|
34
|
|
|
34
|
|
41
|
my ($self, $username) = @_; |
64
|
|
|
|
|
|
|
my ($user) = grep { |
65
|
68
|
|
|
|
|
130
|
$_->{user} eq $username |
66
|
34
|
|
|
|
|
29
|
} @{ $self->realm_settings->{users} }; |
|
34
|
|
|
|
|
80
|
|
67
|
34
|
|
|
|
|
81
|
return $user; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub get_user_roles { |
71
|
8
|
|
|
8
|
0
|
9
|
my ($self, $username) = @_; |
72
|
|
|
|
|
|
|
|
73
|
8
|
50
|
|
|
|
11
|
my $user_details = $self->get_user_details($username) or return; |
74
|
8
|
|
|
|
|
19
|
return $user_details->{roles}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
|