line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SIAM::User; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
58
|
|
4
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
120
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
12
|
use base 'SIAM::Object'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
160
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
1577
|
use SIAM::Privilege; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
18
|
|
9
|
2
|
|
|
2
|
|
181
|
use SIAM::AccessScope; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
9
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
SIAM::User - User object class |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $user = $siam->get_user($uid); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 METHODS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head2 has_privilege |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
$user->has_privilege('ViewContract', $contract) |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Expects a privilege string and an object. Returns true if the object matches |
27
|
|
|
|
|
|
|
the privilege |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub has_privilege |
32
|
|
|
|
|
|
|
{ |
33
|
6
|
|
|
6
|
1
|
558
|
my $self = shift; |
34
|
6
|
|
|
|
|
10
|
my $priv = shift; |
35
|
6
|
|
|
|
|
8
|
my $obj = shift; |
36
|
|
|
|
|
|
|
|
37
|
6
|
|
|
|
|
38
|
my $privileges = $self->get_contained_objects |
38
|
|
|
|
|
|
|
('SIAM::Privilege', |
39
|
|
|
|
|
|
|
{'match_attribute' => ['siam.privilege.type', [$priv]]}); |
40
|
|
|
|
|
|
|
|
41
|
6
|
|
|
|
|
16
|
foreach my $privilege (@{$privileges}) |
|
6
|
|
|
|
|
13
|
|
42
|
|
|
|
|
|
|
{ |
43
|
6
|
100
|
|
|
|
20
|
if( $privilege->match_object($obj) ) |
44
|
|
|
|
|
|
|
{ |
45
|
4
|
|
|
|
|
18
|
return 1; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
2
|
|
|
|
|
15
|
return undef; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 get_objects_by_privilege |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
$user->get_objects_by_privilege('ViewContract', 'SIAM::Contract', $siam) |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Expects 3 arguments: privilege string; object class; and a container object. |
59
|
|
|
|
|
|
|
Returns arrayref with all matching objects. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub get_objects_by_privilege |
64
|
|
|
|
|
|
|
{ |
65
|
3
|
|
|
3
|
1
|
5
|
my $self = shift; |
66
|
3
|
|
|
|
|
3
|
my $priv = shift; |
67
|
3
|
|
|
|
|
5
|
my $objclass = shift; |
68
|
3
|
|
|
|
|
4
|
my $objcontainer = shift; |
69
|
|
|
|
|
|
|
|
70
|
3
|
|
|
|
|
23
|
my $privileges = $self->get_contained_objects |
71
|
|
|
|
|
|
|
('SIAM::Privilege', |
72
|
|
|
|
|
|
|
{'match_attribute' => ['siam.privilege.type', [$priv]]}); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Driver may return the same scope twice, so we keep track of which scopes |
75
|
|
|
|
|
|
|
# we've already seen |
76
|
|
|
|
|
|
|
|
77
|
3
|
|
|
|
|
8
|
my @scopes; |
78
|
|
|
|
|
|
|
my %scopes_seen; |
79
|
|
|
|
|
|
|
|
80
|
3
|
|
|
|
|
5
|
foreach my $privilege (@{$privileges}) |
|
3
|
|
|
|
|
8
|
|
81
|
|
|
|
|
|
|
{ |
82
|
3
|
100
|
|
|
|
13
|
if( $privilege->matches_all($objclass) ) |
83
|
|
|
|
|
|
|
{ |
84
|
1
|
|
|
|
|
5
|
return $objcontainer->get_contained_objects($objclass); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
else |
87
|
|
|
|
|
|
|
{ |
88
|
2
|
|
|
|
|
10
|
my $id = $privilege->scope_id; |
89
|
2
|
50
|
|
|
|
11
|
if( not $scopes_seen{$id} ) |
90
|
|
|
|
|
|
|
{ |
91
|
2
|
|
|
|
|
8
|
push(@scopes, |
92
|
|
|
|
|
|
|
new SIAM::AccessScope($self->_driver, $id)); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# Scopes may overlap, so we put the object IDs in a hash |
98
|
2
|
|
|
|
|
4
|
my %object_ids; |
99
|
2
|
|
|
|
|
3
|
foreach my $scope (@scopes) |
100
|
|
|
|
|
|
|
{ |
101
|
2
|
|
|
|
|
7
|
my $ids = $scope->get_object_ids(); |
102
|
2
|
|
|
|
|
4
|
foreach my $id (@{$ids}) |
|
2
|
|
|
|
|
4
|
|
103
|
|
|
|
|
|
|
{ |
104
|
2
|
|
|
|
|
21
|
$object_ids{$id} = 1; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# Retrieve the matching objects |
109
|
|
|
|
|
|
|
|
110
|
2
|
|
|
|
|
4
|
my $ret = []; |
111
|
2
|
|
|
|
|
9
|
foreach my $id ( keys %object_ids ) |
112
|
|
|
|
|
|
|
{ |
113
|
2
|
|
|
|
|
3
|
push(@{$ret}, $self->instantiate_object($objclass, $id)); |
|
2
|
|
|
|
|
13
|
|
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
2
|
|
|
|
|
29
|
return $ret; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# mandatory attributes |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
my $mandatory_attributes = |
129
|
|
|
|
|
|
|
[ 'siam.user.uid' ]; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub _mandatory_attributes |
132
|
|
|
|
|
|
|
{ |
133
|
6
|
|
|
6
|
|
18
|
return $mandatory_attributes; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub _manifest_attributes |
138
|
|
|
|
|
|
|
{ |
139
|
1
|
|
|
1
|
|
2
|
my $ret = []; |
140
|
1
|
|
|
|
|
2
|
push(@{$ret}, @{$mandatory_attributes}, |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
11
|
|
141
|
1
|
|
|
|
|
3
|
@{ SIAM::Privilege->_manifest_attributes() }); |
142
|
|
|
|
|
|
|
|
143
|
1
|
|
|
|
|
6
|
return $ret; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
1; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
# Local Variables: |
149
|
|
|
|
|
|
|
# mode: cperl |
150
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
151
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
152
|
|
|
|
|
|
|
# cperl-continued-statement-offset: 4 |
153
|
|
|
|
|
|
|
# cperl-continued-brace-offset: -4 |
154
|
|
|
|
|
|
|
# cperl-brace-offset: 0 |
155
|
|
|
|
|
|
|
# cperl-label-offset: -2 |
156
|
|
|
|
|
|
|
# End: |