annotate Lib/IMPL/Web/Handler/SecureCookie.pm @ 196:a705e848dcc7

added IMPL::Config::Reference
author cin
date Mon, 16 Apr 2012 17:42:54 +0400
parents
children 6d8092d8ce1b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
196
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
1 package IMPL::Web::QueryHandler::SecureCookie;
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
2 use strict;
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
3
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
4 use parent qw(IMPL::Web::QueryHandler);
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
5 use Digest::MD5 qw(md5_hex);
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
6
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
7 use IMPL::Class::Property;
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
8 use IMPL::Security::Auth qw(:Const);
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
9 use IMPL::Security;
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
10
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
11 BEGIN {
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
12 public property salt => prop_all;
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
13 }
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
14
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
15 sub CTOR {
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
16 my ($this) = @_;
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
17
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
18 $this->salt('DeadBeef') unless $this->salt;
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
19 }
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
20
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
21 sub Process {
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
22 my ($this,$action,$nextHandler) = @_;
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
23
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
24 return undef unless $nextHandler;
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
25
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
26 local $IMPL::Security::authority = $this;
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
27
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
28 my $method = $action->query->cookie('method') || 'simple';
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
29
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
30 if ($method eq 'simple') {
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
31
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
32 my $sid = $action->query->cookie('sid');
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
33 my $cookie = $action->query->cookie('sdata');
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
34 my $sign = $action->query->cookie('sign');
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
35
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
36 if (
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
37 $sid and
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
38 $cookie and
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
39 $sign and
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
40 $sign eq md5_hex(
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
41 $this->salt,
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
42 $sid,
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
43 $cookie,
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
44 $this->salt
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
45 )
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
46 ) {
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
47 # TODO: add a DefferedProxy to deffer a request to a data source
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
48 my $context = $action->application->security->sourceSession->find(
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
49 { id => $sid }
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
50 ) or return $nextHandler->();
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
51
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
52 my ($result,$challenge) = $context->auth->ValidateSession($cookie);
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
53
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
54 if ($result == AUTH_SUCCESS) {
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
55 $context->authority($this);
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
56 return $context->Impersonate($nextHandler);
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
57 } else {
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
58 return $nextHandler->();
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
59 }
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
60 } else {
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
61 return $nextHandler->();
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
62 }
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
63 } else {
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
64 return $nextHandler->();
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
65 }
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
66 }
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
67
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
68 sub WriteResponse {
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
69 my ($this,$response,$sid,$cookie,$method) = @_;
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
70
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
71 my $sign = md5_hex(
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
72 $this->salt,
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
73 $sid,
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
74 $cookie,
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
75 $this->salt
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
76 );
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
77
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
78 $response->setCookie(sid => $sid);
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
79 $response->setCookie(sdata => $cookie);
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
80 $response->setCookie(sign => $sign);
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
81 $response->setCookie(method => $method) if $method;
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
82 }
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
83
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
84 1;
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
85
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
86 __END__
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
87
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
88 =pod
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
89
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
90 =head1 NAME
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
91
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
92 C<IMPL::Web::QueryHandler::SecureCookie>
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
93
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
94 =head1 DESCRIPTION
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
95
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
96 C<use parent qw(IMPL::Web::QueryHandler)>
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
97
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
98 Возобновляет сессию пользователя на основе информации переданной через Cookie.
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
99
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
100 Использует механизм подписи информации для проверки верности входных данных перед
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
101 началом каких-либо действий.
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
102
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
103 Данный обработчик возвращает результат выполнения следдующего обработчика.
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
104
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
105 =head1 MEMBERS
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
106
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
107 =over
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
108
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
109 =item C<[get,set] salt>
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
110
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
111 Скаляр, использующийся для подписи данных.
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
112
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
113 =back
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
114
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
115 =cut