annotate Lib/IMPL/Web/QueryHandler/SecureCookie.pm @ 95:67eb8eaec3d4

Added a security authority property to the Context and Security classes Added a WriteResponse method to the SecureCookie class Added a setCookie method to the Response class
author wizard
date Thu, 29 Apr 2010 02:21:27 +0400
parents 3d1f584aea60
children 964587c5183c
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;
95
67eb8eaec3d4 Added a security authority property to the Context and Security classes
wizard
parents: 89
diff changeset
2 use strict;
68
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
3
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
4 use base qw(IMPL::Web::QueryHandler);
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
5 use Digest::MD5 qw(md5_hex);
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
6
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
7 use IMPL::Class::Property;
69
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
8 use IMPL::Security::Auth qw(:Const);
95
67eb8eaec3d4 Added a security authority property to the Context and Security classes
wizard
parents: 89
diff changeset
9 use IMPL::Security;
68
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
10
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
11 BEGIN {
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
12 public property salt => prop_all;
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
13 }
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
14
69
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
15 sub CTOR {
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
16 my ($this) = @_;
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
17
75
wizard
parents: 74
diff changeset
18 $this->salt('DeadBeef') unless $this->salt;
69
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
19 }
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
20
68
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
21 sub Process {
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
22 my ($this,$action,$nextHandler) = @_;
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
23
75
wizard
parents: 74
diff changeset
24 return undef unless $nextHandler;
wizard
parents: 74
diff changeset
25
68
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
26 my $method = $action->query->cookie('method') || 'simple';
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
27
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
28 if ($method eq 'simple') {
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
29
69
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
30 my $sid = $action->query->cookie('sid');
75
wizard
parents: 74
diff changeset
31 my $cookie = $action->query->cookie('sdata');
wizard
parents: 74
diff changeset
32 my $sign = $action->query->cookie('sign');
69
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
33
75
wizard
parents: 74
diff changeset
34 if (
wizard
parents: 74
diff changeset
35 $sid and
wizard
parents: 74
diff changeset
36 $cookie and
wizard
parents: 74
diff changeset
37 $sign and
wizard
parents: 74
diff changeset
38 $sign eq md5_hex(
wizard
parents: 74
diff changeset
39 $this->salt,
wizard
parents: 74
diff changeset
40 $sid,
wizard
parents: 74
diff changeset
41 $cookie,
wizard
parents: 74
diff changeset
42 $this->salt
wizard
parents: 74
diff changeset
43 )
wizard
parents: 74
diff changeset
44 ) {
95
67eb8eaec3d4 Added a security authority property to the Context and Security classes
wizard
parents: 89
diff changeset
45 local $IMPL::Security::authority = $this;
68
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
46
89
3d1f584aea60 small fix in the activator and secure cookie
wizard
parents: 75
diff changeset
47 my $context = $action->application->security->sourceSession->find(
3d1f584aea60 small fix in the activator and secure cookie
wizard
parents: 75
diff changeset
48 { id => $sid }
3d1f584aea60 small fix in the activator and secure cookie
wizard
parents: 75
diff changeset
49 ) or return $nextHandler->();
69
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
50
74
wizard
parents: 73
diff changeset
51 my ($result,$challenge) = $context->auth->ValidateSession($cookie);
68
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
52
69
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
53 if ($result == AUTH_SUCCESS) {
95
67eb8eaec3d4 Added a security authority property to the Context and Security classes
wizard
parents: 89
diff changeset
54 $context->authority($this);
69
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
55 return $context->Impersonate($nextHandler);
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
56 } else {
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
57 return $nextHandler->();
8c7b88bdb663 Cookie Simple auth support
wizard
parents: 68
diff changeset
58 }
68
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
59 }
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
60 } else {
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
61 die new IMPL::Exception("Unknown auth method",$method);
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
62 }
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
63 }
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
64
95
67eb8eaec3d4 Added a security authority property to the Context and Security classes
wizard
parents: 89
diff changeset
65 sub WriteResponse {
67eb8eaec3d4 Added a security authority property to the Context and Security classes
wizard
parents: 89
diff changeset
66 my ($this,$response,$sid,$cookie,$method) = @_;
67eb8eaec3d4 Added a security authority property to the Context and Security classes
wizard
parents: 89
diff changeset
67
67eb8eaec3d4 Added a security authority property to the Context and Security classes
wizard
parents: 89
diff changeset
68 my $sign = md5_hex(
67eb8eaec3d4 Added a security authority property to the Context and Security classes
wizard
parents: 89
diff changeset
69 $this->salt,
67eb8eaec3d4 Added a security authority property to the Context and Security classes
wizard
parents: 89
diff changeset
70 $sid,
67eb8eaec3d4 Added a security authority property to the Context and Security classes
wizard
parents: 89
diff changeset
71 $cookie,
67eb8eaec3d4 Added a security authority property to the Context and Security classes
wizard
parents: 89
diff changeset
72 $this->salt
67eb8eaec3d4 Added a security authority property to the Context and Security classes
wizard
parents: 89
diff changeset
73 );
67eb8eaec3d4 Added a security authority property to the Context and Security classes
wizard
parents: 89
diff changeset
74
67eb8eaec3d4 Added a security authority property to the Context and Security classes
wizard
parents: 89
diff changeset
75 $this->setCookie(sid => $sid);
67eb8eaec3d4 Added a security authority property to the Context and Security classes
wizard
parents: 89
diff changeset
76 $this->setCookie(sdata => $cookie);
67eb8eaec3d4 Added a security authority property to the Context and Security classes
wizard
parents: 89
diff changeset
77 $this->setCookie(sign => $sign);
67eb8eaec3d4 Added a security authority property to the Context and Security classes
wizard
parents: 89
diff changeset
78 $this->setCookie(method => $method) if $method;
67eb8eaec3d4 Added a security authority property to the Context and Security classes
wizard
parents: 89
diff changeset
79 }
67eb8eaec3d4 Added a security authority property to the Context and Security classes
wizard
parents: 89
diff changeset
80
75
wizard
parents: 74
diff changeset
81 1;
68
739f1288ca84 Auth in progress
wizard
parents:
diff changeset
82
75
wizard
parents: 74
diff changeset
83 __END__
wizard
parents: 74
diff changeset
84
wizard
parents: 74
diff changeset
85 =pod
wizard
parents: 74
diff changeset
86
wizard
parents: 74
diff changeset
87 =head1 NAME
wizard
parents: 74
diff changeset
88
wizard
parents: 74
diff changeset
89 C<IMPL::Web::QueryHandler::SecureCookie>
wizard
parents: 74
diff changeset
90
wizard
parents: 74
diff changeset
91 =head1 DESCRIPTION
wizard
parents: 74
diff changeset
92
wizard
parents: 74
diff changeset
93 C<use base qw(IMPL::Web::QueryHandler)>
wizard
parents: 74
diff changeset
94
wizard
parents: 74
diff changeset
95 Возобновляет сессию пользователя на основе информации переданной через Cookie.
wizard
parents: 74
diff changeset
96
wizard
parents: 74
diff changeset
97 Использует механизм подписи информации для проверки верности входных данных перед
wizard
parents: 74
diff changeset
98 началом каких-либо действий.
wizard
parents: 74
diff changeset
99
wizard
parents: 74
diff changeset
100 Данный обработчик возвращает результат выполнения следдующего обработчика.
wizard
parents: 74
diff changeset
101
wizard
parents: 74
diff changeset
102 =head1 MEMBERS
wizard
parents: 74
diff changeset
103
wizard
parents: 74
diff changeset
104 =over
wizard
parents: 74
diff changeset
105
wizard
parents: 74
diff changeset
106 =item C<[get,set] salt>
wizard
parents: 74
diff changeset
107
wizard
parents: 74
diff changeset
108 Скаляр, использующийся для подписи данных.
wizard
parents: 74
diff changeset
109
wizard
parents: 74
diff changeset
110 =back
wizard
parents: 74
diff changeset
111
wizard
parents: 74
diff changeset
112 =cut