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