# HG changeset patch # User wizard@linux-odin.local # Date 1267453536 -10800 # Node ID a1498298d3eee6d7732be159f0b5577e25e5a1fd # Parent 521c9c1a3ea1a45387fb7c12cff389988fafc2f7 Security in progress diff -r 521c9c1a3ea1 -r a1498298d3ee .includepath --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.includepath Mon Mar 01 17:25:36 2010 +0300 @@ -0,0 +1,5 @@ + + + + + diff -r 521c9c1a3ea1 -r a1498298d3ee .project --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.project Mon Mar 01 17:25:36 2010 +0300 @@ -0,0 +1,17 @@ + + + Impl + + + + + + org.epic.perleditor.perlbuilder + + + + + + org.epic.perleditor.perlnature + + diff -r 521c9c1a3ea1 -r a1498298d3ee .settings/org.eclipse.core.resources.prefs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.settings/org.eclipse.core.resources.prefs Mon Mar 01 17:25:36 2010 +0300 @@ -0,0 +1,3 @@ +#Fri Feb 26 10:46:20 MSK 2010 +eclipse.preferences.version=1 +encoding/=cp1251 diff -r 521c9c1a3ea1 -r a1498298d3ee .settings/org.eclipse.ltk.core.refactoring.prefs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.settings/org.eclipse.ltk.core.refactoring.prefs Mon Mar 01 17:25:36 2010 +0300 @@ -0,0 +1,3 @@ +#Fri Feb 26 10:46:20 MSK 2010 +eclipse.preferences.version=1 +org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false diff -r 521c9c1a3ea1 -r a1498298d3ee Lib/IMPL/SVN.pm --- a/Lib/IMPL/SVN.pm Sat Feb 27 16:28:45 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -package IMPL::SVN; -use strict; - -use base qw(IMPL::Object); -use IMPL::Object::Property; - -BEGIN { - public virtual _direct property SvnClient => get; -} - -sub UpdateBatch { - my ($this,$revstart,$revend) = @_; - - -} \ No newline at end of file diff -r 521c9c1a3ea1 -r a1498298d3ee Lib/IMPL/Security.pm --- a/Lib/IMPL/Security.pm Sat Feb 27 16:28:45 2010 +0300 +++ b/Lib/IMPL/Security.pm Mon Mar 01 17:25:36 2010 +0300 @@ -1,4 +1,24 @@ package IMPL::Security; +require IMPL::Security::Context; +require IMPL::Security::Rule::RoleCheck; + +our @rules = ( + \&IMPL::Security::Rule::RoleCheck::SatisfyAll +); + +sub AccessCheck { + my ($self, $object, $desiredAccess, $context) = @_; + + $context = IMPL::Security::Context->contextCurrent; + + $_->() or return 0 foreach @{$self->Rules}; + + return 1; +} + +sub Rules { + return \@rules; +} 1; @@ -8,6 +28,16 @@ =head1 DESCRIPTION +Модуль для инфраструктуры безопасности, реализует основные функции для авторизации +и аутентификации пользователей. + +Модуль аутентификации, реализиция которого зависит от приложения, аутентифицирует +пользователя, при этом создается контекст безопасности, который содержит +идентификатор пользователя и список активных ролей. + +При проверке прав доступа происходит последовательная проверка правил доступа, +если все правила выполнены, то доступ разрешается. + =cut \ No newline at end of file diff -r 521c9c1a3ea1 -r a1498298d3ee Lib/IMPL/Security/Auth.pm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/IMPL/Security/Auth.pm Mon Mar 01 17:25:36 2010 +0300 @@ -0,0 +1,36 @@ +package IMPL::Security::Auth; + +use constant { + SUCCESS => 1, + INCOMPLETE => 2, + FAIL => 3 +}; + +use base qw(Exporter); + +our @EXPORT_OK = qw(&SUCCESS &INCOMPLETE &FAI); +our %EXPORT_TAGS = (Const => [qw(&SUCCESS &INCOMPLETE &FAI)]); + +1; + +__END__ + +=pod + +=head1 DESCRIPTION + +Базовыйы модуль для авторизации пользователей. + +Процесс авторизации состоит зи следующих шагов + +1. Клиент отправляет на сервер запрос для авторизации с начальными параметрами. +2. Сервер получает запрос, находит данные аутентификации для клиента, +производит аутентификацию +3. Модуль аутентификации возвращает результат, на основе которого +либо формируется контекст безопасности, либо продолжается процесс аутентификации + +Полученный контекст безопасности содержит объект для доступа к сессии аутентификации, +в которм содержится уникальные свойства сессии, например идентификатор, сеансовые ключи +и т.д. + +=cut \ No newline at end of file diff -r 521c9c1a3ea1 -r a1498298d3ee Lib/IMPL/Security/Auth/AuthResult.pm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/IMPL/Security/Auth/AuthResult.pm Mon Mar 01 17:25:36 2010 +0300 @@ -0,0 +1,15 @@ +package IMPL::Security::Auth::Result; +use strict; + +use base qw(IMPL::Object); +use IMPL::Class::Property; +use IMPL::Class::Property::Direct; + +BEGIN { + public _direct property State => prop_get; + public _direct property ClientSecData => prop_get; + public _direct property AuthMod => prop_get; +} + + +1; diff -r 521c9c1a3ea1 -r a1498298d3ee Lib/IMPL/Security/Auth/Simple.pm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/IMPL/Security/Auth/Simple.pm Mon Mar 01 17:25:36 2010 +0300 @@ -0,0 +1,27 @@ +package IMPL::Security::Auth::Simple; + +use base qw(IMPL::Security::Auth); +use Digest::MD5; +import IMPL::Security::Auth qw(:Const); + +sub DoAuth { + my ($this,$clientData,$serverData) = @_; + + if (Digest::MD5::md5_hex($clientData) eq $serverData) { + return SUCCESS; + } elsee { + return FAIL; + } +} + +1; + +__END__ + +=pod + +=head1 DESCRIPTION + +Модуль простой авторизации + +=cut \ No newline at end of file diff -r 521c9c1a3ea1 -r a1498298d3ee Lib/IMPL/Security/AuthResult.pm --- a/Lib/IMPL/Security/AuthResult.pm Sat Feb 27 16:28:45 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -package IMPL::Security::AuthResult; -use strict; - -use base qw(IMPL::Object); -use IMPL::Class::Property; -use IMPL::Class::Property::Direct; - -BEGIN { - public _direct property State => prop_get; - public _direct property Session => prop_get; - public _direct property ClientSecData => prop_get; - public _direct property AuthMod => prop_get; -} - - -1; diff -r 521c9c1a3ea1 -r a1498298d3ee Lib/IMPL/Security/Context.pm --- a/Lib/IMPL/Security/Context.pm Sat Feb 27 16:28:45 2010 +0300 +++ b/Lib/IMPL/Security/Context.pm Mon Mar 01 17:25:36 2010 +0300 @@ -8,12 +8,13 @@ require IMPL::Security::Principal; -my $current = __PACKAGE__->nobody; +my $current; my $nobody; BEGIN { public property Principal => prop_get; public property AssignedRoles => prop_all; + public property AuthSession => prop_all; } sub Impersonate { @@ -33,10 +34,17 @@ } } -sub nobody { +sub contextNobody { my ($self) = @_; $nobody = $self->new(Principal => IMPL::Security::Principal->nobody, AssignedRoles => undef) unless $nobody; $nobody; } +sub contextCurrent { + my ($self) = @_; + + $current = __PACKAGE__->nobody unless $current; + $current; +} + 1; diff -r 521c9c1a3ea1 -r a1498298d3ee Lib/IMPL/Security/Role.pm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/IMPL/Security/Role.pm Mon Mar 01 17:25:36 2010 +0300 @@ -0,0 +1,67 @@ +package IMPL::Security::Role; + +use base qw(IMPL::Object); + +use IMPL::Class::Property; + +BEGIN { + public property roleName => prop_get; + public property parentRoles => prop_get; +} + +sub CTOR { + my ($this,$name,$parentRoles) = @_; + + $this->roleName($name); + $this->parentRoles($parentRoles); +} + +sub Satisfy { + my ($this,@roles) = @_; + + return 1 unless $this->_FilterRoles( @roles ); +} + +sub _FilterRoles { + my ($this,@roles) = @_; + + @roles = grep not (ref $_ ? $this == $_ : $this->roleName eq $_), @roles; + + @roles = $_->_FilterRoles(@roles) or return foreach @{$this->parentRoles} ; + + return @roles; +} + + +1; + +__END__ + +=pod + +=head1 DESCRIPTION + +Роль. Может включать в себя базовые роли. +Имеется метод для проверки наличия необходимых ролей в текущей роли. + +=head1 MEMBERS + +=over + +=item C + +Имя роли, ее идентификатор + +=item C + +Список родительских ролей + +=item C + +Проверяет наличие ролей указанных ролей из списка @roles_list. +Допускается использование как самих объектов, так и имен ролей. +Возвращает 0 в случае неудачи, 1 при наличии необходимых ролей + +=back + +=cut \ No newline at end of file diff -r 521c9c1a3ea1 -r a1498298d3ee Lib/IMPL/Security/Rule/RoleCheck.pm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/IMPL/Security/Rule/RoleCheck.pm Mon Mar 01 17:25:36 2010 +0300 @@ -0,0 +1,16 @@ +package IMPL::Security::Rule::RoleCheck; + +require IMPL::Security::Role; + +sub SatisfyAll { + my ($secPackage,$object,$desiredAccess,$context) = @_; + + my $roleEffective = new IMPL::Security::Role ( effective => $context->AssignedRoles ); + + return $roleEffective->Satisfy(ExtractRoles($object)); +} + +sub _ExtractRoles { + return (); +} +