Mercurial > pub > Impl
comparison Lib/IMPL/Web/QueryHandler/AuthCookie.pm @ 69:8c7b88bdb663
Cookie Simple auth support
| author | wizard |
|---|---|
| date | Wed, 24 Mar 2010 17:41:41 +0300 |
| parents | 739f1288ca84 |
| children |
comparison
equal
deleted
inserted
replaced
| 68:739f1288ca84 | 69:8c7b88bdb663 |
|---|---|
| 2 | 2 |
| 3 use base qw(IMPL::Web::QueryHandler); | 3 use base qw(IMPL::Web::QueryHandler); |
| 4 use Digest::MD5 qw(md5_hex); | 4 use Digest::MD5 qw(md5_hex); |
| 5 | 5 |
| 6 use IMPL::Class::Property; | 6 use IMPL::Class::Property; |
| 7 use IMPL::Security::Auth qw(:Const); | |
| 7 | 8 |
| 8 BEGIN { | 9 BEGIN { |
| 9 public property salt => prop_all; | 10 public property salt => prop_all; |
| 11 } | |
| 12 | |
| 13 sub CTOR { | |
| 14 my ($this) = @_; | |
| 15 | |
| 16 | |
| 10 } | 17 } |
| 11 | 18 |
| 12 sub Process { | 19 sub Process { |
| 13 my ($this,$action,$nextHandler) = @_; | 20 my ($this,$action,$nextHandler) = @_; |
| 14 | 21 |
| 15 my $method = $action->query->cookie('method') || 'simple'; | 22 my $method = $action->query->cookie('method') || 'simple'; |
| 16 | 23 |
| 17 if ($method eq 'simple') { | 24 if ($method eq 'simple') { |
| 18 | 25 |
| 26 my $sid = $action->query->cookie('sid'); | |
| 27 | |
| 19 if ($action->query->cookie('sign') eq md5_hex( | 28 if ($action->query->cookie('sign') eq md5_hex( |
| 20 $this->salt, | 29 $this->salt, |
| 21 $action->query->cookie('sid'), | 30 $sid, |
| 22 $this->salt | 31 $this->salt |
| 23 ) ) { | 32 ) ) { |
| 24 | 33 |
| 25 my $context = $action->application->security->Session($action->query->cookie('sid')); | 34 my $context = $action->application->security->Session( |
| 35 id => $sid, | |
| 36 method => 'simple' | |
| 37 ); | |
| 26 | 38 |
| 27 $context->auth-> | 39 my ($result,$challenge) = $context->auth->ValidateSession($sid); |
| 28 | 40 |
| 41 if ($result == AUTH_SUCCESS) { | |
| 42 return $context->Impersonate($nextHandler); | |
| 43 } else { | |
| 44 return $nextHandler->(); | |
| 45 } | |
| 29 } | 46 } |
| 30 | |
| 31 } else { | 47 } else { |
| 32 die new IMPL::Exception("Unknown auth method",$method); | 48 die new IMPL::Exception("Unknown auth method",$method); |
| 33 } | 49 } |
| 34 } | 50 } |
| 35 | 51 |
