annotate Lib/IMPL/Security/Context.pm @ 74:84aa8c395fce

doc minor fixes
author wizard
date Mon, 29 Mar 2010 17:40:06 +0400
parents 739f1288ca84
children 077357224bec
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;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
20 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
21
74
wizard
parents: 68
diff changeset
22 sub CTOR {
wizard
parents: 68
diff changeset
23 my ($this) = @_;
wizard
parents: 68
diff changeset
24
wizard
parents: 68
diff changeset
25 die new IMPL::InvalidArgumentException("The parameter is required", 'principal') unless $this->principal;
wizard
parents: 68
diff changeset
26 }
wizard
parents: 68
diff changeset
27
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
28 sub Impersonate {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
29 my ($this,$code) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
30
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
31 my $old = $current;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
32 my $result;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
33 local $@;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
34 eval {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
35 $result = $code->();
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
36 };
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
37 $current = $old;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
38 if($@) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
39 die $@;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
40 } else {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
41 return $result;
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 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
44
74
wizard
parents: 68
diff changeset
45 sub nobody {
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
46 my ($self) = @_;
68
739f1288ca84 Auth in progress
wizard
parents: 66
diff changeset
47 $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
48 $nobody;
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
74
wizard
parents: 68
diff changeset
51 sub current {
51
a1498298d3ee Security in progress
wizard@linux-odin.local
parents: 49
diff changeset
52 my ($self) = @_;
a1498298d3ee Security in progress
wizard@linux-odin.local
parents: 49
diff changeset
53
a1498298d3ee Security in progress
wizard@linux-odin.local
parents: 49
diff changeset
54 $current = __PACKAGE__->nobody unless $current;
a1498298d3ee Security in progress
wizard@linux-odin.local
parents: 49
diff changeset
55 $current;
a1498298d3ee Security in progress
wizard@linux-odin.local
parents: 49
diff changeset
56 }
a1498298d3ee Security in progress
wizard@linux-odin.local
parents: 49
diff changeset
57
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
58 1;
74
wizard
parents: 68
diff changeset
59
wizard
parents: 68
diff changeset
60 __END__
wizard
parents: 68
diff changeset
61
wizard
parents: 68
diff changeset
62 =pod
wizard
parents: 68
diff changeset
63
wizard
parents: 68
diff changeset
64 =head1 NAME
wizard
parents: 68
diff changeset
65
wizard
parents: 68
diff changeset
66 C<IMPL::Security::Context> - контекст безопасности.
wizard
parents: 68
diff changeset
67
wizard
parents: 68
diff changeset
68 =head1 SINOPSYS
wizard
parents: 68
diff changeset
69
wizard
parents: 68
diff changeset
70 =begin code
wizard
parents: 68
diff changeset
71
wizard
parents: 68
diff changeset
72 my $context = IMPL::Security::Context->nobody;
wizard
parents: 68
diff changeset
73
wizard
parents: 68
diff changeset
74 my $result = $context->Impersonate(
wizard
parents: 68
diff changeset
75 sub {
wizard
parents: 68
diff changeset
76 # do some untrusted code
wizard
parents: 68
diff changeset
77 }
wizard
parents: 68
diff changeset
78 );
wizard
parents: 68
diff changeset
79
wizard
parents: 68
diff changeset
80 =end code
wizard
parents: 68
diff changeset
81
wizard
parents: 68
diff changeset
82 =head1 DESCRIPTION
wizard
parents: 68
diff changeset
83
wizard
parents: 68
diff changeset
84 C<[Autofill]>
wizard
parents: 68
diff changeset
85
wizard
parents: 68
diff changeset
86 Являет собой контекст безопасности, описывает пользователя и привелегии, так же
wizard
parents: 68
diff changeset
87 у потока есть текущий контекст безопасности, по умолчанию он C<nobody>.
wizard
parents: 68
diff changeset
88
wizard
parents: 68
diff changeset
89 =head1 MEMBERS
wizard
parents: 68
diff changeset
90
wizard
parents: 68
diff changeset
91 =over
wizard
parents: 68
diff changeset
92
wizard
parents: 68
diff changeset
93 =item C<CTOR(%props)>
wizard
parents: 68
diff changeset
94
wizard
parents: 68
diff changeset
95 Создает объект и заполняет его свойствами.
wizard
parents: 68
diff changeset
96
wizard
parents: 68
diff changeset
97 =item C<[get] principal>
wizard
parents: 68
diff changeset
98
wizard
parents: 68
diff changeset
99 Идентификатор пользователя, владельца контекста.
wizard
parents: 68
diff changeset
100
wizard
parents: 68
diff changeset
101 =item C<[get] rolesAssigned>
wizard
parents: 68
diff changeset
102
wizard
parents: 68
diff changeset
103 Список назначенных (активных) ролей пользователю.
wizard
parents: 68
diff changeset
104
wizard
parents: 68
diff changeset
105 =item C<[get] auth>
wizard
parents: 68
diff changeset
106
wizard
parents: 68
diff changeset
107 Объект асторизации C<IMPL::Security::Auth>, использованный при создании текущего контекста.
wizard
parents: 68
diff changeset
108
wizard
parents: 68
diff changeset
109 =item C<Impersonate($code)>
wizard
parents: 68
diff changeset
110
wizard
parents: 68
diff changeset
111 Делает контекст текущим и выполняет в нем функцию по ссылке C<$code>. По окончании
wizard
parents: 68
diff changeset
112 выполнения, контекст восстанавливается.
wizard
parents: 68
diff changeset
113
wizard
parents: 68
diff changeset
114 =item C<[static,get] nobody>
wizard
parents: 68
diff changeset
115
wizard
parents: 68
diff changeset
116 Контекст для неаутентифицированных пользователей, минимум прав.
wizard
parents: 68
diff changeset
117
wizard
parents: 68
diff changeset
118 =item C<[static,get] current>
wizard
parents: 68
diff changeset
119
wizard
parents: 68
diff changeset
120 Текущий контекст.
wizard
parents: 68
diff changeset
121
wizard
parents: 68
diff changeset
122 =back
wizard
parents: 68
diff changeset
123
wizard
parents: 68
diff changeset
124 =cut