view Lib/IMPL/Security/Context.pm @ 230:6d8092d8ce1b

*reworked IMPL::Security *reworked IMPL::Web::Security *refactoring
author sergey
date Mon, 08 Oct 2012 03:37:37 +0400
parents 4d0e1962161c
children b8c724f6de36
line wrap: on
line source

package IMPL::Security::Context;
use strict;
use warnings;

use IMPL::require {
    Principal => 'IMPL::Security::Principal',
    Role => 'IMPL::Security::Role',
    AbstractContext => 'IMPL::Security::AbstractContext',
    Exception => 'IMPL::Exception',
    ArgumentException => '-IMPL::InvalidArgumentException'
    
};

use IMPL::declare {
    base => [
        'IMPL::Object' => undef,
        'IMPL::Object::Autofill' => undef,
        'IMPL::Security::AbstractContext' => undef,
    ],
    props => [
        @{AbstractContext->abstractProps()}
    ]
};

__PACKAGE__->abstractProps([]);


my $nobody;

sub CTOR {
    my ($this) = @_;
    
    die ArgumentException->new("The parameter is required", 'principal') unless $this->principal;
}

sub nobody {
    my ($self) = @_;
    $nobody = $self->new(principal => Principal->nobody) unless $nobody;
    $nobody;
}

sub isTrusted {
    return 1;
}

1;

__END__

=pod

=head1 NAME

C<IMPL::Security::Context> - реализация контекста безопасности создаваемого в 
приложении.

=head1 SYNOPSIS

=begin code

my $context = IMPL::Security::Context->nobody;

my $result = $context->Impersonate(
    sub {
        # do some untrusted code
    }
);

$context = IMPL::Security::Context->new(
    principal => $user,
    assignedRoles => [
        $backupRole,
        $controlRole
    ]
);

$context->Impersonate(
    sub {
        
        # do some authorized operations
        
        $service->backupData('current.bak');
        $service->stop();
    }
);

=end code

=head1 DESCRIPTION

C<autofill>

Данная реализация контекста безопасности не привязана ни к источнику данных
ни к пакету аутентификации и авторизации, ее приложение может создать в любой
момент, при этом система сама несет ответственность за последствия.

Данный контекст нужен для выполнения системой служебных функций.

=head1 MEMBERS

см. также C<IMPL::Security::AbstractContext>.

=head2 C<CTOR(%props)>

Создает объект и заполняет его свойствами. C<principal> должен быть обязательно
указан.

=head2 C<[static,get] nobody>

Контекст для неаутентифицированных пользователей, минимум прав.

=cut