changeset 47:a9b70d836b28

Web::Application development (request controller) Security development
author Sergey
date Tue, 23 Feb 2010 22:57:16 +0300
parents 75148ccd732d
children 1c3c3e63a314
files Lib/IMPL/Config.pm Lib/IMPL/Security/Context.pm Lib/IMPL/Security/Principal.pm Lib/IMPL/Web/Application.pm
diffstat 4 files changed, 93 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/Lib/IMPL/Config.pm	Tue Feb 02 17:09:49 2010 +0300
+++ b/Lib/IMPL/Config.pm	Tue Feb 23 22:57:16 2010 +0300
@@ -116,6 +116,8 @@
 
 =head1 MEMBERS
 
+=over
+
 =item static LoadXMLFile($fileName)
 Создает из XML файла экземпляр приложения
 
@@ -125,4 +127,6 @@
 =item xml
 Сохраняет конфигурацию приложения в XML строку
 
+=back
+
 =cut
\ No newline at end of file
--- /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;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Lib/IMPL/Security/Principal.pm	Tue Feb 23 22:57:16 2010 +0300
@@ -0,0 +1,15 @@
+package IMPL::Security::Principal;
+use strict;
+use warnings;
+
+use base qw(IMPL::Object);
+use IMPL::Class::Property;
+
+BEGIN {
+    public property Name => prop_get;
+    public property Description => prop_get;
+}
+
+
+
+1;
--- a/Lib/IMPL/Web/Application.pm	Tue Feb 02 17:09:49 2010 +0300
+++ b/Lib/IMPL/Web/Application.pm	Tue Feb 23 22:57:16 2010 +0300
@@ -3,13 +3,45 @@
 use warnings;
 
 use base qw(IMPL::Object IMPL::Object::Singleton);
+use IMPL::Class::Property;
 
+BEGIN {
+    public property RequestFactory => prop_all;
+    public property ContextInitializers => prop_all;
+}
 
+# custom factory
+sub new {
+    my ($self,$file) = @_;
+    
+    return $self->LoadXMLFile($file);
+}
+
+sub Run {
+    my ($this) = @_;
+    
+    while (my $request = $this->fetch_request()) {
+        my $context = $this->prepare_context($request);
+        $context->invoke($request);
+    }
+}
 
 1;
 
 =pod
 
+=head1 SYNOPSIS
 
+require MyApp;
+MyApp->instance('app.config')->Run();
+
+=head1 DESCRIPTION
+
+Зкземпляр приложения содержит в себе глобальные настройки, реализует контроллер запросов,
+
+Получая запрос из источника запросов, создает контекст выполнения запроса
+затем выполняет запрос в указанном контексте.
+
+Контекст формируется сначала из запроса, а затем посредством набора инициализаторов
 
 =cut
\ No newline at end of file