view Lib/IMPL/Security/Context.pm @ 48:1c3c3e63a314

security in progress
author Sergey
date Fri, 26 Feb 2010 01:43:42 +0300
parents a9b70d836b28
children 16ada169ca75
line wrap: on
line source

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;