annotate Lib/IMPL/Web/Security.pm @ 203:68a59c3358ff

Implemented templates selection mechanism
author sergey
date Wed, 25 Apr 2012 18:06:11 +0400
parents 4d0e1962161c
children 6d8092d8ce1b
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;
166
4267a2ac3d46 Added Class::Template,
wizard
parents: 116
diff changeset
3 use parent qw(IMPL::Object IMPL::Security IMPL::Object::Autofill);
73
wizard
parents: 66
diff changeset
4
81
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 79
diff changeset
5 require IMPL::Web::Security::Session;
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 79
diff changeset
6
73
wizard
parents: 66
diff changeset
7 use IMPL::Class::Property;
81
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 79
diff changeset
8 use IMPL::Security::Auth qw(:Const);
73
wizard
parents: 66
diff changeset
9
wizard
parents: 66
diff changeset
10 __PACKAGE__->PassThroughArgs;
wizard
parents: 66
diff changeset
11
wizard
parents: 66
diff changeset
12 BEGIN {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
13 public property sourceUser => prop_all;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
14 public property sourceSession => prop_all;
73
wizard
parents: 66
diff changeset
15 }
wizard
parents: 66
diff changeset
16
107
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
17 sub CTOR {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
18 my ($this) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
19
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
20 die new IMPL::InvalidArgumentException("An argument is required",'sourceUser') unless $this->sourceUser;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
21 die new IMPL::InvalidArgumentException("An argument is required",'sourceSession') unless $this->sourceSession;
107
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
22 }
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
23
81
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 79
diff changeset
24 sub AuthUser {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
25 my ($this,$name,$package,$challenge) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
26
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
27 my $user = $this->sourceUser->find({name => $name}) or return { status => AUTH_FAIL, answer => "Can't find a user '$name'" };
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
28
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
29 my $auth;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
30 if ( my $secData = $user->secData($package) ) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
31 $auth = $package->new($secData);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
32 } else {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
33 die new IMPL::SecurityException("Authentication failed","A sec data for the $package isn't found");
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
34 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
35
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
36 my ($status,$answer) = $auth->DoAuth($challenge);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
37
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
38 return {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
39 status => $status,
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
40 answer => $answer,
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
41 context => $this->MakeContext( $user, [$user->roles], $auth )
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
42 }
73
wizard
parents: 66
diff changeset
43 }
wizard
parents: 66
diff changeset
44
81
077357224bec IMPL::Web::Security alpha version
Sergey
parents: 79
diff changeset
45 sub MakeContext {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
46 my ($this,$principal,$roles,$auth) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
47
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
48 return $this->sourceSession->create(
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
49 {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
50 principal => $principal,
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
51 rolesAssigned => $roles,
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
52 auth => $auth
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
53 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
54 );
73
wizard
parents: 66
diff changeset
55 }
wizard
parents: 66
diff changeset
56
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
57 1;
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
58
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
59 __END__
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
60
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
61 =pod
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
62
73
wizard
parents: 66
diff changeset
63 =head1 NAME
wizard
parents: 66
diff changeset
64
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
65 C<IMPL::Web::Security> Модуль для аутентификации и авторизации веб запроса.
73
wizard
parents: 66
diff changeset
66
wizard
parents: 66
diff changeset
67 =head1 SINOPSYS
wizard
parents: 66
diff changeset
68
wizard
parents: 66
diff changeset
69 =begin code xml
wizard
parents: 66
diff changeset
70
wizard
parents: 66
diff changeset
71 <security type='IMPL::Config::Activator'>
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
72 <factory>IMPL::Web::Security</factory>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
73 <parameters type='HASH'>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
74 <sessionFactory type='IMPL::Object::Factory'>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
75 <factory type='IMPL::Object::Factory'>App::Data::Session</factory>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
76 <method>insert</method>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
77 </sessionFactory>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
78 </parameters>
73
wizard
parents: 66
diff changeset
79 </security>
wizard
parents: 66
diff changeset
80
wizard
parents: 66
diff changeset
81 =end code xml
wizard
parents: 66
diff changeset
82
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
83 =head1 DESCRIPTION
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
84
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
85 Отвечает за инфраструктуру аутентификации и авторизации запросов. Основная особенность
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
86 заключается в том, что запросы приходят через значительные интевалы времени, хотя и
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
87 относятся к одной логической транзакции. В промежутках между запросами сервер не
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
88 сохраняет свое состояние. Поэтому при каждом обращении сервер восстанавливает
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
89 контекст безопасности.
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
90
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
91 C<IMPL::Web::Session> Объект обеспечивающий сохранение состояния в рамках одной сессии
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
92 пользователя. Кроме контекста безопасности хранит дополнительние данные, которые необходимо
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
93 сохранить между обработкой запросов.
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
94
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
95 C<IMPL::Web::User> Объект, устанавливающий связь между идентификатором пользователя
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
96 C<IMPL::Security::Principal>, его ролями и данными безопасности для создания объектов
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
97 аутентификации C<IMPL::Security::Auth>.
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
98
73
wizard
parents: 66
diff changeset
99 =head1 MEMBERS
52
15d720913562 security in work
wizard@linux-odin.local
parents:
diff changeset
100
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
101 =cut