annotate Lib/IMPL/Security/Context.pm @ 47:a9b70d836b28

Web::Application development (request controller) Security development
author Sergey
date Tue, 23 Feb 2010 22:57:16 +0300
parents
children 16ada169ca75
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
47
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
1 package IMPL::Security::Context;
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
2 use strict;
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
3 use warnings;
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
4
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
5 use base qw(IMPL::Object);
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
6
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
7 use IMPL::Class::Property;
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
8
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
9 require IMPL::Security::Principal;
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
10
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
11 my $current = __PACKAGE__->nobody;
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
12 my $nobody;
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
13
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
14 BEGIN {
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
15 public property Principal => prop_get;
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
16 public property AssignedRoles => prop_all;
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
17 }
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
18
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
19 sub Impersonate {
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
20 my ($this,$code) = @_;
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
21
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
22 my $old = $current;
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
23 my $result;
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
24 local $@;
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
25 eval {
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
26 $result = $code->();
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
27 };
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
28 $current = $old;
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
29 if($@) {
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
30 die $@;
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
31 } else {
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
32 return $result;
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
33 }
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
34 }
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
35
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
36 sub nobody {
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
37 my ($self) = @_;
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
38 $nobody = $self->new(Principal => IMPL::Security::Principal->nobody, AssignedRoles => undef) unless $nobody;
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
39 $nobody;
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
40 }
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
41
a9b70d836b28 Web::Application development (request controller)
Sergey
parents:
diff changeset
42 1;