47
|
1 package IMPL::Security::Context;
|
|
2 use strict;
|
|
3 use warnings;
|
|
4
|
|
5 use base qw(IMPL::Object);
|
|
6
|
|
7 use IMPL::Class::Property;
|
|
8
|
|
9 require IMPL::Security::Principal;
|
|
10
|
|
11 my $current = __PACKAGE__->nobody;
|
|
12 my $nobody;
|
|
13
|
|
14 BEGIN {
|
|
15 public property Principal => prop_get;
|
|
16 public property AssignedRoles => prop_all;
|
|
17 }
|
|
18
|
|
19 sub Impersonate {
|
|
20 my ($this,$code) = @_;
|
|
21
|
|
22 my $old = $current;
|
|
23 my $result;
|
|
24 local $@;
|
|
25 eval {
|
|
26 $result = $code->();
|
|
27 };
|
|
28 $current = $old;
|
|
29 if($@) {
|
|
30 die $@;
|
|
31 } else {
|
|
32 return $result;
|
|
33 }
|
|
34 }
|
|
35
|
|
36 sub nobody {
|
|
37 my ($self) = @_;
|
|
38 $nobody = $self->new(Principal => IMPL::Security::Principal->nobody, AssignedRoles => undef) unless $nobody;
|
|
39 $nobody;
|
|
40 }
|
|
41
|
|
42 1;
|