annotate Lib/IMPL/Security/AbstractContext.pm @ 355:8dfb9df07d02

added support for the custom resolvers for the TTView
author sergey
date Thu, 17 Oct 2013 01:04:37 +0400
parents fe725fad2d90
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
1 package IMPL::Security::AbstractContext;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
2 use strict;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
3 use warnings;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
4
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
5 use IMPL::Const qw(:prop);
260
sergey
parents: 238
diff changeset
6
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
7 use IMPL::require {
260
sergey
parents: 238
diff changeset
8 Role => 'IMPL::Security::Role',
330
fe725fad2d90 Added access checking to web resources
sergey
parents: 260
diff changeset
9 Principal => 'IMPL::Security::Principal',
260
sergey
parents: 238
diff changeset
10 Exception => 'IMPL::Exception',
sergey
parents: 238
diff changeset
11 NotImplementedException => '-IMPL::NotImplementedException'
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
12 };
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
13
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
14 use parent qw(IMPL::Class::Meta);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
15
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
16 __PACKAGE__->static_accessor_clone(abstractProps => [
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
17 principal => PROP_RW,
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
18 rolesAssigned => PROP_RW | PROP_LIST,
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
19 auth => PROP_RW,
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
20 authority => PROP_RW
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
21 ]);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
22
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
23 my $current; # current session if any
74
wizard
parents: 68
diff changeset
24
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
25 sub Impersonate {
238
b8c724f6de36 DOM model refactoring
sergey
parents: 230
diff changeset
26 my ($this,$code,@args) = @_;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
27
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
28 my $old = $current;
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 96
diff changeset
29 $current = $this;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
30 my $result;
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 96
diff changeset
31 my $e;
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 96
diff changeset
32
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 96
diff changeset
33 {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
34 local $@;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
35 eval {
238
b8c724f6de36 DOM model refactoring
sergey
parents: 230
diff changeset
36 $result = $code->(@args);
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
37 };
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
38 $e = $@;
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 96
diff changeset
39 }
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
40 $current = $old;
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 96
diff changeset
41 if($e) {
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 96
diff changeset
42 die $e;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
43 } else {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
44 return $result;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
45 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
46 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
47
121
92c850d0bdb9 Minor changes
wizard
parents: 97
diff changeset
48 sub Apply {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
49 my ($this) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
50
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
51 $current = $this;
121
92c850d0bdb9 Minor changes
wizard
parents: 97
diff changeset
52 }
92c850d0bdb9 Minor changes
wizard
parents: 97
diff changeset
53
81
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
54 sub isTrusted {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
55 my ($this) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
56
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
57 if (my $auth = $this->auth) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
58 return $auth->isTrusted;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
59 } else {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
60 return 0;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
61 }
81
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
62 }
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
63
330
fe725fad2d90 Added access checking to web resources
sergey
parents: 260
diff changeset
64 sub isNobody {
fe725fad2d90 Added access checking to web resources
sergey
parents: 260
diff changeset
65 return (shift->principal == Principal->nobody ? 1 : 0);
fe725fad2d90 Added access checking to web resources
sergey
parents: 260
diff changeset
66 }
fe725fad2d90 Added access checking to web resources
sergey
parents: 260
diff changeset
67
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
68 sub Satisfy {
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
69 my ($this,@roles) = @_;
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
70
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
71 my $roleEffective = Role->new ( _effective => scalar $this->rolesAssigned );
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
72
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
73 return $roleEffective->Satisfy(@roles);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
74 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
75
74
wizard
parents: 68
diff changeset
76 sub current {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
77 $current;
51
a1498298d3ee Security in progress
wizard@linux-odin.local
parents: 49
diff changeset
78 }
a1498298d3ee Security in progress
wizard@linux-odin.local
parents: 49
diff changeset
79
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
80 1;
74
wizard
parents: 68
diff changeset
81
wizard
parents: 68
diff changeset
82 __END__
wizard
parents: 68
diff changeset
83
wizard
parents: 68
diff changeset
84 =pod
wizard
parents: 68
diff changeset
85
wizard
parents: 68
diff changeset
86 =head1 NAME
wizard
parents: 68
diff changeset
87
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
88 C<abstract IMPL::Security::Context> - контекст безопасности.
74
wizard
parents: 68
diff changeset
89
wizard
parents: 68
diff changeset
90 =head1 SINOPSYS
wizard
parents: 68
diff changeset
91
wizard
parents: 68
diff changeset
92 =begin code
wizard
parents: 68
diff changeset
93
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
94 package MyApp::Model::Session;
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
95 use strict;
74
wizard
parents: 68
diff changeset
96
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
97 use IMPL::delare {
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
98 base => [
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
99 'MyApp::Model::BaseDBO' => '@_',
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
100 'IMPL::Security::AbstractContext' => undef
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
101 ],
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
102 props {
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
103 IMPL::Security::AbstractContext->abstractProps,
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
104 qouta => PROP_GET
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
105 }
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
106 }
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
107
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
108 package main;
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
109
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
110 $app->model->GetSession('546a54df4')->Impersonate(sub{
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
111 # do something
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
112 });
74
wizard
parents: 68
diff changeset
113
wizard
parents: 68
diff changeset
114 =end code
wizard
parents: 68
diff changeset
115
wizard
parents: 68
diff changeset
116 =head1 DESCRIPTION
wizard
parents: 68
diff changeset
117
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
118 Код приложения, которое выполняется
74
wizard
parents: 68
diff changeset
119
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
120 Являет собой контекст безопасности, описывает пользователя и привелегии, так же
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
121 у программы есть текущий контекст безопасности, по умолчанию он C<nobody>.
74
wizard
parents: 68
diff changeset
122
wizard
parents: 68
diff changeset
123 =head1 MEMBERS
wizard
parents: 68
diff changeset
124
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
125 =head2 C<[get] principal>
74
wizard
parents: 68
diff changeset
126
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
127 Идентификатор пользователя, владельца контекста.
74
wizard
parents: 68
diff changeset
128
260
sergey
parents: 238
diff changeset
129 =head2 C<[get,set] rolesAssigned>
74
wizard
parents: 68
diff changeset
130
260
sergey
parents: 238
diff changeset
131 Явно назначенные роли. Если список пуст, то считается, что используются роли
sergey
parents: 238
diff changeset
132 пользователя по-умолчанию.
74
wizard
parents: 68
diff changeset
133
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
134 =head2 C<[get] auth>
74
wizard
parents: 68
diff changeset
135
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
136 Объект асторизации C<IMPL::Security::Auth>, использованный при создании текущего контекста.
74
wizard
parents: 68
diff changeset
137
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
138 =head2 C<[get] authority>
96
4c55aed00ff2 Minor changes
wizard
parents: 95
diff changeset
139
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
140 Модуль безопасности, породивший данный контекст. Модуль безопасности, отвечающий
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
141 за создание контекста безопасности должен реализовывать метод
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
142 C<CreateContext($user,$auth,$roles)>
96
4c55aed00ff2 Minor changes
wizard
parents: 95
diff changeset
143
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
144 =head2 C<[get] isTrusted>
81
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
145
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
146 Возвращает значение является ли контекст доверенным, тоесть клиент
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
147 аутентифицирован и сессия установлена. Если C<false> значит, что сессия была
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
148 начата, однако не установлена до конца.
81
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
149
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
150 =head2 C<Impersonate($code)>
74
wizard
parents: 68
diff changeset
151
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
152 Делает контекст текущим и выполняет в нем функцию по ссылке C<$code>. По окончании
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
153 выполнения, контекст восстанавливается в предыдущий (не зависимо от того, что
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
154 с ним происходило во время выполнения C<$code>).
74
wizard
parents: 68
diff changeset
155
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
156 =head2 C<Apply()>
121
92c850d0bdb9 Minor changes
wizard
parents: 97
diff changeset
157
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
158 Заменяет текущий контекст на себя, но до конца действия метода C<Impersonate>, если
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
159 таковой был вызван.
121
92c850d0bdb9 Minor changes
wizard
parents: 97
diff changeset
160
260
sergey
parents: 238
diff changeset
161 =head2 C<Satisfy(@roles)>
sergey
parents: 238
diff changeset
162
sergey
parents: 238
diff changeset
163 Проверяет наличие необходимых ролей у контекста. Данный метод позволяет
sergey
parents: 238
diff changeset
164 абстрагироваться от механизмов связи контекста и ролей. Возвращает истинное
sergey
parents: 238
diff changeset
165 значение если список необходимых ролей у пользователя имеется.
sergey
parents: 238
diff changeset
166
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
167 =cut