line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Lazy::Authz; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
2887
|
use CGI::Lazy::Globals; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
115
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
511
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
8
|
|
|
|
|
|
|
sub AUTOLOAD { |
9
|
0
|
|
|
0
|
|
|
my $self = shift; |
10
|
0
|
|
|
|
|
|
my $perm = shift; |
11
|
|
|
|
|
|
|
|
12
|
0
|
|
|
|
|
|
my $name = our $AUTOLOAD; |
13
|
0
|
0
|
|
|
|
|
return if $name =~ /::DESTROY$/; |
14
|
0
|
|
|
|
|
|
my @list = split "::", $name; |
15
|
|
|
|
|
|
|
|
16
|
0
|
|
|
|
|
|
my $groupName = pop @list; |
17
|
0
|
|
|
|
|
|
my $userID = $self->q->session->data->authn->{id}; |
18
|
0
|
|
|
|
|
|
my @binds = ($groupName, $userID); |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
my $map = $self->_mapTable; |
21
|
0
|
|
|
|
|
|
my $user = $self->_userTable; |
22
|
0
|
|
|
|
|
|
my $group = $self->_groupTable; |
23
|
0
|
|
|
|
|
|
my $flag = $self->_permFlag; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
my $query = "select * from $map->{name} inner join $group->{name} on $group->{primarykey} = $map->{groupField} where $group->{groupNameField} = ? and $map->{userField} = ?"; |
26
|
|
|
|
|
|
|
|
27
|
0
|
0
|
|
|
|
|
if ($perm) { |
28
|
0
|
|
|
|
|
|
$query .= " and $perm = ?"; |
29
|
0
|
|
|
|
|
|
push @binds, $flag; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# $self->q->util->debug->edump($query, $groupName, $userID); |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my $result = $self->q->db->get($query, @binds); |
35
|
|
|
|
|
|
|
|
36
|
0
|
0
|
|
|
|
|
if ($result) { |
37
|
0
|
|
|
|
|
|
return 1; |
38
|
|
|
|
|
|
|
} else { |
39
|
0
|
|
|
|
|
|
return; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
45
|
|
|
|
|
|
|
sub _groupTable { |
46
|
0
|
|
|
0
|
|
|
my $self = shift; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
return $self->{_groupTable}; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
52
|
|
|
|
|
|
|
sub q { |
53
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
return $self->{_q}; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
59
|
|
|
|
|
|
|
sub _mapTable { |
60
|
0
|
|
|
0
|
|
|
my $self = shift; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
return $self->{_mapTable}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
66
|
|
|
|
|
|
|
sub new { |
67
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
68
|
0
|
|
|
|
|
|
my $q = shift; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
0
|
|
|
|
my $self = { |
71
|
|
|
|
|
|
|
_q => $q, |
72
|
|
|
|
|
|
|
_userTable => $q->plugin->authz->{userTable}, |
73
|
|
|
|
|
|
|
_groupTable => $q->plugin->authz->{groupTable}, |
74
|
|
|
|
|
|
|
_mapTable => $q->plugin->authz->{mapTable}, |
75
|
|
|
|
|
|
|
_permFlag => $q->plugin->authz->{permFlag} || 1, |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
}; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
bless $self, $class; |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
die "Cannot use Authz without Authn. Please enable Authn plugin" unless $self->q->authn; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
return $self; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
87
|
|
|
|
|
|
|
sub _permFlag { |
88
|
0
|
|
|
0
|
|
|
my $self = shift; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
return $self->{_permFlag}; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
94
|
|
|
|
|
|
|
sub _userTable { |
95
|
0
|
|
|
0
|
|
|
my $self = shift; |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
return $self->{_userTable}; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
1 |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
__END__ |