annotate Lib/IMPL/Security/Context.pm @ 180:d1676be8afcc

Перекодировка в utf-8
author sourcer
date Fri, 30 Dec 2011 23:40:00 +0300
parents aaab45153411
children 4d0e1962161c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
1 package IMPL::Security::Context;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
2 use strict;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
3 use warnings;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
4
166
4267a2ac3d46 Added Class::Template,
wizard
parents: 158
diff changeset
5 use parent qw(IMPL::Object IMPL::Object::Autofill);
74
wizard
parents: 68
diff changeset
6
wizard
parents: 68
diff changeset
7 __PACKAGE__->PassThroughArgs;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
8
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
9 use IMPL::Class::Property;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
10
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
11 require IMPL::Security::Principal;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
12
51
a1498298d3ee Security in progress
wizard@linux-odin.local
parents: 49
diff changeset
13 my $current;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
14 my $nobody;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
15
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
16 BEGIN {
68
739f1288ca84 Auth in progress
wizard
parents: 66
diff changeset
17 public property principal => prop_get;
739f1288ca84 Auth in progress
wizard
parents: 66
diff changeset
18 public property rolesAssigned => prop_all | prop_list;
739f1288ca84 Auth in progress
wizard
parents: 66
diff changeset
19 public property auth => prop_all;
95
67eb8eaec3d4 Added a security authority property to the Context and Security classes
wizard
parents: 94
diff changeset
20 public property authority => prop_all;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
21 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
22
74
wizard
parents: 68
diff changeset
23 sub CTOR {
wizard
parents: 68
diff changeset
24 my ($this) = @_;
wizard
parents: 68
diff changeset
25
wizard
parents: 68
diff changeset
26 die new IMPL::InvalidArgumentException("The parameter is required", 'principal') unless $this->principal;
wizard
parents: 68
diff changeset
27 }
wizard
parents: 68
diff changeset
28
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
29 sub Impersonate {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
30 my ($this,$code) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
31
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
32 my $old = $current;
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 96
diff changeset
33 $current = $this;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
34 my $result;
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 96
diff changeset
35 my $e;
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 96
diff changeset
36
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 96
diff changeset
37 {
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 96
diff changeset
38 local $@;
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 96
diff changeset
39 eval {
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 96
diff changeset
40 $result = $code->();
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 96
diff changeset
41 };
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 96
diff changeset
42 $e = $@;
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 96
diff changeset
43 }
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
44 $current = $old;
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 96
diff changeset
45 if($e) {
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 96
diff changeset
46 die $e;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
47 } else {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
48 return $result;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
49 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
50 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
51
121
92c850d0bdb9 Minor changes
wizard
parents: 97
diff changeset
52 sub Apply {
92c850d0bdb9 Minor changes
wizard
parents: 97
diff changeset
53 my ($this) = @_;
92c850d0bdb9 Minor changes
wizard
parents: 97
diff changeset
54
92c850d0bdb9 Minor changes
wizard
parents: 97
diff changeset
55 $current = $this;
92c850d0bdb9 Minor changes
wizard
parents: 97
diff changeset
56 }
92c850d0bdb9 Minor changes
wizard
parents: 97
diff changeset
57
81
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
58 sub isTrusted {
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
59 my ($this) = @_;
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
60
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
61 if (my $auth = $this->auth) {
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
62 return $auth->isTrusted;
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
63 } else {
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
64 return 0;
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
65 }
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
66 }
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
67
74
wizard
parents: 68
diff changeset
68 sub nobody {
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
69 my ($self) = @_;
173
aaab45153411 minor bugfixes
sourcer
parents: 166
diff changeset
70 $nobody = $self->new(principal => IMPL::Security::Principal->nobody) unless $nobody;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
71 $nobody;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
72 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
73
74
wizard
parents: 68
diff changeset
74 sub current {
51
a1498298d3ee Security in progress
wizard@linux-odin.local
parents: 49
diff changeset
75 my ($self) = @_;
a1498298d3ee Security in progress
wizard@linux-odin.local
parents: 49
diff changeset
76
a1498298d3ee Security in progress
wizard@linux-odin.local
parents: 49
diff changeset
77 $current = __PACKAGE__->nobody unless $current;
a1498298d3ee Security in progress
wizard@linux-odin.local
parents: 49
diff changeset
78 $current;
a1498298d3ee Security in progress
wizard@linux-odin.local
parents: 49
diff changeset
79 }
a1498298d3ee Security in progress
wizard@linux-odin.local
parents: 49
diff changeset
80
94
79bf75223afe Fixed security related bugs
wizard
parents: 81
diff changeset
81 sub Satisfy {
79bf75223afe Fixed security related bugs
wizard
parents: 81
diff changeset
82 my ($this,@roles) = @_;
79bf75223afe Fixed security related bugs
wizard
parents: 81
diff changeset
83
158
a9f4ba4783eb Minor changes
wizard
parents: 121
diff changeset
84 my $roleEffective = new IMPL::Security::Role ( _effective => scalar $this->rolesAssigned );
94
79bf75223afe Fixed security related bugs
wizard
parents: 81
diff changeset
85
79bf75223afe Fixed security related bugs
wizard
parents: 81
diff changeset
86 return $roleEffective->Satisfy(@roles);
79bf75223afe Fixed security related bugs
wizard
parents: 81
diff changeset
87 }
79bf75223afe Fixed security related bugs
wizard
parents: 81
diff changeset
88
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
89 1;
74
wizard
parents: 68
diff changeset
90
wizard
parents: 68
diff changeset
91 __END__
wizard
parents: 68
diff changeset
92
wizard
parents: 68
diff changeset
93 =pod
wizard
parents: 68
diff changeset
94
wizard
parents: 68
diff changeset
95 =head1 NAME
wizard
parents: 68
diff changeset
96
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
97 C<IMPL::Security::Context> - контекст безопасности.
74
wizard
parents: 68
diff changeset
98
wizard
parents: 68
diff changeset
99 =head1 SINOPSYS
wizard
parents: 68
diff changeset
100
wizard
parents: 68
diff changeset
101 =begin code
wizard
parents: 68
diff changeset
102
wizard
parents: 68
diff changeset
103 my $context = IMPL::Security::Context->nobody;
wizard
parents: 68
diff changeset
104
wizard
parents: 68
diff changeset
105 my $result = $context->Impersonate(
wizard
parents: 68
diff changeset
106 sub {
wizard
parents: 68
diff changeset
107 # do some untrusted code
wizard
parents: 68
diff changeset
108 }
wizard
parents: 68
diff changeset
109 );
wizard
parents: 68
diff changeset
110
wizard
parents: 68
diff changeset
111 =end code
wizard
parents: 68
diff changeset
112
wizard
parents: 68
diff changeset
113 =head1 DESCRIPTION
wizard
parents: 68
diff changeset
114
wizard
parents: 68
diff changeset
115 C<[Autofill]>
wizard
parents: 68
diff changeset
116
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
117 Являет собой контекст безопасности, описывает пользователя и привелегии, так же
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
118 у программы есть текущий контекст безопасности, по умолчанию он C<nobody>.
74
wizard
parents: 68
diff changeset
119
wizard
parents: 68
diff changeset
120 =head1 MEMBERS
wizard
parents: 68
diff changeset
121
wizard
parents: 68
diff changeset
122 =over
wizard
parents: 68
diff changeset
123
wizard
parents: 68
diff changeset
124 =item C<CTOR(%props)>
wizard
parents: 68
diff changeset
125
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
126 Создает объект и заполняет его свойствами.
74
wizard
parents: 68
diff changeset
127
wizard
parents: 68
diff changeset
128 =item C<[get] principal>
wizard
parents: 68
diff changeset
129
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
130 Идентификатор пользователя, владельца контекста.
74
wizard
parents: 68
diff changeset
131
wizard
parents: 68
diff changeset
132 =item C<[get] rolesAssigned>
wizard
parents: 68
diff changeset
133
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
134 Список назначенных (активных) ролей пользователю.
74
wizard
parents: 68
diff changeset
135
wizard
parents: 68
diff changeset
136 =item C<[get] auth>
wizard
parents: 68
diff changeset
137
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
138 Объект асторизации C<IMPL::Security::Auth>, использованный при создании текущего контекста.
74
wizard
parents: 68
diff changeset
139
96
4c55aed00ff2 Minor changes
wizard
parents: 95
diff changeset
140 =item C<[static,get] authority>
4c55aed00ff2 Minor changes
wizard
parents: 95
diff changeset
141
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
142 Источник данных безопасности, породивший данный контекст.
96
4c55aed00ff2 Minor changes
wizard
parents: 95
diff changeset
143
81
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
144 =item C<[get] isTrusted>
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
145
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
146 Возвращает значение является ли контекст доверенным, тоесть сессия аутетифицирована.
81
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
147
74
wizard
parents: 68
diff changeset
148 =item C<Impersonate($code)>
wizard
parents: 68
diff changeset
149
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
150 Делает контекст текущим и выполняет в нем функцию по ссылке C<$code>. По окончании
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
151 выполнения, контекст восстанавливается.
74
wizard
parents: 68
diff changeset
152
121
92c850d0bdb9 Minor changes
wizard
parents: 97
diff changeset
153 =item C<Apply()>
92c850d0bdb9 Minor changes
wizard
parents: 97
diff changeset
154
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
155 Заменяет текущий контекст на себя, но до конца действия метода C<Impersonate>, если
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
156 таковой был вызван.
121
92c850d0bdb9 Minor changes
wizard
parents: 97
diff changeset
157
74
wizard
parents: 68
diff changeset
158 =item C<[static,get] nobody>
wizard
parents: 68
diff changeset
159
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
160 Контекст для неаутентифицированных пользователей, минимум прав.
74
wizard
parents: 68
diff changeset
161
wizard
parents: 68
diff changeset
162 =item C<[static,get] current>
wizard
parents: 68
diff changeset
163
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
164 Текущий контекст.
74
wizard
parents: 68
diff changeset
165
wizard
parents: 68
diff changeset
166 =back
wizard
parents: 68
diff changeset
167
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
168 =cut