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