annotate Lib/IMPL/Security/AbstractContext.pm @ 238:b8c724f6de36

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