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