73
|
1 package IMPL::Web::QueryHandler::SecureCookie;
|
68
|
2
|
|
3 use base qw(IMPL::Web::QueryHandler);
|
|
4 use Digest::MD5 qw(md5_hex);
|
|
5
|
|
6 use IMPL::Class::Property;
|
69
|
7 use IMPL::Security::Auth qw(:Const);
|
68
|
8
|
|
9 BEGIN {
|
|
10 public property salt => prop_all;
|
|
11 }
|
|
12
|
69
|
13 sub CTOR {
|
|
14 my ($this) = @_;
|
|
15
|
|
16
|
|
17 }
|
|
18
|
68
|
19 sub Process {
|
|
20 my ($this,$action,$nextHandler) = @_;
|
|
21
|
|
22 my $method = $action->query->cookie('method') || 'simple';
|
|
23
|
|
24 if ($method eq 'simple') {
|
|
25
|
69
|
26 my $sid = $action->query->cookie('sid');
|
74
|
27 my $cookie = $action->query->cookie('cookie');
|
69
|
28
|
68
|
29 if ($action->query->cookie('sign') eq md5_hex(
|
|
30 $this->salt,
|
69
|
31 $sid,
|
74
|
32 $cookie,
|
68
|
33 $this->salt
|
|
34 ) ) {
|
|
35
|
69
|
36 my $context = $action->application->security->Session(
|
73
|
37 id => $sid
|
69
|
38 );
|
|
39
|
74
|
40 my ($result,$challenge) = $context->auth->ValidateSession($cookie);
|
68
|
41
|
69
|
42 if ($result == AUTH_SUCCESS) {
|
|
43 return $context->Impersonate($nextHandler);
|
|
44 } else {
|
|
45 return $nextHandler->();
|
|
46 }
|
68
|
47 }
|
|
48 } else {
|
|
49 die new IMPL::Exception("Unknown auth method",$method);
|
|
50 }
|
|
51 }
|
|
52
|
|
53
|
|
54 1; |