# HG changeset patch # User wizard # Date 1269870006 -14400 # Node ID 84aa8c395fce0e13350e5c6040a61b20b2f816eb # Parent 2f31ecabe9ea88a6fc1f0773ab54b7f031688864 doc minor fixes diff -r 2f31ecabe9ea -r 84aa8c395fce Lib/IMPL/Security.pm --- a/Lib/IMPL/Security.pm Mon Mar 29 06:56:05 2010 +0400 +++ b/Lib/IMPL/Security.pm Mon Mar 29 17:40:06 2010 +0400 @@ -67,10 +67,10 @@ #forced delegation my $delegatedContext = IMPL::Security::Context->new( - Principal => IMPL::Security::Principal->new( - Name => 'suser' + principal => IMPL::Security::Principal->new( + name => 'suser' ), - AssignedRoles => ['administrator'] + rolesAssigned => ['administrator'] ) my $result; diff -r 2f31ecabe9ea -r 84aa8c395fce Lib/IMPL/Security/Context.pm --- a/Lib/IMPL/Security/Context.pm Mon Mar 29 06:56:05 2010 +0400 +++ b/Lib/IMPL/Security/Context.pm Mon Mar 29 17:40:06 2010 +0400 @@ -2,7 +2,9 @@ use strict; use warnings; -use base qw(IMPL::Object); +use base qw(IMPL::Object IMPL::Object::Autofill); + +__PACKAGE__->PassThroughArgs; use IMPL::Class::Property; @@ -17,6 +19,12 @@ public property auth => prop_all; } +sub CTOR { + my ($this) = @_; + + die new IMPL::InvalidArgumentException("The parameter is required", 'principal') unless $this->principal; +} + sub Impersonate { my ($this,$code) = @_; @@ -34,13 +42,13 @@ } } -sub contextNobody { +sub nobody { my ($self) = @_; $nobody = $self->new(principal => IMPL::Security::Principal->nobody, rolesAssigned => undef) unless $nobody; $nobody; } -sub contextCurrent { +sub current { my ($self) = @_; $current = __PACKAGE__->nobody unless $current; @@ -48,3 +56,69 @@ } 1; + +__END__ + +=pod + +=head1 NAME + +C - контекст безопасности. + +=head1 SINOPSYS + +=begin code + +my $context = IMPL::Security::Context->nobody; + +my $result = $context->Impersonate( + sub { + # do some untrusted code + } +); + +=end code + +=head1 DESCRIPTION + +C<[Autofill]> + +Являет собой контекст безопасности, описывает пользователя и привелегии, так же +у потока есть текущий контекст безопасности, по умолчанию он C. + +=head1 MEMBERS + +=over + +=item C + +Создает объект и заполняет его свойствами. + +=item C<[get] principal> + +Идентификатор пользователя, владельца контекста. + +=item C<[get] rolesAssigned> + +Список назначенных (активных) ролей пользователю. + +=item C<[get] auth> + +Объект асторизации C, использованный при создании текущего контекста. + +=item C + +Делает контекст текущим и выполняет в нем функцию по ссылке C<$code>. По окончании +выполнения, контекст восстанавливается. + +=item C<[static,get] nobody> + +Контекст для неаутентифицированных пользователей, минимум прав. + +=item C<[static,get] current> + +Текущий контекст. + +=back + +=cut \ No newline at end of file diff -r 2f31ecabe9ea -r 84aa8c395fce Lib/IMPL/Security/Principal.pm --- a/Lib/IMPL/Security/Principal.pm Mon Mar 29 06:56:05 2010 +0400 +++ b/Lib/IMPL/Security/Principal.pm Mon Mar 29 17:40:06 2010 +0400 @@ -2,19 +2,49 @@ use strict; use warnings; -use base qw(IMPL::Object); +use base qw(IMPL::Object IMPL::Object::Autofill); use IMPL::Class::Property; BEGIN { - public property Name => prop_get; - public property Description => prop_get; + public property name => prop_get; + public property description => prop_all; } my $nobody; sub nobody { - $nobody = $_[0]->new(Name => 'nobody', Description => '') unless $nobody; + $nobody = $_[0]->new(name => 'nobody', description => '') unless $nobody; return $nobody; } 1; + +__END__ + +=pod + +=head1 NAME + +C Идентификатор пользователя + +C<[Autofill]> + +=head1 MEMBERS + +=over + +=item C + +Создает новый объект. + +=item C<[get] name> + +Возвращает имя пользователя. + +=item C<[get,set] description> + +Возвращает описание пользователя. + +=back + +=cut diff -r 2f31ecabe9ea -r 84aa8c395fce Lib/IMPL/Web/Application/Session.pm --- a/Lib/IMPL/Web/Application/Session.pm Mon Mar 29 06:56:05 2010 +0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -package IMPL::Web::Application::Session; -use strict; - -use base qw(IMPL::Object); - -use IMPL::Security::Auth qw(GenSSID); - -use IMPL::Class::Property; - -BEGIN { - public property id => prop_get | owner_set; - public property principal => prop_get | owner_set; - public property authSession => prop_get | owner_set; - public property roles => prop_get | owner_set | prop_list; -} - -sub CTOR { - my ($this,%args) = @_; - - $this->principal($args{principal}) or die new IMPL::InvalidArgumentException("A principal is required"); - $this->authSession($args{auth}) or die new IMPL::InvalidArgumentException("An auth session is required"); - $this->roles($args{roles}) if $args{roles}; - - $this->id(GenSSID()); -} - -sub DoAuth { - my ($this,$secData) = @_; - - return $this->authSession->DoAuth($secData); -} - -sub ValidateSession { - my ($this,$secData) = @_; - - return $this->authSession->ValidateSession($secData); -} - -1; - -__END__ \ No newline at end of file diff -r 2f31ecabe9ea -r 84aa8c395fce Lib/IMPL/Web/QueryHandler/SecureCookie.pm --- a/Lib/IMPL/Web/QueryHandler/SecureCookie.pm Mon Mar 29 06:56:05 2010 +0400 +++ b/Lib/IMPL/Web/QueryHandler/SecureCookie.pm Mon Mar 29 17:40:06 2010 +0400 @@ -24,10 +24,12 @@ if ($method eq 'simple') { my $sid = $action->query->cookie('sid'); + my $cookie = $action->query->cookie('cookie'); if ($action->query->cookie('sign') eq md5_hex( $this->salt, $sid, + $cookie, $this->salt ) ) { @@ -35,7 +37,7 @@ id => $sid ); - my ($result,$challenge) = $context->auth->ValidateSession($sid); + my ($result,$challenge) = $context->auth->ValidateSession($cookie); if ($result == AUTH_SUCCESS) { return $context->Impersonate($nextHandler); diff -r 2f31ecabe9ea -r 84aa8c395fce Lib/IMPL/Web/Security/Session.pm --- a/Lib/IMPL/Web/Security/Session.pm Mon Mar 29 06:56:05 2010 +0400 +++ b/Lib/IMPL/Web/Security/Session.pm Mon Mar 29 17:40:06 2010 +0400 @@ -1,14 +1,55 @@ package IMPL::Web::Security::Session; - -use base qw(IMPL::Object); +use strict; +use base qw(IMPL::Security::Context); use IMPL::Class::Property; __PACKAGE__->PassThroughArgs; BEGIN { - public property id => prop_all; - public property securityContext => prop_all; + public property id => prop_all | owner_set; } -1; \ No newline at end of file +1; + +__END__ + +=pod + +=head1 NAME + +C - Сессия пользователя. + +=head1 SINOPSYS + +=begin code + +# define a custom session for the application + +package App::Session; +use base qw(IMPL::Web::Security::Session); + +use IMPL::Class::Property; + +BEGIN { + public property transactionId => prop_all; +} + +=end code + +=head1 DESCRIPTION + +C + +Представляет собой контекст безопасности, имеет идентификатор. Является базовым классом +для расширения дополнительными атрибутами. + +=head1 MEMBERS + +=over + +=item C<[get] id> + +=back + +=cut \ No newline at end of file diff -r 2f31ecabe9ea -r 84aa8c395fce _doc/make.pl --- a/_doc/make.pl Mon Mar 29 06:56:05 2010 +0400 +++ b/_doc/make.pl Mon Mar 29 17:40:06 2010 +0400 @@ -119,7 +119,7 @@ IMPL reference - +