line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Dancer::Plugin::Auth::RBAC authentication via the Dancer configuration file! |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Dancer::Plugin::Auth::RBAC::Credentials::Config; |
4
|
|
|
|
|
|
|
BEGIN { |
5
|
2
|
|
|
2
|
|
42
|
$Dancer::Plugin::Auth::RBAC::Credentials::Config::VERSION = '1.110720'; |
6
|
|
|
|
|
|
|
} |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
68
|
|
9
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
63
|
|
10
|
2
|
|
|
2
|
|
11
|
use base qw/Dancer::Plugin::Auth::RBAC::Credentials/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1390
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub authorize { |
14
|
|
|
|
|
|
|
|
15
|
6
|
|
|
6
|
1
|
17
|
my ($self, $options, @arguments) = @_; |
16
|
6
|
|
|
|
|
15
|
my ($login, $password) = @arguments; |
17
|
|
|
|
|
|
|
|
18
|
6
|
|
|
|
|
11
|
my $settings = $Dancer::Plugin::Auth::RBAC::settings; |
19
|
|
|
|
|
|
|
|
20
|
6
|
100
|
|
|
|
21
|
if ($login) { |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# authorize a new account using supplied credentials |
23
|
|
|
|
|
|
|
|
24
|
4
|
|
|
|
|
10
|
my $accounts = $options->{accounts}; |
25
|
|
|
|
|
|
|
|
26
|
4
|
50
|
|
|
|
17
|
unless ($password) { |
27
|
0
|
|
|
|
|
0
|
$self->errors('login and password are required'); |
28
|
0
|
|
|
|
|
0
|
return 0; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
4
|
50
|
|
|
|
18
|
if (defined $accounts->{$login}) { |
32
|
|
|
|
|
|
|
|
33
|
4
|
50
|
|
|
|
18
|
if (defined $accounts->{$login}->{password}) { |
34
|
|
|
|
|
|
|
|
35
|
4
|
50
|
|
|
|
92
|
if ($accounts->{$login}->{password} =~ /^$password$/) { |
36
|
|
|
|
|
|
|
|
37
|
4
|
|
|
|
|
31
|
my $session_data = { |
38
|
|
|
|
|
|
|
id => $login, |
39
|
|
|
|
|
|
|
name => $accounts->{$login}->{name} || ucfirst($login), |
40
|
|
|
|
|
|
|
login => $login, |
41
|
4
|
|
33
|
|
|
36
|
roles => [@{$accounts->{$login}->{roles}}], |
42
|
|
|
|
|
|
|
error => [] |
43
|
|
|
|
|
|
|
}; |
44
|
4
|
|
|
|
|
23
|
return $self->credentials($session_data); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
else { |
48
|
0
|
|
|
|
|
0
|
$self->errors('login and/or password is invalid'); |
49
|
0
|
|
|
|
|
0
|
return 0; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
0
|
|
|
|
|
0
|
$self->errors('attempting to access as inaccessible account'); |
55
|
0
|
|
|
|
|
0
|
return 0; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
else { |
60
|
0
|
|
|
|
|
0
|
$self->errors('login and/or password is invalid'); |
61
|
0
|
|
|
|
|
0
|
return 0; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
else { |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# check if current user session is authorized |
68
|
|
|
|
|
|
|
|
69
|
2
|
|
|
|
|
13
|
my $user = $self->credentials; |
70
|
2
|
50
|
33
|
|
|
6479
|
if (($user->{id} || $user->{login}) && !@{$user->{error}}) { |
|
0
|
|
33
|
|
|
0
|
|
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
0
|
return $user; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
else { |
76
|
2
|
|
|
|
|
21
|
$self->errors('you are not authorized', 'your session may have ended'); |
77
|
2
|
|
|
|
|
14
|
return 0; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |
85
|
|
|
|
|
|
|
__END__ |