Mercurial > pub > Impl
annotate Lib/IMPL/Security.pm @ 246:2746a8e5a6c4
Fixed regressions in DOM due previous refactorings
Fixed ObjectToDOM transformation to handle a schema with mixed node types
author | sergey |
---|---|
date | Tue, 30 Oct 2012 01:17:31 +0400 |
parents | 7c517134c42f |
children | 2270de2469ff |
rev | line source |
---|---|
49 | 1 package IMPL::Security; |
230 | 2 use strict; |
3 use Carp qw(carp); | |
4 | |
5 ##VERSION## | |
6 | |
7 require IMPL::Exception; | |
245 | 8 require IMPL::Security::Principal; |
230 | 9 require IMPL::Security::AbstractContext; |
51 | 10 require IMPL::Security::Rule::RoleCheck; |
11 | |
12 our @rules = ( | |
194 | 13 \&IMPL::Security::Rule::RoleCheck::SatisfyAll |
51 | 14 ); |
15 | |
95
67eb8eaec3d4
Added a security authority property to the Context and Security classes
wizard
parents:
74
diff
changeset
|
16 our $authority = undef; |
67eb8eaec3d4
Added a security authority property to the Context and Security classes
wizard
parents:
74
diff
changeset
|
17 |
51 | 18 sub AccessCheck { |
194 | 19 my ($self, $object, $desiredAccess, $context) = @_; |
20 | |
230 | 21 $context ||= IMPL::Security::AbstractContext->context; |
194 | 22 |
23 $_->() or return 0 foreach @{$self->Rules}; | |
24 | |
25 return 1; | |
51 | 26 } |
27 | |
66 | 28 sub Take { |
194 | 29 my ($self,$principal,$refRoles) = @_; |
30 | |
31 die new IMPL::NotImplementedException(); | |
66 | 32 } |
33 | |
73 | 34 sub MakeContext { |
194 | 35 my ($this,$principal,$refRoles,$auth) = @_; |
36 | |
37 return new IMPL::Security::Context( | |
38 principal => $principal, | |
39 rolesAssigned => $refRoles, | |
40 auth => $auth | |
41 ); | |
73 | 42 } |
43 | |
51 | 44 sub Rules { |
194 | 45 return \@rules; |
51 | 46 } |
49 | 47 |
95
67eb8eaec3d4
Added a security authority property to the Context and Security classes
wizard
parents:
74
diff
changeset
|
48 sub authority { |
194 | 49 return $authority; |
95
67eb8eaec3d4
Added a security authority property to the Context and Security classes
wizard
parents:
74
diff
changeset
|
50 } |
67eb8eaec3d4
Added a security authority property to the Context and Security classes
wizard
parents:
74
diff
changeset
|
51 |
245 | 52 sub principal { |
53 return | |
54 IMPL::Security::AbstractContext->current | |
55 && IMPL::Security::AbstractContext->current->principal | |
56 || IMPL::Security::Principal->nobody; | |
57 } | |
58 | |
59 sub context { | |
60 IMPL::Security::AbstractContext->current; | |
61 } | |
62 | |
49 | 63 1; |
50 | 64 |
65 __END__ | |
66 | |
67 =pod | |
68 | |
66 | 69 =head1 NAME |
70 | |
180 | 71 C<IMPL::Security> - Модуль для работы с функциями авторизации и аутентификации. |
66 | 72 |
73 =head1 SINOPSYS | |
74 | |
75 =begin code | |
76 | |
77 use IMPL::Security; | |
78 | |
79 my Method { | |
194 | 80 my $this = shift; |
81 | |
82 # access check in the current context, using standard configuration | |
83 IMPL::Security->AccessCheck($this,'Method') or die new IMPL::AccessDeniedException("Access is denied"); | |
84 | |
85 #some more results | |
66 | 86 } |
87 | |
88 my DelegationMethod { | |
194 | 89 |
90 my $this = shift; | |
91 | |
92 #forced delegation | |
93 my $delegatedContext = IMPL::Security::Context->new( | |
94 principal => IMPL::Security::Principal->new( | |
95 name => 'suser' | |
96 ), | |
97 rolesAssigned => ['administrator'] | |
98 ) | |
99 | |
100 my $result; | |
101 | |
102 $delegatedContext->Impersonate(sub{ | |
103 $result = $this->Method(); | |
104 }); | |
105 | |
106 return $result; | |
66 | 107 } |
108 | |
109 my SafeDelegationMethod { | |
194 | 110 |
111 my $this = shift; | |
112 | |
113 my $delegatedContext = IMPL::Security->Take( suser => 'administrator' ); | |
114 | |
115 my $result; | |
116 | |
117 $delegatedContext->Impersonate(sub{ | |
118 $result = $this->Method(); | |
119 }); | |
120 | |
121 return $result; | |
66 | 122 } |
123 | |
124 =end code | |
125 | |
50 | 126 =head1 DESCRIPTION |
127 | |
180 | 128 Модуль для инфраструктуры безопасности, реализует основные функции для авторизации |
129 и аутентификации пользователей. | |
51 | 130 |
180 | 131 Модуль аутентификации, реализиция которого зависит от приложения, аутентифицирует |
132 пользователя, при этом создается контекст безопасности, который содержит | |
133 идентификатор пользователя и список активных ролей. | |
51 | 134 |
180 | 135 При проверке прав доступа происходит последовательная проверка правил доступа, |
136 если все правила выполнены, то доступ разрешается. | |
51 | 137 |
66 | 138 =head1 MEMBERS |
50 | 139 |
66 | 140 =over |
141 | |
142 =item C<AccessCheck($object,$desiredAccess,$context)> | |
143 | |
180 | 144 Метод. Проверка доступа к объекту с определенными правами, в определенном контексте безопасности. |
66 | 145 |
146 =over | |
147 | |
148 =item C<$object> | |
149 | |
180 | 150 Объект доступа. |
66 | 151 |
152 =item C<$desiredAccess> | |
153 | |
180 | 154 Требуемые права доступа. |
66 | 155 |
156 =item C<$context> | |
157 | |
180 | 158 Контекст безопасности, если не указан, то используется текущий C<< IMPL::Security::Context->contextCurrent >> |
66 | 159 |
160 =item C<returns> | |
161 | |
180 | 162 C<true | false> - результат проверки |
66 | 163 |
164 =back | |
165 | |
73 | 166 =item C<MakeContext($principal,$role,$auth)> |
167 | |
180 | 168 Создает контекст безопасности, инициализируя его передданными параметрами. |
73 | 169 |
170 =over | |
171 | |
172 =item C<$principal> | |
173 | |
180 | 174 Объект пользователя |
73 | 175 |
176 =item C<$role> | |
177 | |
180 | 178 Роль или ссылка на массив ролей |
73 | 179 |
180 =item C<$auth> | |
181 | |
180 | 182 Объект аутентификации |
73 | 183 |
184 =back | |
185 | |
66 | 186 =item C<Take($principal,$role)> |
187 | |
180 | 188 Метод. Делегирует текущему пользователю полномочия другого пользователя. При этом выполняется проверка |
189 правомерности такой операции. В случае неудачи вызывается исключение. | |
66 | 190 |
191 =over | |
192 | |
193 =item C<$principal> | |
194 | |
180 | 195 Либо имя пользователя либо объект C<IMPL::Security::Principal>. |
66 | 196 |
197 =item C<$role> | |
198 | |
180 | 199 Либо имя либо ссылка на роль, или ссылка на массив либо имен, либо ролей. |
66 | 200 |
201 =item C<returns> | |
202 | |
180 | 203 Новый контекст безопасности. |
66 | 204 |
205 =back | |
206 | |
73 | 207 =item C<Rules()> |
66 | 208 |
180 | 209 Возвращает список правил которые выполняются при проверках доступа. Пререопределите этот |
210 метод, чтобы возвращать собственный список правил. Список правил является ссылкой на массив | |
211 элементами которого являются функции. | |
66 | 212 |
213 =begin code | |
214 | |
215 package MySecurity; | |
216 | |
166 | 217 use parent qw(IMPL::Security); |
66 | 218 |
219 sub Rules { | |
194 | 220 return [ |
221 \&Rule1, | |
222 \&Rule2, | |
223 #... | |
224 ] | |
66 | 225 } |
226 | |
227 =end code | |
228 | |
95
67eb8eaec3d4
Added a security authority property to the Context and Security classes
wizard
parents:
74
diff
changeset
|
229 =item C<[static,get] authority> |
67eb8eaec3d4
Added a security authority property to the Context and Security classes
wizard
parents:
74
diff
changeset
|
230 |
180 | 231 Метод, позволяющий получить текущий источник системы безопасности. Источник безопасности, это модуль, |
232 который получает входные данные и использует их для работы системы безопасности. | |
95
67eb8eaec3d4
Added a security authority property to the Context and Security classes
wizard
parents:
74
diff
changeset
|
233 |
66 | 234 =back |
50 | 235 |
180 | 236 =cut |