annotate Lib/IMPL/Security/Context.pm @ 111:6c25ea91c985

ControllerUnit concept
author wizard
date Tue, 18 May 2010 01:33:37 +0400
parents 964587c5183c
children 92c850d0bdb9
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: 47
diff changeset
1 package IMPL::Security::Context;
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
74
wizard
parents: 68
diff changeset
5 use base qw(IMPL::Object IMPL::Object::Autofill);
wizard
parents: 68
diff changeset
6
wizard
parents: 68
diff changeset
7 __PACKAGE__->PassThroughArgs;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
8
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
9 use IMPL::Class::Property;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
10
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
11 require IMPL::Security::Principal;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
12
51
a1498298d3ee Security in progress
wizard@linux-odin.local
parents: 49
diff changeset
13 my $current;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
14 my $nobody;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
15
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
16 BEGIN {
68
739f1288ca84 Auth in progress
wizard
parents: 66
diff changeset
17 public property principal => prop_get;
739f1288ca84 Auth in progress
wizard
parents: 66
diff changeset
18 public property rolesAssigned => prop_all | prop_list;
739f1288ca84 Auth in progress
wizard
parents: 66
diff changeset
19 public property auth => prop_all;
95
67eb8eaec3d4 Added a security authority property to the Context and Security classes
wizard
parents: 94
diff changeset
20 public property authority => prop_all;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
21 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
22
74
wizard
parents: 68
diff changeset
23 sub CTOR {
wizard
parents: 68
diff changeset
24 my ($this) = @_;
wizard
parents: 68
diff changeset
25
wizard
parents: 68
diff changeset
26 die new IMPL::InvalidArgumentException("The parameter is required", 'principal') unless $this->principal;
wizard
parents: 68
diff changeset
27 }
wizard
parents: 68
diff changeset
28
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
29 sub Impersonate {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
30 my ($this,$code) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
31
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
32 my $old = $current;
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 96
diff changeset
33 $current = $this;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
34 my $result;
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 96
diff changeset
35 my $e;
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 96
diff changeset
36
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 96
diff changeset
37 {
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 96
diff changeset
38 local $@;
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 96
diff changeset
39 eval {
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 96
diff changeset
40 $result = $code->();
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 96
diff changeset
41 };
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 96
diff changeset
42 $e = $@;
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 96
diff changeset
43 }
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
44 $current = $old;
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 96
diff changeset
45 if($e) {
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 96
diff changeset
46 die $e;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
47 } else {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
48 return $result;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
49 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
50 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
51
81
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
52 sub isTrusted {
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
53 my ($this) = @_;
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
54
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
55 if (my $auth = $this->auth) {
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
56 return $auth->isTrusted;
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
57 } else {
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
58 return 0;
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
59 }
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
60 }
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
61
74
wizard
parents: 68
diff changeset
62 sub nobody {
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
63 my ($self) = @_;
68
739f1288ca84 Auth in progress
wizard
parents: 66
diff changeset
64 $nobody = $self->new(principal => IMPL::Security::Principal->nobody, rolesAssigned => undef) unless $nobody;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
65 $nobody;
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 {
51
a1498298d3ee Security in progress
wizard@linux-odin.local
parents: 49
diff changeset
69 my ($self) = @_;
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 $current = __PACKAGE__->nobody unless $current;
a1498298d3ee Security in progress
wizard@linux-odin.local
parents: 49
diff changeset
72 $current;
a1498298d3ee Security in progress
wizard@linux-odin.local
parents: 49
diff changeset
73 }
a1498298d3ee Security in progress
wizard@linux-odin.local
parents: 49
diff changeset
74
94
79bf75223afe Fixed security related bugs
wizard
parents: 81
diff changeset
75 sub Satisfy {
79bf75223afe Fixed security related bugs
wizard
parents: 81
diff changeset
76 my ($this,@roles) = @_;
79bf75223afe Fixed security related bugs
wizard
parents: 81
diff changeset
77
79bf75223afe Fixed security related bugs
wizard
parents: 81
diff changeset
78 my $roleEffective = new IMPL::Security::Role ( _effective => $this->rolesAssigned );
79bf75223afe Fixed security related bugs
wizard
parents: 81
diff changeset
79
79bf75223afe Fixed security related bugs
wizard
parents: 81
diff changeset
80 return $roleEffective->Satisfy(@roles);
79bf75223afe Fixed security related bugs
wizard
parents: 81
diff changeset
81 }
79bf75223afe Fixed security related bugs
wizard
parents: 81
diff changeset
82
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
83 1;
74
wizard
parents: 68
diff changeset
84
wizard
parents: 68
diff changeset
85 __END__
wizard
parents: 68
diff changeset
86
wizard
parents: 68
diff changeset
87 =pod
wizard
parents: 68
diff changeset
88
wizard
parents: 68
diff changeset
89 =head1 NAME
wizard
parents: 68
diff changeset
90
wizard
parents: 68
diff changeset
91 C<IMPL::Security::Context> - контекст безопасности.
wizard
parents: 68
diff changeset
92
wizard
parents: 68
diff changeset
93 =head1 SINOPSYS
wizard
parents: 68
diff changeset
94
wizard
parents: 68
diff changeset
95 =begin code
wizard
parents: 68
diff changeset
96
wizard
parents: 68
diff changeset
97 my $context = IMPL::Security::Context->nobody;
wizard
parents: 68
diff changeset
98
wizard
parents: 68
diff changeset
99 my $result = $context->Impersonate(
wizard
parents: 68
diff changeset
100 sub {
wizard
parents: 68
diff changeset
101 # do some untrusted code
wizard
parents: 68
diff changeset
102 }
wizard
parents: 68
diff changeset
103 );
wizard
parents: 68
diff changeset
104
wizard
parents: 68
diff changeset
105 =end code
wizard
parents: 68
diff changeset
106
wizard
parents: 68
diff changeset
107 =head1 DESCRIPTION
wizard
parents: 68
diff changeset
108
wizard
parents: 68
diff changeset
109 C<[Autofill]>
wizard
parents: 68
diff changeset
110
wizard
parents: 68
diff changeset
111 Являет собой контекст безопасности, описывает пользователя и привелегии, так же
96
4c55aed00ff2 Minor changes
wizard
parents: 95
diff changeset
112 у программы есть текущий контекст безопасности, по умолчанию он C<nobody>.
74
wizard
parents: 68
diff changeset
113
wizard
parents: 68
diff changeset
114 =head1 MEMBERS
wizard
parents: 68
diff changeset
115
wizard
parents: 68
diff changeset
116 =over
wizard
parents: 68
diff changeset
117
wizard
parents: 68
diff changeset
118 =item C<CTOR(%props)>
wizard
parents: 68
diff changeset
119
wizard
parents: 68
diff changeset
120 Создает объект и заполняет его свойствами.
wizard
parents: 68
diff changeset
121
wizard
parents: 68
diff changeset
122 =item C<[get] principal>
wizard
parents: 68
diff changeset
123
wizard
parents: 68
diff changeset
124 Идентификатор пользователя, владельца контекста.
wizard
parents: 68
diff changeset
125
wizard
parents: 68
diff changeset
126 =item C<[get] rolesAssigned>
wizard
parents: 68
diff changeset
127
wizard
parents: 68
diff changeset
128 Список назначенных (активных) ролей пользователю.
wizard
parents: 68
diff changeset
129
wizard
parents: 68
diff changeset
130 =item C<[get] auth>
wizard
parents: 68
diff changeset
131
wizard
parents: 68
diff changeset
132 Объект асторизации C<IMPL::Security::Auth>, использованный при создании текущего контекста.
wizard
parents: 68
diff changeset
133
96
4c55aed00ff2 Minor changes
wizard
parents: 95
diff changeset
134 =item C<[static,get] authority>
4c55aed00ff2 Minor changes
wizard
parents: 95
diff changeset
135
4c55aed00ff2 Minor changes
wizard
parents: 95
diff changeset
136 Источник данных безопасности, породивший данный контекст.
4c55aed00ff2 Minor changes
wizard
parents: 95
diff changeset
137
81
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
138 =item C<[get] isTrusted>
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
139
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
140 Возвращает значение является ли контекст доверенным, тоесть сессия аутетифицирована.
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 74
diff changeset
141
74
wizard
parents: 68
diff changeset
142 =item C<Impersonate($code)>
wizard
parents: 68
diff changeset
143
wizard
parents: 68
diff changeset
144 Делает контекст текущим и выполняет в нем функцию по ссылке C<$code>. По окончании
wizard
parents: 68
diff changeset
145 выполнения, контекст восстанавливается.
wizard
parents: 68
diff changeset
146
wizard
parents: 68
diff changeset
147 =item C<[static,get] nobody>
wizard
parents: 68
diff changeset
148
wizard
parents: 68
diff changeset
149 Контекст для неаутентифицированных пользователей, минимум прав.
wizard
parents: 68
diff changeset
150
wizard
parents: 68
diff changeset
151 =item C<[static,get] current>
wizard
parents: 68
diff changeset
152
wizard
parents: 68
diff changeset
153 Текущий контекст.
wizard
parents: 68
diff changeset
154
wizard
parents: 68
diff changeset
155 =back
wizard
parents: 68
diff changeset
156
wizard
parents: 68
diff changeset
157 =cut