| 49 | 1 package Security::Authz; | 
|  | 2 use Common; | 
|  | 3 use Security; | 
|  | 4 | 
|  | 5 our @ISA = qw(Object); | 
|  | 6 | 
|  | 7 BEGIN { | 
|  | 8     DeclareProperty User => ACCESS_READ; | 
|  | 9 } | 
|  | 10 | 
|  | 11 sub _CurrentUser { | 
|  | 12     my ($class) = @_; | 
|  | 13 | 
|  | 14     if (ref $class) { | 
|  | 15         return $class->{$User}; | 
|  | 16     } else { | 
|  | 17         if (Security->CurrentSession) { | 
|  | 18             Security->CurrentSession->User; | 
|  | 19         } else { | 
|  | 20             return undef; | 
|  | 21         } | 
|  | 22     } | 
|  | 23 } | 
|  | 24 | 
|  | 25 sub demand { | 
|  | 26     my ($class,@Roles) = @_; | 
|  | 27 | 
|  | 28     return 0 if not $class->_CurrentUser; | 
|  | 29 | 
|  | 30     my %UserRoles = map { $_->Name, 1 } $class->_CurrentUser->Roles; | 
|  | 31 | 
|  | 32     return not grep {not $UserRoles{$_}} @Roles; | 
|  | 33 } |