annotate Lib/IMPL/Web/Security.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 ff1e8fa932f2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
1 package IMPL::Web::Security;
81
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 79
diff changeset
2 use strict;
73
wizard
parents: 66
diff changeset
3
81
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 79
diff changeset
4 use IMPL::Security::Auth qw(:Const);
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
5 use IMPL::declare {
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
6 require => {
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
7 Exception => 'IMPL::Exception',
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
8 NotImplementedException => '-IMPL::NotImplementedException',
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
9 SecurityContext => 'IMPL::Security::AbstractContext'
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
10 },
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
11 };
107
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
12
81
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 79
diff changeset
13 sub AuthUser {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
14 my ($this,$name,$package,$challenge) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
15
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
16 my $user = $this->FindUserByName($name)
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
17 or return { status => AUTH_FAIL, answer => "Can't find a user '$name'" };
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
18
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
19 my $auth;
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
20 if ( my $secData = $user->GetSecData($package) ) {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
21 $auth = $package->new($secData);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
22 } else {
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
23 return {
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
24 status => AUTH_FAIL,
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
25 user => $user
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
26 };
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
27 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
28
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
29 my ($status,$answer) = $auth->DoAuth($challenge);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
30
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
31 if ($status != AUTH_FAIL) {
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
32 SecurityContext->current->authority->CreateContext(
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
33 $user,
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
34 $auth,
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
35 [$user->roles],
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
36 $answer,
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
37 $this
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
38 );
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
39 }
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
40
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
41 return {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
42 status => $status,
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
43 user => $user
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
44 };
73
wizard
parents: 66
diff changeset
45 }
wizard
parents: 66
diff changeset
46
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
47 sub FindUserByName {
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
48 die NotImplementedException->new();
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
49 }
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
50
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
51 sub CreateSession {
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
52 die NotImplementedException->new();
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
53 }
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
54
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
55 sub GetSession {
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
56 die NotImplementedException->new();
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
57 }
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
58
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
59 sub SaveSession {
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
60 die NotImplementedException->new();
73
wizard
parents: 66
diff changeset
61 }
wizard
parents: 66
diff changeset
62
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
63 1;
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
64
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
65 __END__
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
66
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
67 =pod
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
68
73
wizard
parents: 66
diff changeset
69 =head1 NAME
wizard
parents: 66
diff changeset
70
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
71 C<IMPL::Web::Security> Модуль для аутентификации и авторизации веб запроса.
73
wizard
parents: 66
diff changeset
72
wizard
parents: 66
diff changeset
73 =head1 SINOPSYS
wizard
parents: 66
diff changeset
74
wizard
parents: 66
diff changeset
75 =begin code xml
wizard
parents: 66
diff changeset
76
wizard
parents: 66
diff changeset
77 <security type='IMPL::Config::Activator'>
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
78 <factory>IMPL::Web::Security</factory>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
79 <parameters type='HASH'>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
80 <sessionFactory type='IMPL::Object::Factory'>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
81 <factory type='IMPL::Object::Factory'>App::Data::Session</factory>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
82 <method>insert</method>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
83 </sessionFactory>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
84 </parameters>
73
wizard
parents: 66
diff changeset
85 </security>
wizard
parents: 66
diff changeset
86
wizard
parents: 66
diff changeset
87 =end code xml
wizard
parents: 66
diff changeset
88
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
89 =head1 DESCRIPTION
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
90
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
91 Отвечает за инфраструктуру аутентификации и авторизации запросов. Основная особенность
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
92 заключается в том, что запросы приходят через значительные интевалы времени, хотя и
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
93 относятся к одной логической транзакции. В промежутках между запросами сервер не
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
94 сохраняет свое состояние. Поэтому при каждом обращении сервер восстанавливает
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
95 контекст безопасности.
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
96
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
97 C<IMPL::Web::Security::Session> Объект обеспечивающий сохранение состояния в рамках одной сессии
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
98 пользователя. Кроме контекста безопасности хранит дополнительние данные, которые необходимо
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
99 сохранить между обработкой запросов.
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
100
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
101 C<IMPL::Web::Security::User> Объект, устанавливающий связь между идентификатором пользователя
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
102 C<IMPL::Security::Principal>, его ролями и данными безопасности для создания объектов
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
103 аутентификации C<IMPL::Security::Auth>.
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
104
73
wizard
parents: 66
diff changeset
105 =head1 MEMBERS
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
106
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
107 =cut