annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
68
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
1 package IMPL::Web::QueryHandler::AuthCookie;
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(
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
35 id => $sid,
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
36 method => 'simple'
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
37 );
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
38
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
39 my ($result,$challenge) = $context->auth->ValidateSession($sid);
68
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
40
69
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
41 if ($result == AUTH_SUCCESS) {
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
42 return $context->Impersonate($nextHandler);
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
43 } else {
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
44 return $nextHandler->();
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
45 }
68
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
46 }
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
47 } else {
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
48 die new IMPL::Exception("Unknown auth method",$method);
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
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
53 1;