annotate Lib/IMPL/Web/QueryHandler/SecureCookie.pm @ 74:84aa8c395fce

doc minor fixes
author wizard
date Mon, 29 Mar 2010 17:40:06 +0400
parents 2f31ecabe9ea
children 915df8fcd16f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
73
wizard
parents: 69
diff changeset
1 package IMPL::Web::QueryHandler::SecureCookie;
68
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
2
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
3 use base qw(IMPL::Web::QueryHandler);
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
4 use Digest::MD5 qw(md5_hex);
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
5
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
6 use IMPL::Class::Property;
69
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
7 use IMPL::Security::Auth qw(:Const);
68
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
8
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
9 BEGIN {
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
10 public property salt => prop_all;
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
11 }
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
12
69
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
13 sub CTOR {
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
14 my ($this) = @_;
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
15
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
16
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
17 }
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
18
68
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
19 sub Process {
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
20 my ($this,$action,$nextHandler) = @_;
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
21
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
22 my $method = $action->query->cookie('method') || 'simple';
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
23
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
24 if ($method eq 'simple') {
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
25
69
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
26 my $sid = $action->query->cookie('sid');
74
wizard
parents: 73
diff changeset
27 my $cookie = $action->query->cookie('cookie');
69
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
28
68
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
29 if ($action->query->cookie('sign') eq md5_hex(
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
30 $this->salt,
69
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
31 $sid,
74
wizard
parents: 73
diff changeset
32 $cookie,
68
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
33 $this->salt
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
34 ) ) {
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
35
69
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
36 my $context = $action->application->security->Session(
73
wizard
parents: 69
diff changeset
37 id => $sid
69
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
38 );
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
39
74
wizard
parents: 73
diff changeset
40 my ($result,$challenge) = $context->auth->ValidateSession($cookie);
68
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
41
69
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
42 if ($result == AUTH_SUCCESS) {
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
43 return $context->Impersonate($nextHandler);
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
44 } else {
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
45 return $nextHandler->();
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
46 }
68
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
47 }
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
48 } else {
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
49 die new IMPL::Exception("Unknown auth method",$method);
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
50 }
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
51 }
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
52
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
53
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
54 1;