annotate Lib/IMPL/Web/QueryHandler/SecureCookie.pm @ 73:2f31ecabe9ea

doc security
author wizard
date Mon, 29 Mar 2010 06:56:05 +0400
parents Lib/IMPL/Web/QueryHandler/AuthCookie.pm@8c7b88bdb663
children 84aa8c395fce
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');
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
27
68
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
28 if ($action->query->cookie('sign') eq md5_hex(
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
29 $this->salt,
69
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
30 $sid,
68
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
31 $this->salt
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
32 ) ) {
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
33
69
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
34 my $context = $action->application->security->Session(
73
wizard
parents: 69
diff changeset
35 id => $sid
69
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
36 );
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
37
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
38 my ($result,$challenge) = $context->auth->ValidateSession($sid);
68
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
39
69
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
40 if ($result == AUTH_SUCCESS) {
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
41 return $context->Impersonate($nextHandler);
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
42 } else {
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
43 return $nextHandler->();
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
44 }
68
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
45 }
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
46 } else {
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
47 die new IMPL::Exception("Unknown auth method",$method);
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
48 }
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
49 }
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 1;