annotate Lib/IMPL/Security/Auth/Simple.pm @ 230:6d8092d8ce1b

*reworked IMPL::Security *reworked IMPL::Web::Security *refactoring
author sergey
date Mon, 08 Oct 2012 03:37:37 +0400
parents 4d0e1962161c
children 23daf2fae33a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
51
a1498298d3ee Security in progress
wizard@linux-odin.local
parents:
diff changeset
1 package IMPL::Security::Auth::Simple;
71
wizard
parents: 68
diff changeset
2 use strict;
51
a1498298d3ee Security in progress
wizard@linux-odin.local
parents:
diff changeset
3
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
4 use Digest::MD5 qw(md5_hex);
52
15d720913562 security in work
wizard@linux-odin.local
parents: 51
diff changeset
5
81
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 73
diff changeset
6 use IMPL::Security::Auth qw(:Const);
52
15d720913562 security in work
wizard@linux-odin.local
parents: 51
diff changeset
7
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
8 use IMPL::Const qw(:prop);
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
9 use IMPL::declare {
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
10 require => {
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
11 Exception => 'IMPL::Exception',
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
12 WrongDataException => '-IMPL::WrongDataException'
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
13 },
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
14 base => [
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
15 'IMPL::Security::Auth' => undef,
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
16 'IMPL::Object' => undef
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
17 ],
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
18 props => [
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
19 _stage => PROP_ALL,
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
20 _salt => PROP_ALL,
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
21 _image => PROP_ALL
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
22 ]
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
23 };
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
24
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
25 use constant {
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
26 STAGE_INIT => 1,
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
27 STAGE_DONE => 2
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
28 };
52
15d720913562 security in work
wizard@linux-odin.local
parents: 51
diff changeset
29
15d720913562 security in work
wizard@linux-odin.local
parents: 51
diff changeset
30 sub CTOR {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
31 my ($this,$secData) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
32
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
33 my ($stage,$salt,$img) = split /\|/,$secData;
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
34
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
35 die WrongDataException->new() unless grep $_ == $stage, (STAGE_INIT, STAGE_DONE);
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
36
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
37 $this->_stage($stage);
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
38 $this->_salt($salt);
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
39 $this->_image($img);
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
40
81
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 73
diff changeset
41 }
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 73
diff changeset
42
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 73
diff changeset
43 sub secData {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
44 my ($this) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
45
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
46 return join ('|',$this->_stage, $this->_salt , $this->_image );
81
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 73
diff changeset
47 }
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 73
diff changeset
48
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 73
diff changeset
49 sub isTrusted {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
50 my ($this) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
51
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
52 $this->_stage == STAGE_DONE ? 1 : 0;
52
15d720913562 security in work
wizard@linux-odin.local
parents: 51
diff changeset
53 }
51
a1498298d3ee Security in progress
wizard@linux-odin.local
parents:
diff changeset
54
a1498298d3ee Security in progress
wizard@linux-odin.local
parents:
diff changeset
55 sub DoAuth {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
56 my ($this,$challenge) = @_;
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
57
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
58 my $salt = $this->_salt;
52
15d720913562 security in work
wizard@linux-odin.local
parents: 51
diff changeset
59
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
60 if (md5_hex($salt, $challenge, $salt) eq $this->_image) {
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
61 if ($this->_stage == STAGE_INIT) {
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
62 $this->_stage(STAGE_DONE);
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
63 }
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
64 return (AUTH_SUCCESS, undef);
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
65 } elsee {
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
66 return (AUTH_FAIL, undef);
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
67 }
51
a1498298d3ee Security in progress
wizard@linux-odin.local
parents:
diff changeset
68 }
a1498298d3ee Security in progress
wizard@linux-odin.local
parents:
diff changeset
69
71
wizard
parents: 68
diff changeset
70 sub CreateSecData {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
71 my ($self,%args) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
72
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
73 die new IMPL::InvalidArgumentException("The parameter is required",'password') unless $args{password};
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
74
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
75 my $salt = $self->GenSSID();
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
76 return return join ('|',STAGE_INIT, $salt, md5_hex($salt,$args{password},$salt));
71
wizard
parents: 68
diff changeset
77 }
wizard
parents: 68
diff changeset
78
wizard
parents: 68
diff changeset
79 sub SecDataArgs {
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
80 password => 'SCALAR'
71
wizard
parents: 68
diff changeset
81 }
wizard
parents: 68
diff changeset
82
51
a1498298d3ee Security in progress
wizard@linux-odin.local
parents:
diff changeset
83 1;
a1498298d3ee Security in progress
wizard@linux-odin.local
parents:
diff changeset
84
a1498298d3ee Security in progress
wizard@linux-odin.local
parents:
diff changeset
85 __END__
a1498298d3ee Security in progress
wizard@linux-odin.local
parents:
diff changeset
86
a1498298d3ee Security in progress
wizard@linux-odin.local
parents:
diff changeset
87 =pod
a1498298d3ee Security in progress
wizard@linux-odin.local
parents:
diff changeset
88
71
wizard
parents: 68
diff changeset
89 =head1 NAME
wizard
parents: 68
diff changeset
90
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
91 C<IMPL::Security::Auth::Simple> Модуль простой авторизации.
71
wizard
parents: 68
diff changeset
92
51
a1498298d3ee Security in progress
wizard@linux-odin.local
parents:
diff changeset
93 =head1 DESCRIPTION
a1498298d3ee Security in progress
wizard@linux-odin.local
parents:
diff changeset
94
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
95 Использует алгоритм MD5 для хранения образа пароля.
71
wizard
parents: 68
diff changeset
96
72
wizard
parents: 71
diff changeset
97 =head1 MEMBERS
71
wizard
parents: 68
diff changeset
98
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
99 =head2 C<CTOR($secData)>
81
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 73
diff changeset
100
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
101 Создает объект аутентификации, передавая ему данные для инициализации.
81
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 73
diff changeset
102
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
103 =head2 C<[get]secData>
81
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 73
diff changeset
104
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
105 Возвращает данные безопасности, которые можно использовать для восстановления
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
106 состояния объекта.
81
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 73
diff changeset
107
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
108 =head2 C<[get]isTrusted>
81
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 73
diff changeset
109
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
110 Является ли объект доверенным для аутентификации сессии (тоесть хранит данные
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
111 для аутентификации сессии).
81
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 73
diff changeset
112
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
113 =head2 C<DoAuth($challenge)>
72
wizard
parents: 71
diff changeset
114
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
115 Аутентифицирует пользователя. Используется один этап. C<$challenge>
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
116 открытый пароль пользователя или cookie сессии.
72
wizard
parents: 71
diff changeset
117
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
118 Возвращает C<($status,$challenge)>
72
wizard
parents: 71
diff changeset
119
wizard
parents: 71
diff changeset
120 =over
wizard
parents: 71
diff changeset
121
wizard
parents: 71
diff changeset
122 =item C<$status>
wizard
parents: 71
diff changeset
123
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
124 Результат либо C<AUTH_SUCCESS>, либо C<AUTH_FAIL>
72
wizard
parents: 71
diff changeset
125
73
wizard
parents: 72
diff changeset
126 =item C<$challenge>
wizard
parents: 72
diff changeset
127
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
128 В случае успеха возвращает cookie (уникальный номер) сессии, либо C<undef>
72
wizard
parents: 71
diff changeset
129
wizard
parents: 71
diff changeset
130 =back
51
a1498298d3ee Security in progress
wizard@linux-odin.local
parents:
diff changeset
131
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
132 =cut