comparison Lib/IMPL/Security/Context.pm @ 194:4d0e1962161c

Replaced tabs with spaces IMPL::Web::View - fixed document model, new features (control classes, document constructor parameters)
author cin
date Tue, 10 Apr 2012 20:08:29 +0400
parents d1676be8afcc
children 6d8092d8ce1b
comparison
equal deleted inserted replaced
193:8e8401c0aea4 194:4d0e1962161c
19 public property auth => prop_all; 19 public property auth => prop_all;
20 public property authority => prop_all; 20 public property authority => prop_all;
21 } 21 }
22 22
23 sub CTOR { 23 sub CTOR {
24 my ($this) = @_; 24 my ($this) = @_;
25 25
26 die new IMPL::InvalidArgumentException("The parameter is required", 'principal') unless $this->principal; 26 die new IMPL::InvalidArgumentException("The parameter is required", 'principal') unless $this->principal;
27 } 27 }
28 28
29 sub Impersonate { 29 sub Impersonate {
30 my ($this,$code) = @_; 30 my ($this,$code) = @_;
31 31
33 $current = $this; 33 $current = $this;
34 my $result; 34 my $result;
35 my $e; 35 my $e;
36 36
37 { 37 {
38 local $@; 38 local $@;
39 eval { 39 eval {
40 $result = $code->(); 40 $result = $code->();
41 }; 41 };
42 $e = $@; 42 $e = $@;
43 } 43 }
44 $current = $old; 44 $current = $old;
45 if($e) { 45 if($e) {
46 die $e; 46 die $e;
47 } else { 47 } else {
48 return $result; 48 return $result;
49 } 49 }
50 } 50 }
51 51
52 sub Apply { 52 sub Apply {
53 my ($this) = @_; 53 my ($this) = @_;
54 54
55 $current = $this; 55 $current = $this;
56 } 56 }
57 57
58 sub isTrusted { 58 sub isTrusted {
59 my ($this) = @_; 59 my ($this) = @_;
60 60
61 if (my $auth = $this->auth) { 61 if (my $auth = $this->auth) {
62 return $auth->isTrusted; 62 return $auth->isTrusted;
63 } else { 63 } else {
64 return 0; 64 return 0;
65 } 65 }
66 } 66 }
67 67
68 sub nobody { 68 sub nobody {
69 my ($self) = @_; 69 my ($self) = @_;
70 $nobody = $self->new(principal => IMPL::Security::Principal->nobody) unless $nobody; 70 $nobody = $self->new(principal => IMPL::Security::Principal->nobody) unless $nobody;
71 $nobody; 71 $nobody;
72 } 72 }
73 73
74 sub current { 74 sub current {
75 my ($self) = @_; 75 my ($self) = @_;
76 76
77 $current = __PACKAGE__->nobody unless $current; 77 $current = __PACKAGE__->nobody unless $current;
78 $current; 78 $current;
79 } 79 }
80 80
81 sub Satisfy { 81 sub Satisfy {
82 my ($this,@roles) = @_; 82 my ($this,@roles) = @_;
83 83
84 my $roleEffective = new IMPL::Security::Role ( _effective => scalar $this->rolesAssigned ); 84 my $roleEffective = new IMPL::Security::Role ( _effective => scalar $this->rolesAssigned );
85 85
86 return $roleEffective->Satisfy(@roles); 86 return $roleEffective->Satisfy(@roles);
87 } 87 }
88 88
89 1; 89 1;
90 90
91 __END__ 91 __END__
101 =begin code 101 =begin code
102 102
103 my $context = IMPL::Security::Context->nobody; 103 my $context = IMPL::Security::Context->nobody;
104 104
105 my $result = $context->Impersonate( 105 my $result = $context->Impersonate(
106 sub { 106 sub {
107 # do some untrusted code 107 # do some untrusted code
108 } 108 }
109 ); 109 );
110 110
111 =end code 111 =end code
112 112
113 =head1 DESCRIPTION 113 =head1 DESCRIPTION