changeset 231:ff1e8fa932f2

sync
author sergey
date Tue, 09 Oct 2012 03:09:41 +0400
parents 6d8092d8ce1b
children 5c82eec23bb6
files Lib/IMPL/Web/Handler/SecureCookie.pm Lib/IMPL/Web/Security.pm
diffstat 2 files changed, 15 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/Lib/IMPL/Web/Handler/SecureCookie.pm	Mon Oct 08 03:37:37 2012 +0400
+++ b/Lib/IMPL/Web/Handler/SecureCookie.pm	Tue Oct 09 03:09:41 2012 +0400
@@ -10,6 +10,9 @@
         SecurityContext => 'IMPL::Security::Context',
         User => 'IMPL::Security::User',
         AuthSimple => 'IMPL::Security::Auth::Simple',
+        Exception => 'IMPL::Exception',
+        OperationException => '-IMPL::InvalidOperationException',
+        HttpResponse => '-IMPL::Web::HttpResponse'
     },
     base => {
         'IMPL::Object' => undef,
@@ -68,15 +71,17 @@
         
     }
     
-    $context = SecurityContext->new(principal => User->nobody, authority => $this);
+    $context ||= SecurityContext->new(principal => User->nobody, authority => $this);
     
     my $httpResponse = $context->Impersonate($nextHandler);
     
-    $this->WriteResponse($httpResponse);
+    die OperationException->new("A HttpResponse instance is expected")
+        unless ref $httpResponse && eval { $httpResponse->isa(HttpResponse) };
     
+    return $this->WriteResponse($httpResponse);
 }
 
-sub CreateContext {
+sub InitSession {
     my ($this,$user,$auth,$roles) = @_;
     
     my $sid = GenSSID();
@@ -90,7 +95,7 @@
     my $context = $this->$manager->CreateSession(
         sessionId => $sid,
         principal => $user,
-        auth => AuthSimple->(password => $cookie),
+        auth => AuthSimple->new(password => $cookie),
         authority => $this,
         assignedRoles => $roles
     );
@@ -116,6 +121,8 @@
         $response->cookies->{sdata} = $data->{sdata};
         $response->cookies->{sign} = $sign;
     }
+    
+    return $response;
 }
 
 1;
@@ -141,12 +148,10 @@
 
 =head1 MEMBERS
 
-=over
-
-=item C<[get,set] salt>
+=head2 C<[get,set] salt>
 
 Скаляр, использующийся для подписи данных.
 
-=back
+=head2 C<InitSession($user,$auth,$roles)>
 
 =cut
--- a/Lib/IMPL/Web/Security.pm	Mon Oct 08 03:37:37 2012 +0400
+++ b/Lib/IMPL/Web/Security.pm	Tue Oct 09 03:09:41 2012 +0400
@@ -29,12 +29,11 @@
     my ($status,$answer) = $auth->DoAuth($challenge);
     
     if ($status != AUTH_FAIL) {
-        SecurityContext->current->authority->CreateContext(
+        SecurityContext->current->authority->InitSession(
             $user,
             $auth,
             [$user->roles],
-            $answer,
-            $this
+            $answer
         );
     }