49
|
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
|
51
|
11 my $current;
|
49
|
12 my $nobody;
|
|
13
|
|
14 BEGIN {
|
|
15 public property Principal => prop_get;
|
|
16 public property AssignedRoles => prop_all;
|
51
|
17 public property AuthSession => prop_all;
|
49
|
18 }
|
|
19
|
|
20 sub Impersonate {
|
|
21 my ($this,$code) = @_;
|
|
22
|
|
23 my $old = $current;
|
|
24 my $result;
|
|
25 local $@;
|
|
26 eval {
|
|
27 $result = $code->();
|
|
28 };
|
|
29 $current = $old;
|
|
30 if($@) {
|
|
31 die $@;
|
|
32 } else {
|
|
33 return $result;
|
|
34 }
|
|
35 }
|
|
36
|
51
|
37 sub contextNobody {
|
49
|
38 my ($self) = @_;
|
|
39 $nobody = $self->new(Principal => IMPL::Security::Principal->nobody, AssignedRoles => undef) unless $nobody;
|
|
40 $nobody;
|
|
41 }
|
|
42
|
51
|
43 sub contextCurrent {
|
|
44 my ($self) = @_;
|
|
45
|
|
46 $current = __PACKAGE__->nobody unless $current;
|
|
47 $current;
|
|
48 }
|
|
49
|
49
|
50 1;
|