SPOPS/Secure.pm

filter: Statementstmt 21.3% 63 / 295 Branchbran 0.0% 0 / 176 Conditioncond 0.0% 0 / 77 MC/DCmcdc 0.0% 0 / 49 Subroutinesub 47.0% 16 / 34 Podpod 31.2% 5 / 16 totaltotal 12.9% 84 / 647 CC 123 SCAR 54.6
CC
123
Cov
11%
create_initial_security
600.0
get_security_scopes
420.0
set_security
306.0
CRAP 234.2
↑ Summary SPOPS/ClassFactory/DefaultBehavior.pm »
1 package SPOPS::Secure;
2  
3 # $Id: Secure.pm,v 3.14 2004/06/02 00:48:21 lachoy Exp $
4  
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use base qw( Exporter );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use vars qw( $EMPTY );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Data::Dumper qw( Dumper );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Log::Log4perl qw( get_logger );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 $SPOPS::Secure::VERSION = sprintf("%d.%02d", q$Revision: 3.14 $ =~ /(\d+)\.(\d+)/);
12  
13 # Stuff for security constants and exporting
14  
15 3 ▶use constant SEC_LEVEL_NONE => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use constant SEC_LEVEL_SUMMARY => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use constant SEC_LEVEL_READ => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use constant SEC_LEVEL_WRITE => 8;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 3 ▶use constant SEC_LEVEL_NONE_VERBOSE => 'NONE';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 ▶use constant SEC_LEVEL_SUMMARY_VERBOSE => 'SUMMARY';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 3 ▶use constant SEC_LEVEL_READ_VERBOSE => 'READ';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 3 ▶use constant SEC_LEVEL_WRITE_VERBOSE => 'WRITE';
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 3 ▶use constant SEC_SCOPE_USER => 'u';
Subroutine BEGIN: called CC=1 SCAR=0.0
26 3 ▶use constant SEC_SCOPE_GROUP => 'g';
Subroutine BEGIN: called CC=1 SCAR=0.0
27 3 ▶use constant SEC_SCOPE_WORLD => 'w';
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 3 my $log = get_logger();
30  
31 3 my @LEVEL = qw( SEC_LEVEL_NONE SEC_LEVEL_SUMMARY SEC_LEVEL_READ SEC_LEVEL_WRITE );
32 3 my @SCOPE = qw( SEC_SCOPE_USER SEC_SCOPE_GROUP SEC_SCOPE_WORLD );
33 3 my @VRBS = qw( SEC_LEVEL_NONE_VERBOSE SEC_LEVEL_SUMMARY_VERBOSE
34 SEC_LEVEL_READ_VERBOSE SEC_LEVEL_WRITE_VERBOSE );
35  
36 3 @SPOPS::Secure::EXPORT_OK = ( '$EMPTY', @LEVEL, @SCOPE, @VRBS );
37 3 %SPOPS::Secure::EXPORT_TAGS = (
38 all => [ @LEVEL, @SCOPE, @VRBS ],
39 scope => [ @SCOPE ],
40 level => [ @LEVEL ],
41 verbose => [ @VRBS ],
42 );
43  
44 # Dummy (empty) hashref to pass back if we need to
45 # basically deny the request -- e.g., they asked for a
46 # user that isn't an object, they asked for the current
47 # user and there is none, etc.
48  
49 3 $EMPTY = {
50 SEC_SCOPE_WORLD() => SEC_LEVEL_NONE,
51 SEC_SCOPE_USER() => SEC_LEVEL_NONE,
52 SEC_SCOPE_GROUP() => {}
53 };
54  
55 3 my %LEVEL_VERBOSE = (
56 SEC_LEVEL_NONE_VERBOSE() => SEC_LEVEL_NONE,
57 SEC_LEVEL_SUMMARY_VERBOSE() => SEC_LEVEL_SUMMARY,
58 SEC_LEVEL_READ_VERBOSE() => SEC_LEVEL_READ,
59 SEC_LEVEL_WRITE_VERBOSE() => SEC_LEVEL_WRITE,
60 );
61  
62 3 my %LEVEL_CODE = map { $LEVEL_VERBOSE{ $_ } => $_ } keys %LEVEL_VERBOSE;
63  
64 3 my $INITIAL_SECURITY_DEFAULT = SEC_LEVEL_NONE;
65  
66 # This needs to be down here so we don't get into a deadlock (and die)
67 # situation
68  
69 3 require SPOPS::Exception::Security;
70 3 require SPOPS::Secure::Util;
71  
72 ########################################
73 # RETRIEVE SECURITY
74 ########################################
75  
76 # Typical calls:
77 # $self->check_action_security({ required => SEC_LEVEL_WRITE });
78 # $class->check_action_security({ required => SEC_LEVEL_READ, id => $id });
79  
80 # Note that we return SEC_LEVEL_WRITE to all requests where the object
81 # does not have an ID -- meaning that the object has not yet been
82 # saved, and this object creation security must be handled by the
83 # application rather than SPOPS
84  
85 # Returns the security level if ok, die()s with an error message if not
86  
87 # TODO: What is the difference between check_security and
88 # check_action_security? Do we need both? Should we only expose
89 # check_action_security()?
90  
91 0 ▶sub check_action_security {
Subroutine check_action_security: not called CC=14 SCAR=53.5
Pod undocumented
92 0 my ( $item, $p ) = @_;
93 0 ▶ $log->is_debug &&
Branch: 2 branches
BranchTrueFalseTotal
$log->is_debug and $log->debug("Trying to check security on: ", ref $item ? ref($item) . ' ' . $item->id : $item, " with params: ", Dumper($p)) 0 0 0
ref $item ? : 0 0 0
94 $log->debug( "Trying to check security on: ",
95 ( ref $item ) ? ref( $item ) . " " . $item->id : $item,
96 " with params: ", Dumper( $p ) );
97  
98 # since the assumption outlined above (only saved objects have ids)
99 # might not be true in all cases, provide an escape route for classes
100 # that need security and want to handle their ids themselves
101  
102 0 ▶ return SEC_LEVEL_WRITE if ( $p->{is_add} ); # or ! $item->is_saved );
Branch: 1 branch
BranchTrueFalseTotal
if $p->{"is_add"} 0 0 0
103  
104 # If the class has told us they're not using security (even tho
105 # SPOPS::Secure is in the 'isa', then everyone can do everything
106  
107 0 ▶ return SEC_LEVEL_WRITE if ( $item->no_security );
Branch: 1 branch
BranchTrueFalseTotal
if $item->no_security 0 0 0
108  
109 # This gets filled with the found security level, oddly, the user
110 # can pass in a security level if it's already been found
111  
112 0 my $level = $p->{security_level};
113  
114 0 my ( $class, $id );
115  
116 # If not already defined, find the security level explicitly
117  
118 0 ▶ unless ( $level ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($level) 0 0 0
119  
120 # Check to see that the ID exists -- if not, it's an add and will
121 # not be checked since SPOPS relies on your application to implement
122 # who should and should not create an object.
123  
124 0 ▶ $class = ref $item || $item;
Condition0%0/3
ref $item || $item
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $item || $item
ref $item $item
Truth table0%0/3
A || B
A= ref $itemB= $item
ABresult
1X1
011
000
125 0 ▶ $id = ( ref $item ) ? $item->id : $p->{id};
Branch: 1 branch
BranchTrueFalseTotal
ref $item ? : 0 0 0
126 0 ▶ unless ( $id ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($id) 0 0 0
127 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("ID not found, returning WRITE security") 0 0 0
128 $log->info( "ID not found, returning WRITE security" );
129 0 return SEC_LEVEL_WRITE;
130 }
131 $log->is_debug &&
132 0 ▶ $log->debug( "Checking action on $class [$id] and required ",
Branch: 1 branch
BranchTrueFalseTotal
$log->is_debug and $log->debug("Checking action on $class [$id] and required ", qq[level is [$p->{"required"}]]) 0 0 0
133 "level is [$p->{required}]" );
134  
135 # Calls to SPOPS::Secure->... note that we do not need to
136 # explicitly pass in group/user information, since SPOPS::Secure
137 # will retrieve it for us.
138  
139 # TODO: Revisit that we allow exceptions to bubble up
140  
141 0 ▶ $level = $class->check_security({ class => $class,
Branch: 1 branch
BranchTrueFalseTotal
ref $item ? : 0 0 0
142 object_id => $id,
143 object => ( ref $item ) ? $item : undef });
144  
145 }
146 $log->is_info &&
147 0 ▶ $log->info( "Found security level of ($level)" );
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Found security level of ($level)") 0 0 0
148  
149 # If the level is below what is necessary call
150 # register_security_error() which should set an error message and
151 # die with a general one.
152  
153 0 ▶ if ( $level < $p->{required} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level < $p->{"required"}) 0 0 0
154 $class->register_security_error({ class => $class, id => $id,
155 level => $level,
156 0 required => $p->{required} });
157 }
158 0 return $level; # Rock and roll
159 }
160  
161  
162 0 ▶sub register_security_error {
Subroutine register_security_error: not called CC=2 SCAR=17.9
Pod undocumented
163 0 my ( $class, $p ) = @_;
164 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info(qq[Cannot access $p->{"class"} record with ID $p->{"id"}; ], qq[access: $p->{"level"} while $p->{"required"} is required.]) 0 0 0
165 $log->info( "Cannot access $p->{class} record with ID $p->{id}; ",
166 "access: $p->{level} while $p->{required} is required." );
167 SPOPS::Exception::Security->throw( "Access denied due to security level",
168 { required => $p->{required},
169 0 found => $p->{level} } );
170 }
171  
172  
173 # Returns: security level for a particular object/class given a scope
174 # and if necessary, a scope_id; should always return at least the
175 # security level for the WORLD scope, since everything must have at
176 # least a permission for the WORLD scope.
177  
178 0 ▶sub check_security {
Subroutine check_security: not called CC=14 SCAR=53.5
Pod documented
179 0 my ( $class, $p ) = @_;
180 0 my $sec_info = $p->{sec_info};
181 0 ▶ unless ( $sec_info ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sec_info) 0 0 0
182 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Retrieving security information using get_security()") 0 0 0
183 $log->info( "Retrieving security information using get_security()" );
184 0 ▶ $p->{user} = shift @{ $p->{user} } if ( ref $p->{user} eq 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $p->{"user"} eq "ARRAY" 0 0 0
185  
186 # Retrieve security. If a subclass wants to implement a different
187 # way of implementing security, this is the method to override.
188  
189 # TODO: Revisit exception bubble up from here
190  
191 0 $sec_info = $class->get_security( $p );
192 }
193  
194 $log->is_info &&
195 0 ▶ $log->info( "Security information:\n", Dumper( $sec_info ) );
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Security information:\n", Dumper($sec_info)) 0 0 0
196  
197 # If a user security level exists, return it
198  
199 0 ▶ if ( my $user_level = $sec_info->{ SEC_SCOPE_USER() } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $user_level = $sec_info->{"u"}) 0 0 0
200 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Return level [$user_level] at scope USER.") 0 0 0
201 $log->info( "Return level [$user_level] at scope USER." );
202 0 return $user_level;
203 }
204  
205 # Go through the groups; if there are groups, we return the highest
206 # level among them.
207  
208 0 my $group_max = 0;
209 0 ▶ $sec_info->{ SEC_SCOPE_GROUP() } ||= {};
Condition0%0/2
$sec_info->{"g"} ||= {}
l!l
00
MC/DC0%0/1
$sec_info->{"g"} ||= {}
$sec_info->{"g"}
Truth table0%0/2
A
A= $sec_info->{"g"}
Aresult
11
00
210 0 foreach my $gid ( keys %{ $sec_info->{ SEC_SCOPE_GROUP() } } ) {
211 0 my $group_level = $sec_info->{ SEC_SCOPE_GROUP() }{ $gid };
212 0 ▶ next unless ( $group_level );
Branch: 1 branch
BranchTrueFalseTotal
unless $group_level 0 0 0
213 0 ▶ $group_max = ( $group_level > $group_max ) ? $group_level : $group_max;
Branch: 1 branch
BranchTrueFalseTotal
$group_level > $group_max ? : 0 0 0
214 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Level of GROUP [$gid] is [$group_level]") 0 0 0
215 $log->info( "Level of GROUP [$gid] is [$group_level]" );
216 }
217 0 ▶ return $group_max if ( $group_max );
Branch: 1 branch
BranchTrueFalseTotal
if $group_max 0 0 0
218  
219 0 my $world_level = $sec_info->{ SEC_SCOPE_WORLD() };
220 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Return level [$world_level] at scope WORLD") 0 0 0
221 $log->info( "Return level [$world_level] at scope WORLD" );
222 0 return $world_level;
223 }
224  
225  
226 # Returns hashref
227  
228 0 ▶sub get_security {
Subroutine get_security: not called CC=7 SCAR=40.3
Pod documented
229 0 my ( $item, $p ) = @_;
230  
231 # Since we can pass in the class/oid, those take precedence
232  
233 0 my ( $class, $oid ) = SPOPS::Secure::Util->find_class_and_oid( $item, $p );
234 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Checking security for [$class] [$oid] with:\n", Dumper($p)) 0 0 0
235 $log->info( "Checking security for [$class] [$oid] with:\n", Dumper( $p ) );
236 0 my ( $user, $group_list ) = $item->get_security_scopes( $p );
237  
238 0 ▶ if ( my $security_info = $item->_check_superuser( $user, $group_list ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $security_info = $item->_check_superuser($user, $group_list)) 0 0 0
239 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Superuser is logged in, can do anything") 0 0 0
240 $log->info( "Superuser is logged in, can do anything" );
241 0 return $security_info;
242 }
243  
244 my $sec_obj_class = $p->{security_object_class} ||
245 0 ▶ $item->global_security_object_class;
Condition0%0/3
$p->{'security_object_class'} || $item->global_security_object_class
l!l&&r!l&&!r
000
MC/DC0%0/2
$p->{'security_object_class'} || $item->global_security_object_class
$p->{'security_object_class'} $item->global_security_object_class
Truth table0%0/3
A || B
A= $p->{'security_object_class'}B= $item->global_security_object_class
ABresult
1X1
011
000
246 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Using security object [$sec_obj_class]") 0 0 0
247 $log->info( "Using security object [$sec_obj_class]" );
248  
249 # TODO: Revisit exception bubble up from here
250  
251 0 my $sec_listing = $sec_obj_class->fetch_by_object( $class,
252 { object_id => $oid,
253 user => $user,
254 group => $group_list } );
255 0 ▶ return $sec_listing || \%{ $EMPTY };
Condition0%0/2
$sec_listing || \%{$SPOPS::Secure::EMPTY;}
l!l
00
MC/DC0%0/1
$sec_listing || \%{$SPOPS::Secure::EMPTY;}
$sec_listing
Truth table0%0/2
A
A= $sec_listing
Aresult
11
00
256 }
257  
258  
259  
260 0 ▶sub get_security_scopes {
Subroutine get_security_scopes: not called CC=20 SCAR=60.4
Pod documented
261 0 my ( $item, $p ) = @_;
262 0 my $user = undef;
263 0 my $group_list = [];
264  
265 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Checking security scopes with:\n", Dumper($p)) 0 0 0
266 $log->info( "Checking security scopes with:\n", Dumper( $p ) );
267  
268 # If both user and group(s) are passed in, we need to modify the
269 # group list to include the groups that the user belongs to as well
270 # as the groups specified
271  
272 0 ▶ if ( $p->{user} and $p->{group} ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($p->{'user'} and $p->{'group'}) { } 0 0 0
elsif (not $p->{'user'} || $p->{'group'}) { } 0 0 0
elsif ($p->{'user'}) { } 0 0 0
elsif ($p->{'group'}) { } 0 0 0
Condition0%0/3
$p->{"user"} and $p->{"group"}
!ll&&!rl&&r
000
MC/DC0%0/2
$p->{"user"} and $p->{"group"}
$p->{"user"} $p->{"group"}
Truth table0%0/3
A and B
A= $p->{"user"}B= $p->{"group"}
ABresult
0X0
100
111
273 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Both user and group were specified.") 0 0 0
274 $log->info( "Both user and group were specified." );
275 0 $user = $p->{user};
276 0 $group_list = eval { $user->group };
277 0 ▶ $log->warn( "Cannot fetch groups from user record: $@." ) if ( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
278 0 ▶ push @{ $group_list }, ( ref $p->{group} eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
ref $p->{'group'} eq 'ARRAY' ? : 0 0 0
279 0 ? @{ $p->{group} } : ( $p->{group} );
280 }
281  
282 # The default (no user, no group) is just to get the user and its
283 # groups
284  
285 ▶ elsif ( ! $p->{user} and ! $p->{group} ) {
Condition0%0/3
$p->{'user'} || $p->{'group'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$p->{'user'} || $p->{'group'}
$p->{'user'} $p->{'group'}
Truth table0%0/3
A || B
A= $p->{'user'}B= $p->{'group'}
ABresult
1X1
011
000
286 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Neither user/group specified, using logins.") 0 0 0
287 $log->info( "Neither user/group specified, using logins." );
288 0 $user = $item->global_user_current;
289 0 ▶ $group_list = $item->global_group_current || [];
Condition0%0/2
$item->global_group_current || []
l!l
00
MC/DC0%0/1
$item->global_group_current || []
$item->global_group_current
Truth table0%0/2
A
A= $item->global_group_current
Aresult
11
00
290  
291 # If no user or group was passed in, and we cannot retrieve a
292 # user object with the global_user_current() or group objects
293 # with global_group_current(), then all we want to get is the
294 # WORLD security level, which means we can skip the
295 # user/group_list stuff altogether
296  
297 # NOTE: even tho it doesn't appear, there IS a dependency between
298 # the next two clauses; that is, you *MUST NOT* check to see if
299 # $user->{user_id} == 1 if there actually is no user. Otherwise
300 # perl will autovivify a hashref in $R->{auth}{user} which
301 # will throw a 800-pound monkey wrench into operations.
302 # We really need to look into that, it's quite brittle.
303  
304 0 ▶ unless ( $user or scalar @{ $group_list } > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($user or scalar @{$group_list;} > 0) 0 0 0
Condition0%0/3
$user or scalar @{$group_list;} > 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$user or scalar @{$group_list;} > 0
$user scalar @{$group_list;} > 0
Truth table0%0/3
A or B
A= $userB= scalar @{$group_list;} > 0
ABresult
1X1
011
000
305 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("No user or groups found.") 0 0 0
306 $log->info( "No user or groups found." );
307 0 $user = undef;
308 0 $group_list = undef;
309 }
310 }
311  
312 # If we were given a user to check, base the group_list around the
313 # groups the user belongs to
314  
315 elsif ( $p->{user} ) {
316 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Only user specified; using user's groups.") 0 0 0
317 $log->info( "Only user specified; using user's groups." );
318 0 $user = $p->{user};
319 0 $group_list = eval { $user->group; };
320 0 ▶ $log->warn( "Cannot fetch groups from user record: $@." ) if ( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
321 }
322  
323 # Otherwise, the group list is based on whatever was passed in
324  
325 elsif ( $p->{group} ) {
326 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Only group specified.") 0 0 0
327 $log->info( "Only group specified." );
328 $group_list = ( ref $p->{group} eq 'ARRAY' )
329 0 ▶ ? $p->{group}: [ $p->{group} ];
Branch: 1 branch
BranchTrueFalseTotal
ref $p->{'group'} eq 'ARRAY' ? : 0 0 0
330 }
331 0 return ( $user, $group_list );
332 }
333  
334  
335 ########################################
336 # SET SECURITY
337 ########################################
338  
339  
340 0 ▶sub create_initial_security {
Subroutine create_initial_security: not called CC=24 SCAR=64.0
Pod documented
341 0 my ( $item, $p ) = @_;
342  
343 # Since we can pass in the class/oid, those take precedence
344  
345 0 my ( $class, $oid ) = SPOPS::Secure::Util->find_class_and_oid( $item, $p );
346 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Setting initial security for $class ($oid)") 0 0 0
347 $log->info( "Setting initial security for $class ($oid)" );
348  
349 # \%init describes the initial security to create for this object;
350 # note that \%init may describe code to execute or it may simply
351 # describe a level to denote
352  
353 0 my $init = $class->creation_security;
354 0 ▶ return undef unless ( ref $init and scalar keys %{ $init } );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $init and scalar keys %{$init;} 0 0 0
Condition0%0/2
ref $init and scalar keys %{$init;}
!ll
00
MC/DC0%0/1
ref $init and scalar keys %{$init;}
ref $init
Truth table0%0/2
A
A= ref $init
Aresult
00
11
355  
356 # Get the current user and groups
357  
358 0 my $user = $class->global_user_current;
359 0 my $group = $class->global_group_current;
360  
361 # \%level holds the actual security settings for this object
362  
363 0 my $level = {};
364  
365 # If our level assignment looks like this:
366 # creation_security => {
367 # code => [ 'MyApp::SecurityPolicy' => 'handler' ] },
368 # },
369 #
370 # Then we execute "MyApp::SecurityPolicy->handler( \% ), passing the
371 # parameters class and oid (for the object), $user (current user
372 # object) and $group (arrayref of groups the user belongs to)
373 #
374  
375 # The code should return a hashref of either scope => SEC_LEVEL_* (in
376 # the case of USER and WORLD) or scope => { scope_id => SEC_LEVEL* }
377 # (in the case of GROUP). If an 'undef' is passed for a scope then
378 # that scope will not be processed. For example:
379 #
380 # return { u => undef,
381 # g => { $main_gid => SEC_LEVEL_READ, $admin_gid => SEC_LEVEL_WRITE },
382 # w => SEC_LEVEL_NONE };
383  
384 0 ▶ if ( ref $init->{code} eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $init->{'code'} eq 'ARRAY') { } 0 0 0
385 0 my ( $pkg, $method ) = @{ $init->{code} };
386 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("$pkg->$method being executed for security") 0 0 0
387 $log->info( "$pkg\-\>$method being executed for security" );
388 0 $level = $pkg->$method({ class => $class,
389 object_id => $oid,
390 user => $user,
391 group => $group });
392 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Result of code:\n", Dumper($level)) 0 0 0
393 $log->info( "Result of code:\n", Dumper( $level ) );
394 }
395  
396 # Go through each scope specified in the init and evaluate the
397 # specification for initial security.
398  
399 else {
400  
401 # Create a list of the group_id for ez-reference
402  
403 0 my @gid = map { $_->{group_id} } @{ $group };
404  
405 SCOPE:
406 0 foreach my $scope ( keys %{ $init } ) {
407 0 my $todo = $init->{ $scope };
408 0 ▶ next unless ( $todo );
Branch: 1 branch
BranchTrueFalseTotal
unless $todo 0 0 0
409 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Determining security level for $scope") 0 0 0
410 $log->info( "Determining security level for $scope" );
411  
412 # If our level assignment looks like this:
413 # creation_security => {
414 # ...,
415 # g => { 3 => WRITE },
416 # ...,
417 # },
418 #
419 # Then we want to do the assignments for the IDs in that scope
420  
421 0 ▶ if ( ref $todo eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $todo eq 'HASH') { } 0 0 0
422 0 $level->{ $scope } = { map { $_ => $LEVEL_VERBOSE{ uc $todo->{$_} } }
423 0 keys %{ $todo } };
424 }
425  
426 # Otherwise it will look like this:
427 # creation_security => {
428 # ...,
429 # g => 'WRITE',
430 # ...,
431 # },
432 #
433 # Which means we'd want to apply WRITE for all the groups
434 # to which this user belongs. Be careful with this!
435 # (remember that 'public' is a group, too).
436  
437 else {
438 0 ▶ if ( $scope eq 'w' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($scope eq 'w') { } 0 0 0
elsif ($scope eq 'u' and ref $user) { } 0 0 0
elsif ($scope eq 'g') { } 0 0 0
439 0 $level->{w} = $LEVEL_VERBOSE{ uc $todo };
440 }
441 ▶ elsif ( $scope eq 'u' and ref $user ) {
Condition0%0/3
$scope eq "u" and ref $user
!ll&&!rl&&r
000
MC/DC0%0/2
$scope eq "u" and ref $user
$scope eq "u" ref $user
Truth table0%0/3
A and B
A= $scope eq "u"B= ref $user
ABresult
0X0
100
111
442 0 $level->{u} = { $user->id() => $LEVEL_VERBOSE{ uc $todo } };
443 }
444 elsif ( $scope eq 'g' ) {
445 0 $level->{g} = { map { $_ => $LEVEL_VERBOSE{ uc $todo } } @gid };
446 }
447 }
448 }
449 $log->is_info &&
450 0 ▶ $log->info( "Level assigned:\n", Dumper( $level ) );
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Level assigned:\n", Dumper($level)) 0 0 0
451 }
452  
453 # Now that \%level is all setup, process it
454  
455 # Ensure that this is a *$class* (this was the focus of bugs earlier,
456 # exhibited by something in the sys_security table that looks like
457 # "This::Class=HASH(0x8bb7028)"
458  
459 0 ▶ my $obj_class = ref $class || $class;
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
460  
461 # First do WORLD
462  
463 0 ▶ $level->{w} ||= $INITIAL_SECURITY_DEFAULT;
Condition0%0/3
$level->{"w"} ||= $INITIAL_SECURITY_DEFAULT
l!l&&r!l&&!r
000
MC/DC0%0/2
$level->{"w"} ||= $INITIAL_SECURITY_DEFAULT
$level->{"w"} $INITIAL_SECURITY_DEFAULT
Truth table0%0/3
A ||= B
A= $level->{"w"}B= $INITIAL_SECURITY_DEFAULT
ABresult
1X1
011
000
464 $class->set_item_security({
465 class => $obj_class,
466 object_id => $oid,
467 security_level => $level->{w},
468 0 scope => SEC_SCOPE_WORLD });
469 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Set initial security for WORLD to $level") 0 0 0
470 $log->info( "Set initial security for WORLD to $level" );
471  
472 # Doing the user and group perms is identical, so we don't
473 # need to partition by scope for them
474  
475 # Note that we're relying on the fact that u => SEC_SCOPE_USER and
476 # g => SEC_SCOPE_GROUP; if this changes we'll have to do a little
477 # mapping from the scopes in $level to the actual scope values
478  
479 # TODO: Should collect exceptions as we go?
480  
481 0 foreach my $scope ( ( SEC_SCOPE_USER, SEC_SCOPE_GROUP ) ) {
482 0 ▶ next unless ( ref $level->{ $scope } eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $level->{$scope} eq "HASH" 0 0 0
483 0 foreach my $id ( keys %{ $level->{ $scope } } ) {
484 0 ▶ $id ||= '';
Condition0%0/2
$id ||= ""
l!l
00
MC/DC0%0/1
$id ||= ""
$id
Truth table0%0/2
A
A= $id
Aresult
11
00
485 $class->set_item_security({
486 class => $obj_class,
487 object_id => $oid,
488 0 security_level => $level->{ $scope }{ $id },
489 scope => $scope,
490 scope_id => $id });
491 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Set initial security for $scope ($id) to $level->{$scope}{$id}") 0 0 0
492 $log->info( "Set initial security for $scope ($id) to $level->{$scope}{$id}" );
493 }
494 }
495 0 return 1;
496 }
497  
498  
499 # Set security for one or more objects
500  
501 0 ▶sub set_security {
Subroutine set_security: not called CC=17 SCAR=57.2
Pod documented
502 0 my ( $item, $p ) = @_;
503 my $sec_obj_class = $p->{security_object_class} ||
504 0 ▶ $item->global_security_object_class;
Condition0%0/3
$p->{'security_object_class'} || $item->global_security_object_class
l!l&&r!l&&!r
000
MC/DC0%0/2
$p->{'security_object_class'} || $item->global_security_object_class
$p->{'security_object_class'} $item->global_security_object_class
Truth table0%0/3
A || B
A= $p->{'security_object_class'}B= $item->global_security_object_class
ABresult
1X1
011
000
505  
506 0 ▶ my $level = $p->{level} || $p->{security_level};
Condition0%0/3
$p->{'level'} || $p->{'security_level'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$p->{'level'} || $p->{'security_level'}
$p->{'level'} $p->{'security_level'}
Truth table0%0/3
A || B
A= $p->{'level'}B= $p->{'security_level'}
ABresult
1X1
011
000
507  
508 # First ensure that both a level is specified...
509  
510 0 ▶ unless ( $level ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($level) 0 0 0
511 0 SPOPS::Exception->throw( 'Cannot set security: no permissions defined' );
512 }
513  
514 # ...and that a scope is specified
515  
516 0 ▶ unless ( $p->{scope} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($p->{"scope"}) 0 0 0
517 0 SPOPS::Exception->throw( 'Cannot set security: no scope defined' );
518 }
519  
520 # Since we can pass in the class/oid, those take precedence
521  
522 0 my ( $class, $oid ) = SPOPS::Secure::Util->find_class_and_oid( $item, $p );
523 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Checking security for $class [$oid]") 0 0 0
524 $log->info( "Checking security for $class [$oid]" );
525  
526 # If we were passed a particular scope, just return
527 # the results of updating that information
528  
529 0 ▶ unless ( ref $p->{scope} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $p->{"scope"}) 0 0 0
530 0 ▶ if ( $p->{scope} eq SEC_SCOPE_WORLD ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($p->{'scope'} eq 'w') { } 0 0 0
elsif ($p->{'scope'} eq 'g' or $p->{'scope'} eq 'u') { } 0 0 0
531 return $item->set_item_security({
532 class => $class,
533 object_id => $oid,
534 security_level => $level,
535 scope => $p->{scope},
536 0 scope_id => $p->{scope_id} } );
537 }
538  
539 # For user/group, we can pass in multiple items for which we
540 # want to set security acting upon a particular class/object;
541 # the test for this is if $level is a hashref.
542  
543 ▶ elsif ( $p->{scope} eq SEC_SCOPE_GROUP or $p->{scope} eq SEC_SCOPE_USER ) {
Condition0%0/3
$p->{"scope"} eq "g" or $p->{"scope"} eq "u"
l!l&&r!l&&!r
000
MC/DC0%0/2
$p->{"scope"} eq "g" or $p->{"scope"} eq "u"
$p->{"scope"} eq "g" $p->{"scope"} eq "u"
Truth table0%0/3
A or B
A= $p->{"scope"} eq "g"B= $p->{"scope"} eq "u"
ABresult
1X1
011
000
544 0 ▶ if ( ref $level eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $level eq "HASH") 0 0 0
545 return $item->set_multiple_security({
546 class => $class,
547 object_id => $oid,
548 security_level => $level,
549 0 scope => $p->{scope} } );
550 }
551 return $item->set_item_security({
552 class => $class,
553 object_id => $oid,
554 security_level => $level,
555 scope => $p->{scope},
556 0 scope_id => $p->{scope_id} } );
557 }
558 0 SPOPS::Exception->throw( "Set security failed: unrecognized scope " .
559 "[$p->{scope}] defined" );
560 }
561  
562 # If we've made it here, the scope should be a reference. But if
563 # it's not an arrayref, we have a problem
564  
565 0 ▶ if ( ref $p->{scope} ne 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $p->{"scope"} ne "ARRAY") 0 0 0
566 0 SPOPS::Exception->throw( "Set security failed: unrecognized scope " .
567 "[$p->{scope}] defined" );
568 }
569  
570 # If level is not a hashref (since we are using multiple scopes)
571 # at this point, we have a problem
572  
573 0 ▶ if ( ref $level ne 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $level ne "HASH") 0 0 0
574 0 SPOPS::Exception->throw( "Set security failed: there are multiple scopes" .
575 "but security_level does not match " );
576 }
577  
578 # If we were passed multiple scope entries, go through each one
579 # and total up the items changed for return. Note that we no
580 # longer have a need for scope_id (for user/group) since that logic
581 # is embedded within the level hashref
582  
583 # Note that *removing* security must be done outside this routine.
584 # That is, you can't simply pass a full list of 'new' security
585 # options for a particular object/class and expect this method to
586 # sort them out for you
587  
588 0 my $count = 0;
589  
590 SCOPE:
591 0 foreach my $scope ( @{ $p->{scope} } ) {
592 0 ▶ if ( $scope eq SEC_SCOPE_WORLD ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($scope eq 'w') { } 0 0 0
elsif ($scope eq 'g' or $scope eq 'u') { } 0 0 0
593 $count += $item->set_item_security({
594 class => $class,
595 object_id => $oid,
596 scope => $scope,
597 0 security_level => $level->{ $scope } });
598 }
599 ▶ elsif ( $scope eq SEC_SCOPE_GROUP or $scope eq SEC_SCOPE_USER ) {
Condition0%0/3
$scope eq "g" or $scope eq "u"
l!l&&r!l&&!r
000
MC/DC0%0/2
$scope eq "g" or $scope eq "u"
$scope eq "g" $scope eq "u"
Truth table0%0/3
A or B
A= $scope eq "g"B= $scope eq "u"
ABresult
1X1
011
000
600 $count += $item->set_multiple_security({
601 class => $class,
602 object_id => $oid,
603 scope => $scope,
604 0 security_level => $level->{ $scope } });
605 }
606 else {
607 0 $log->warn( "Cannot set security for scope [$scope] since it is not ",
608 join( '/', SEC_SCOPE_WORLD, SEC_SCOPE_USER, SEC_SCOPE_GROUP ) );
609 }
610 }
611 0 return $count;
612 }
613  
614  
615 0 ▶sub set_item_security {
Subroutine set_item_security: not called CC=9 SCAR=45.0
Pod undocumented
616 0 my ( $item, $p ) = @_;
617  
618 0 ▶ my $level = $p->{level} || $p->{security_level};
Condition0%0/3
$p->{'level'} || $p->{'security_level'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$p->{'level'} || $p->{'security_level'}
$p->{'level'} $p->{'security_level'}
Truth table0%0/3
A || B
A= $p->{'level'}B= $p->{'security_level'}
ABresult
1X1
011
000
619  
620 # Since we can pass in the class/oid, those take precedence
621  
622 0 my ( $class, $oid ) = SPOPS::Secure::Util->find_class_and_oid( $item, $p );
623  
624 0 ▶ $p->{scope_id} ||= '';
Condition0%0/2
$p->{"scope_id"} ||= ""
l!l
00
MC/DC0%0/1
$p->{"scope_id"} ||= ""
$p->{"scope_id"}
Truth table0%0/2
A
A= $p->{"scope_id"}
Aresult
11
00
625 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info(qq[Modifying scope $p->{"scope"} ($p->{"scope_id"}) for ], "$class ($oid) with $level") 0 0 0
626 $log->info( "Modifying scope $p->{scope} ($p->{scope_id}) for ",
627 "$class ($oid) with $level" );
628  
629 my $sec_obj_class = $p->{security_object_class} ||
630 0 ▶ $item->global_security_object_class;
Condition0%0/3
$p->{'security_object_class'} || $item->global_security_object_class
l!l&&r!l&&!r
000
MC/DC0%0/2
$p->{'security_object_class'} || $item->global_security_object_class
$p->{'security_object_class'} $item->global_security_object_class
Truth table0%0/3
A || B
A= $p->{'security_object_class'}B= $item->global_security_object_class
ABresult
1X1
011
000
631 my $obj = $sec_obj_class->fetch_match( $class,
632 { object_id => $oid,
633 scope => $p->{scope},
634 0 scope_id => $p->{scope_id} } );
635 0 ▶ return 1 if ( $obj and $obj->{security_level} == $level );
Branch: 1 branch
BranchTrueFalseTotal
if $obj and $obj->{"security_level"} == $level 0 0 0
Condition0%0/3
$obj and $obj->{"security_level"} == $level
!ll&&!rl&&r
000
MC/DC0%0/2
$obj and $obj->{"security_level"} == $level
$obj $obj->{"security_level"} == $level
Truth table0%0/3
A and B
A= $objB= $obj->{"security_level"} == $level
ABresult
0X0
100
111
636  
637 0 ▶ unless ( $obj ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($obj) 0 0 0
638 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Current object does not exist. Creating one [$oid]") 0 0 0
639 $log->info( "Current object does not exist. Creating one [$oid]" );
640 $obj = $sec_obj_class->new({ class => $class,
641 object_id => $oid,
642 scope => $p->{scope},
643 0 scope_id => $p->{scope_id} });
644 }
645  
646  
647 # Otherwise set the level and save, letting any errors from the
648 # save bubble up
649  
650 0 $obj->{security_level} = $level;
651 0 return $obj->save;
652 }
653  
654  
655 0 ▶sub set_multiple_security {
Subroutine set_multiple_security: not called CC=7 SCAR=40.3
Pod undocumented
656 0 my ( $item, $p ) = @_;
657  
658 # Since we can pass in the class/oid, those take precedence
659  
660 0 my ( $class, $oid ) = SPOPS::Secure::Util->find_class_and_oid( $item, $p );
661 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Setting multiple security for $class ($oid) and ", qq[scope $p->{"scope"}.]) 0 0 0
662 $log->info( "Setting multiple security for $class ($oid) and ",
663 "scope $p->{scope}." );
664  
665 my $sec_obj_class = $p->{security_object_class} ||
666 0 ▶ $item->global_security_object_class;
Condition0%0/3
$p->{'security_object_class'} || $item->global_security_object_class
l!l&&r!l&&!r
000
MC/DC0%0/2
$p->{'security_object_class'} || $item->global_security_object_class
$p->{'security_object_class'} $item->global_security_object_class
Truth table0%0/3
A || B
A= $p->{'security_object_class'}B= $item->global_security_object_class
ABresult
1X1
011
000
667  
668 0 ▶ my $level = $p->{level} || $p->{security_level};
Condition0%0/3
$p->{'level'} || $p->{'security_level'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$p->{'level'} || $p->{'security_level'}
$p->{'level'} $p->{'security_level'}
Truth table0%0/3
A || B
A= $p->{'level'}B= $p->{'security_level'}
ABresult
1X1
011
000
669  
670 0 $item->_remove_superuser_level( $level );
671  
672 # Count up the number of modifications we are making -- if there
673 # are none then we're done
674  
675 0 ▶ return 1 unless ( scalar keys %{ $level } );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar keys %{$level;} 0 0 0
676 0 my $count = 0;
677  
678 ITEM:
679 0 foreach my $id ( keys %{ $level } ) {
680 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Setting ID $id to $level->{$id}") 0 0 0
681 $log->info( "Setting ID $id to $level->{$id}" );
682 $count += $item->set_item_security({ class => $class,
683 object_id => $oid,
684 scope => $p->{scope},
685 scope_id => $id,
686 0 security_level => $level->{ $id } });
687 }
688 0 return $count;
689 }
690  
691  
692 0 ▶sub remove_item_security {
Subroutine remove_item_security: not called CC=7 SCAR=40.3
Pod undocumented
693 0 my ( $item, $p ) = @_;
694 0 ▶ if ( $p->{scope} ne SEC_SCOPE_WORLD and $p->{scope_id} == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p->{"scope"} ne "w" and $p->{"scope_id"} == 1) 0 0 0
Condition0%0/3
$p->{"scope"} ne "w" and $p->{"scope_id"} == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$p->{"scope"} ne "w" and $p->{"scope_id"} == 1
$p->{"scope"} ne "w" $p->{"scope_id"} == 1
Truth table0%0/3
A and B
A= $p->{"scope"} ne "w"B= $p->{"scope_id"} == 1
ABresult
0X0
100
111
695 0 $log->warn( "Will not remove security with scope $p->{scope} ($p->{scope_id}) - admin." );
696 0 return undef;
697 }
698  
699 # Since we can pass in the class/oid, those take precedence
700  
701 0 my ( $class, $oid ) = SPOPS::Secure::Util->find_class_and_oid( $item, $p );
702 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Removing security for $class ($oid) with ", qq[scope $p->{"scope"} ($p->{"scope_id"})]) 0 0 0
703 $log->info( "Removing security for $class ($oid) with ",
704 "scope $p->{scope} ($p->{scope_id})" );
705  
706 my $sec_obj_class = $p->{security_object_class} ||
707 0 ▶ $item->global_security_object_class;
Condition0%0/3
$p->{'security_object_class'} || $item->global_security_object_class
l!l&&r!l&&!r
000
MC/DC0%0/2
$p->{'security_object_class'} || $item->global_security_object_class
$p->{'security_object_class'} $item->global_security_object_class
Truth table0%0/3
A || B
A= $p->{'security_object_class'}B= $item->global_security_object_class
ABresult
1X1
011
000
708 0 my $obj = eval { $sec_obj_class->fetch_match(
709 $class,
710 { object_id => $oid,
711 scope => $p->{scope},
712 0 scope_id => $p->{scope_id} }) };
713 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
714 0 $log->warn( "Error found trying to match parameters to an existing object\n",
715 "Error: $@->{error}\nSQL: $@->{sql}" );
716 }
717 0 ▶ unless ( $obj ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($obj) 0 0 0
718 0 $log->warn( "Security object does not exist with parameters, so we cannot remove it." );
719 0 return undef;
720 }
721  
722 # Let error trickle up
723  
724 0 return $obj->remove;
725 }
726  
727  
728 ########################################
729 # SCOPE RETRIEVAL METHODS
730 ########################################
731  
732 # If no users/groups are available, these ensure we just check WORLD
733  
734 0 ▶sub global_user_current {
Subroutine global_user_current: not called CC=2 SCAR=17.9
Pod undocumented
735 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Using empty definition for current user; this may not be what you want") 0 0 0
736 $log->info( "Using empty definition for current user; this may not be what you want" );
737 return undef
738 0 }
739  
740  
741 0 ▶sub global_group_current {
Subroutine global_group_current: not called CC=2 SCAR=17.9
Pod undocumented
742 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Using empty definition for current groups; this may not be what you want") 0 0 0
743 $log->info( "Using empty definition for current groups; this may not be what you want" );
744 0 return [];
745 }
746  
747  
748 ########################################
749 # ROOT CHECKS
750 ########################################
751  
752 0 ▶sub get_superuser_id { return 1 }
Subroutine get_superuser_id: not called CC=1 SCAR=6.9
Pod undocumented
753 0 ▶sub get_supergroup_id { return 1 }
Subroutine get_supergroup_id: not called CC=1 SCAR=6.9
Pod undocumented
754  
755 # Define comparison operations for superuser/supergroup
756  
757 0 ▶sub is_superuser {
Subroutine is_superuser: not called CC=1 SCAR=6.9
Pod undocumented
758 0 my ( $class, $id ) = @_;
759 0 return ( $id eq $class->get_superuser_id );
760 }
761  
762 0 ▶sub is_supergroup {
Subroutine is_supergroup: not called CC=1 SCAR=6.9
Pod undocumented
763 0 my ( $class, @id ) = @_;
764 0 my $super_gid = $class->get_supergroup_id;
765 0 return grep { $_ eq $super_gid } @id;
766 }
767  
768  
769 # See if this is the superuser or a member of the supergroup
770  
771 0 ▶sub _check_superuser {
Subroutine _check_superuser: not called CC=8 SCAR=42.8
772 0 my ( $item, $user, $group_list ) = @_;
773 0 ▶ return undef unless ( $user or $group_list );
Branch: 1 branch
BranchTrueFalseTotal
unless $user or $group_list 0 0 0
Condition0%0/3
$user or $group_list
l!l&&r!l&&!r
000
MC/DC0%0/2
$user or $group_list
$user $group_list
Truth table0%0/3
A or B
A= $userB= $group_list
ABresult
1X1
011
000
774 0 my %allow_all = %{ $EMPTY };
775 0 $allow_all{ SEC_SCOPE_USER() } = SEC_LEVEL_WRITE;
776  
777 0 ▶ if ( ref $user and $item->is_superuser( $user->{user_id} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $user and $item->is_superuser($user->{"user_id"})) 0 0 0
Condition0%0/3
ref $user and $item->is_superuser($user->{"user_id"})
!ll&&!rl&&r
000
MC/DC0%0/2
ref $user and $item->is_superuser($user->{"user_id"})
ref $user $item->is_superuser($user->{"user_id"})
Truth table0%0/3
A and B
A= ref $userB= $item->is_superuser($user->{"user_id"})
ABresult
0X0
100
111
778 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("User is superuser, checking ($item)") 0 0 0
779 $log->info( "User is superuser, checking ($item)" );
780 0 return \%allow_all;
781 }
782 0 ▶ if ( ref $group_list eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $group_list eq "ARRAY") 0 0 0
783 0 ▶ if ( $item->is_supergroup( map { $_->{group_id} } @{ $group_list } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item->is_supergroup(map({$_->{"group_id"};} @{$group_list;}))) 0 0 0
784 0 return \%allow_all ;
785 }
786 }
787 0 return undef;
788 }
789  
790  
791 # Removes the superuser and supergroup levels from \%level
792  
793 0 ▶sub _remove_superuser_level {
Subroutine _remove_superuser_level: not called CC=3 SCAR=24.8
794 0 my ( $class, $level ) = @_;
795 0 ▶ return unless ( ref $level eq 'HASH' and scalar keys %{ $level } );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $level eq "HASH" and scalar keys %{$level;} 0 0 0
Condition0%0/2
ref $level eq "HASH" and scalar keys %{$level;}
!ll
00
MC/DC0%0/1
ref $level eq "HASH" and scalar keys %{$level;}
ref $level eq "HASH"
Truth table0%0/2
A
A= ref $level eq "HASH"
Aresult
00
11
796 0 my $super_gid = $class->get_supergroup_id;
797 0 delete $level->{ $class->get_superuser_id };
798 0 delete $level->{ $class->get_supergroup_id };
799 }
800  
801  
802 3 1;
803  
804 __END__
↑ Summary SPOPS/ClassFactory/DefaultBehavior.pm »