annotate Lib/IMPL/Security.pm @ 217:bfce101e0a5a

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