Mercurial > pub > Impl
annotate Lib/IMPL/Security.pm @ 119:8114aaa7feba
Json format
| author | wizard |
|---|---|
| date | Mon, 07 Jun 2010 17:43:15 +0400 |
| parents | 67eb8eaec3d4 |
| children | 4267a2ac3d46 |
| rev | line source |
|---|---|
| 49 | 1 package IMPL::Security; |
| 51 | 2 require IMPL::Security::Context; |
| 3 require IMPL::Security::Rule::RoleCheck; | |
| 4 | |
| 5 our @rules = ( | |
| 6 \&IMPL::Security::Rule::RoleCheck::SatisfyAll | |
| 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 { |
| 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; | |
| 19 } | |
| 20 | |
| 66 | 21 sub Take { |
| 22 my ($self,$principal,$refRoles) = @_; | |
| 23 | |
| 24 die new IMPL::NotImplementedException(); | |
| 25 } | |
| 26 | |
| 73 | 27 sub MakeContext { |
| 28 my ($this,$principal,$refRoles,$auth) = @_; | |
| 29 | |
| 30 return new IMPL::Security::Context( | |
| 31 principal => $principal, | |
| 32 rolesAssigned => $refRoles, | |
| 33 auth => $auth | |
| 34 ); | |
| 35 } | |
| 36 | |
| 51 | 37 sub Rules { |
| 38 return \@rules; | |
| 39 } | |
| 49 | 40 |
|
95
67eb8eaec3d4
Added a security authority property to the Context and Security classes
wizard
parents:
74
diff
changeset
|
41 sub authority { |
|
67eb8eaec3d4
Added a security authority property to the Context and Security classes
wizard
parents:
74
diff
changeset
|
42 return $authority; |
|
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 | |
| 53 C<IMPL::Security> - Модуль для работы с функциями авторизации и аутентификации. | |
| 54 | |
| 55 =head1 SINOPSYS | |
| 56 | |
| 57 =begin code | |
| 58 | |
| 59 use IMPL::Security; | |
| 60 | |
| 61 my Method { | |
| 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 | |
| 68 } | |
| 69 | |
| 70 my DelegationMethod { | |
| 71 | |
| 72 my $this = shift; | |
| 73 | |
| 74 #forced delegation | |
| 75 my $delegatedContext = IMPL::Security::Context->new( | |
| 74 | 76 principal => IMPL::Security::Principal->new( |
| 77 name => 'suser' | |
| 66 | 78 ), |
| 74 | 79 rolesAssigned => ['administrator'] |
| 66 | 80 ) |
| 81 | |
| 82 my $result; | |
| 83 | |
| 84 $delegatedContext->Impersonate(sub{ | |
| 85 $result = $this->Method(); | |
| 86 }); | |
| 87 | |
| 88 return $result; | |
| 89 } | |
| 90 | |
| 91 my SafeDelegationMethod { | |
| 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; | |
| 104 } | |
| 105 | |
| 106 =end code | |
| 107 | |
| 50 | 108 =head1 DESCRIPTION |
| 109 | |
| 51 | 110 Модуль для инфраструктуры безопасности, реализует основные функции для авторизации |
| 111 и аутентификации пользователей. | |
| 112 | |
| 113 Модуль аутентификации, реализиция которого зависит от приложения, аутентифицирует | |
| 114 пользователя, при этом создается контекст безопасности, который содержит | |
| 115 идентификатор пользователя и список активных ролей. | |
| 116 | |
| 117 При проверке прав доступа происходит последовательная проверка правил доступа, | |
| 118 если все правила выполнены, то доступ разрешается. | |
| 119 | |
| 66 | 120 =head1 MEMBERS |
| 50 | 121 |
| 66 | 122 =over |
| 123 | |
| 124 =item C<AccessCheck($object,$desiredAccess,$context)> | |
| 125 | |
| 126 Метод. Проверка доступа к объекту с определенными правами, в определенном контексте безопасности. | |
| 127 | |
| 128 =over | |
| 129 | |
| 130 =item C<$object> | |
| 131 | |
| 132 Объект доступа. | |
| 133 | |
| 134 =item C<$desiredAccess> | |
| 135 | |
| 136 Требуемые права доступа. | |
| 137 | |
| 138 =item C<$context> | |
| 139 | |
| 140 Контекст безопасности, если не указан, то используется текущий C<< IMPL::Security::Context->contextCurrent >> | |
| 141 | |
| 142 =item C<returns> | |
| 143 | |
| 144 C<true | false> - результат проверки | |
| 145 | |
| 146 =back | |
| 147 | |
| 73 | 148 =item C<MakeContext($principal,$role,$auth)> |
| 149 | |
| 150 Создает контекст безопасности, инициализируя его передданными параметрами. | |
| 151 | |
| 152 =over | |
| 153 | |
| 154 =item C<$principal> | |
| 155 | |
| 156 Объект пользователя | |
| 157 | |
| 158 =item C<$role> | |
| 159 | |
| 160 Роль или ссылка на массив ролей | |
| 161 | |
| 162 =item C<$auth> | |
| 163 | |
| 164 Объект аутентификации | |
| 165 | |
| 166 =back | |
| 167 | |
| 66 | 168 =item C<Take($principal,$role)> |
| 169 | |
| 170 Метод. Делегирует текущему пользователю полномочия другого пользователя. При этом выполняется проверка | |
| 171 правомерности такой операции. В случае неудачи вызывается исключение. | |
| 172 | |
| 173 =over | |
| 174 | |
| 175 =item C<$principal> | |
| 176 | |
| 177 Либо имя пользователя либо объект C<IMPL::Security::Principal>. | |
| 178 | |
| 179 =item C<$role> | |
| 180 | |
| 181 Либо имя либо ссылка на роль, или ссылка на массив либо имен, либо ролей. | |
| 182 | |
| 183 =item C<returns> | |
| 184 | |
| 185 Новый контекст безопасности. | |
| 186 | |
| 187 =back | |
| 188 | |
| 73 | 189 =item C<Rules()> |
| 66 | 190 |
| 191 Возвращает список правил которые выполняются при проверках доступа. Пререопределите этот | |
| 192 метод, чтобы возвращать собственный список правил. Список правил является ссылкой на массив | |
| 193 элементами которого являются функции. | |
| 194 | |
| 195 =begin code | |
| 196 | |
| 197 package MySecurity; | |
| 198 | |
| 199 use base qw(IMPL::Security); | |
| 200 | |
| 201 sub Rules { | |
| 202 return [ | |
| 203 \&Rule1, | |
| 204 \&Rule2, | |
| 205 #... | |
| 206 ] | |
| 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 |
|
67eb8eaec3d4
Added a security authority property to the Context and Security classes
wizard
parents:
74
diff
changeset
|
213 Метод, позволяющий получить текущий источник системы безопасности. Источник безопасности, это модуль, |
|
67eb8eaec3d4
Added a security authority property to the Context and Security classes
wizard
parents:
74
diff
changeset
|
214 который получает входные данные и использует их для работы системы безопасности. |
|
67eb8eaec3d4
Added a security authority property to the Context and Security classes
wizard
parents:
74
diff
changeset
|
215 |
| 66 | 216 =back |
| 50 | 217 |
| 218 =cut |
