line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Dancer Authentication, Security and Role-Based Access Control Framework! |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Dancer::Plugin::Auth::RBAC; |
4
|
|
|
|
|
|
|
BEGIN { |
5
|
3
|
|
|
3
|
|
1123052
|
$Dancer::Plugin::Auth::RBAC::VERSION = '1.110720'; |
6
|
|
|
|
|
|
|
} |
7
|
3
|
|
|
3
|
|
34
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
101
|
|
8
|
3
|
|
|
3
|
|
21
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
122
|
|
9
|
3
|
|
|
3
|
|
24
|
use Dancer qw/:syntax/; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
18
|
|
10
|
3
|
|
|
3
|
|
3853
|
use Dancer::Plugin; |
|
3
|
|
|
|
|
4351
|
|
|
3
|
|
|
|
|
706
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $settings = {}; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
register auth => sub { |
15
|
6
|
|
|
6
|
|
98164
|
$settings = plugin_setting; |
16
|
6
|
|
|
|
|
174
|
return Dancer::Plugin::Auth::RBAC->new(@_) |
17
|
|
|
|
|
|
|
}; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
register authd => sub { |
20
|
0
|
0
|
|
0
|
|
0
|
if ( session('user') ) { |
21
|
0
|
0
|
|
|
|
0
|
if ( session('user')->{id} ) { |
22
|
0
|
|
|
|
|
0
|
return true; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
} |
25
|
0
|
|
|
|
|
0
|
return false; |
26
|
|
|
|
|
|
|
}; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub new { |
30
|
6
|
|
|
6
|
0
|
16
|
my $class = shift; |
31
|
6
|
|
|
|
|
19
|
my @credentials = @_; |
32
|
|
|
|
|
|
|
|
33
|
6
|
|
|
|
|
34
|
my $credentialsClass = |
34
|
|
|
|
|
|
|
__PACKAGE__ . "::Credentials::" . $settings->{credentials}->{class}; |
35
|
|
|
|
|
|
|
{ |
36
|
3
|
|
|
3
|
|
27
|
no warnings 'redefine'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
707
|
|
|
6
|
|
|
|
|
15
|
|
37
|
6
|
|
|
|
|
40
|
$credentialsClass =~ s/::/\//g; |
38
|
6
|
|
|
|
|
1835
|
require "$credentialsClass.pm"; |
39
|
6
|
|
|
|
|
39
|
$credentialsClass =~ s/\//::/g; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
6
|
|
|
|
|
58
|
my $self = {}; |
43
|
6
|
|
|
|
|
19
|
bless $self, $class; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# return $credentialsClass->new |
46
|
|
|
|
|
|
|
# unless scalar @credentials; |
47
|
|
|
|
|
|
|
|
48
|
6
|
|
|
|
|
32
|
my $user = session('user'); |
49
|
|
|
|
|
|
|
|
50
|
6
|
100
|
|
|
|
31425
|
if ($user) { |
51
|
|
|
|
|
|
|
# reset authentication errors |
52
|
4
|
|
|
|
|
13
|
$user->{error} = []; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
else { |
55
|
|
|
|
|
|
|
# initialize user session object |
56
|
2
|
|
|
|
|
14
|
$user = { |
57
|
|
|
|
|
|
|
id => undef, |
58
|
|
|
|
|
|
|
name => undef, |
59
|
|
|
|
|
|
|
login => undef, |
60
|
|
|
|
|
|
|
roles => [], |
61
|
|
|
|
|
|
|
error => [] |
62
|
|
|
|
|
|
|
}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
6
|
|
|
|
|
31
|
session 'user' => $user; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
#return $credentialsClass->new->authorize($settings->{credentials}->{options}, @credentials) |
68
|
|
|
|
|
|
|
#? $self : undef; |
69
|
|
|
|
|
|
|
|
70
|
6
|
|
|
|
|
24993
|
$credentialsClass->new->authorize($settings->{credentials}->{options}, @credentials); |
71
|
6
|
|
|
|
|
30499
|
return $self; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub asa { |
75
|
12
|
|
|
12
|
0
|
20534
|
my $self = shift; |
76
|
12
|
|
|
|
|
68
|
my $permissionsClass = |
77
|
|
|
|
|
|
|
__PACKAGE__ . "::Permissions::" . $settings->{permissions}->{class}; |
78
|
|
|
|
|
|
|
{ |
79
|
3
|
|
|
3
|
|
16
|
no warnings 'redefine'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
428
|
|
|
12
|
|
|
|
|
21
|
|
80
|
12
|
|
|
|
|
81
|
$permissionsClass =~ s/::/\//g; |
81
|
12
|
|
|
|
|
1039
|
require "$permissionsClass.pm"; |
82
|
12
|
|
|
|
|
68
|
$permissionsClass =~ s/\//::/g; |
83
|
|
|
|
|
|
|
} |
84
|
12
|
|
|
|
|
134
|
return $permissionsClass->new->subject_asa($settings->{permissions}->{options}, @_); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub can { |
88
|
10
|
|
|
10
|
0
|
9837
|
my $self = shift; |
89
|
10
|
|
|
|
|
35
|
my $permissionsClass = |
90
|
|
|
|
|
|
|
__PACKAGE__ . "::Permissions::" . $settings->{permissions}->{class}; |
91
|
|
|
|
|
|
|
{ |
92
|
3
|
|
|
3
|
|
21
|
no warnings 'redefine'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
1040
|
|
|
10
|
|
|
|
|
15
|
|
93
|
10
|
|
|
|
|
51
|
$permissionsClass =~ s/::/\//g; |
94
|
10
|
|
|
|
|
798
|
require "$permissionsClass.pm"; |
95
|
10
|
|
|
|
|
49
|
$permissionsClass =~ s/\//::/g; |
96
|
|
|
|
|
|
|
} |
97
|
10
|
|
|
|
|
81
|
return $permissionsClass->new->subject_can($settings->{permissions}->{options}, @_); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub roles { |
101
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
102
|
0
|
0
|
|
|
|
0
|
if (@_) { |
103
|
0
|
|
|
|
|
0
|
my $user = session('user'); |
104
|
0
|
0
|
|
|
|
0
|
if ($user) { |
105
|
0
|
0
|
|
|
|
0
|
if ($user->{id}) { |
106
|
0
|
|
|
|
|
0
|
push @{$user->{roles}}, @_; |
|
0
|
|
|
|
|
0
|
|
107
|
0
|
|
|
|
|
0
|
session 'user' => $user; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
else { |
112
|
0
|
|
|
|
|
0
|
my $user = session('user'); |
113
|
0
|
0
|
|
|
|
0
|
if ($user) { |
114
|
0
|
0
|
|
|
|
0
|
if ($user->{id}) { |
115
|
0
|
|
|
|
|
0
|
return $user->{roles}; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub errors { |
122
|
6
|
|
|
6
|
0
|
4391
|
my $self = shift; |
123
|
6
|
|
|
|
|
16
|
return @{ session('user')->{error} }; |
|
6
|
|
|
|
|
30
|
|
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub revoke { |
127
|
6
|
|
|
6
|
0
|
16
|
my $self = shift; |
128
|
6
|
|
|
|
|
34
|
return session 'user' => {}; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
register_plugin; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
1; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
__END__ |