diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Lib/IMPL/Security/Context.pm	Tue Feb 23 22:57:16 2010 +0300
@@ -0,0 +1,42 @@
+package IMPL::Security::Context;
+use strict;
+use warnings;
+
+use base qw(IMPL::Object);
+
+use IMPL::Class::Property;
+
+require IMPL::Security::Principal;
+
+my $current = __PACKAGE__->nobody;
+my $nobody;
+
+BEGIN {
+    public property Principal => prop_get;
+    public property AssignedRoles => prop_all;
+}
+
+sub Impersonate {
+    my ($this,$code) = @_;
+    
+    my $old = $current;
+    my $result;
+    local $@;
+    eval {
+        $result = $code->();
+    };
+    $current = $old;
+    if($@) {
+        die $@;
+    } else {
+        return $result;
+    }
+}
+
+sub nobody {
+    my ($self) = @_;
+    $nobody = $self->new(Principal => IMPL::Security::Principal->nobody, AssignedRoles => undef) unless $nobody;
+    $nobody;
+}
+
+1;