Mercurial > pub > Impl
diff Lib/IMPL/Web/QueryHandler/SecureCookie.pm @ 194:4d0e1962161c
Replaced tabs with spaces
IMPL::Web::View - fixed document model, new features (control classes, document constructor parameters)
author | cin |
---|---|
date | Tue, 10 Apr 2012 20:08:29 +0400 |
parents | d1676be8afcc |
children |
line wrap: on
line diff
--- a/Lib/IMPL/Web/QueryHandler/SecureCookie.pm Tue Apr 10 08:13:22 2012 +0400 +++ b/Lib/IMPL/Web/QueryHandler/SecureCookie.pm Tue Apr 10 20:08:29 2012 +0400 @@ -9,76 +9,76 @@ use IMPL::Security; BEGIN { - public property salt => prop_all; + public property salt => prop_all; } sub CTOR { - my ($this) = @_; - - $this->salt('DeadBeef') unless $this->salt; + my ($this) = @_; + + $this->salt('DeadBeef') unless $this->salt; } sub Process { - my ($this,$action,$nextHandler) = @_; - - return undef unless $nextHandler; - - local $IMPL::Security::authority = $this; - - my $method = $action->query->cookie('method') || 'simple'; - - if ($method eq 'simple') { - - my $sid = $action->query->cookie('sid'); - my $cookie = $action->query->cookie('sdata'); - my $sign = $action->query->cookie('sign'); - - if ( - $sid and - $cookie and - $sign and - $sign eq md5_hex( - $this->salt, - $sid, - $cookie, - $this->salt - ) - ) { - # TODO: add a DefferedProxy to deffer a request to a data source - my $context = $action->application->security->sourceSession->find( - { id => $sid } - ) or return $nextHandler->(); - - my ($result,$challenge) = $context->auth->ValidateSession($cookie); - - if ($result == AUTH_SUCCESS) { - $context->authority($this); - return $context->Impersonate($nextHandler); - } else { - return $nextHandler->(); - } - } else { - return $nextHandler->(); - } - } else { - return $nextHandler->(); - } + my ($this,$action,$nextHandler) = @_; + + return undef unless $nextHandler; + + local $IMPL::Security::authority = $this; + + my $method = $action->query->cookie('method') || 'simple'; + + if ($method eq 'simple') { + + my $sid = $action->query->cookie('sid'); + my $cookie = $action->query->cookie('sdata'); + my $sign = $action->query->cookie('sign'); + + if ( + $sid and + $cookie and + $sign and + $sign eq md5_hex( + $this->salt, + $sid, + $cookie, + $this->salt + ) + ) { + # TODO: add a DefferedProxy to deffer a request to a data source + my $context = $action->application->security->sourceSession->find( + { id => $sid } + ) or return $nextHandler->(); + + my ($result,$challenge) = $context->auth->ValidateSession($cookie); + + if ($result == AUTH_SUCCESS) { + $context->authority($this); + return $context->Impersonate($nextHandler); + } else { + return $nextHandler->(); + } + } else { + return $nextHandler->(); + } + } else { + return $nextHandler->(); + } } sub WriteResponse { - my ($this,$response,$sid,$cookie,$method) = @_; + my ($this,$response,$sid,$cookie,$method) = @_; - my $sign = md5_hex( - $this->salt, - $sid, - $cookie, - $this->salt - ); - - $response->setCookie(sid => $sid); - $response->setCookie(sdata => $cookie); - $response->setCookie(sign => $sign); - $response->setCookie(method => $method) if $method; + my $sign = md5_hex( + $this->salt, + $sid, + $cookie, + $this->salt + ); + + $response->setCookie(sid => $sid); + $response->setCookie(sdata => $cookie); + $response->setCookie(sign => $sign); + $response->setCookie(method => $method) if $method; } 1;