comparison Lib/IMPL/Web/Security.pm @ 194:4d0e1962161c

Replaced tabs with spaces IMPL::Web::View - fixed document model, new features (control classes, document constructor parameters)
author cin
date Tue, 10 Apr 2012 20:08:29 +0400
parents d1676be8afcc
children 6d8092d8ce1b
comparison
equal deleted inserted replaced
193:8e8401c0aea4 194:4d0e1962161c
8 use IMPL::Security::Auth qw(:Const); 8 use IMPL::Security::Auth qw(:Const);
9 9
10 __PACKAGE__->PassThroughArgs; 10 __PACKAGE__->PassThroughArgs;
11 11
12 BEGIN { 12 BEGIN {
13 public property sourceUser => prop_all; 13 public property sourceUser => prop_all;
14 public property sourceSession => prop_all; 14 public property sourceSession => prop_all;
15 } 15 }
16 16
17 sub CTOR { 17 sub CTOR {
18 my ($this) = @_; 18 my ($this) = @_;
19 19
20 die new IMPL::InvalidArgumentException("An argument is required",'sourceUser') unless $this->sourceUser; 20 die new IMPL::InvalidArgumentException("An argument is required",'sourceUser') unless $this->sourceUser;
21 die new IMPL::InvalidArgumentException("An argument is required",'sourceSession') unless $this->sourceSession; 21 die new IMPL::InvalidArgumentException("An argument is required",'sourceSession') unless $this->sourceSession;
22 } 22 }
23 23
24 sub AuthUser { 24 sub AuthUser {
25 my ($this,$name,$package,$challenge) = @_; 25 my ($this,$name,$package,$challenge) = @_;
26 26
27 my $user = $this->sourceUser->find({name => $name}) or return { status => AUTH_FAIL, answer => "Can't find a user '$name'" }; 27 my $user = $this->sourceUser->find({name => $name}) or return { status => AUTH_FAIL, answer => "Can't find a user '$name'" };
28 28
29 my $auth; 29 my $auth;
30 if ( my $secData = $user->secData($package) ) { 30 if ( my $secData = $user->secData($package) ) {
31 $auth = $package->new($secData); 31 $auth = $package->new($secData);
32 } else { 32 } else {
33 die new IMPL::SecurityException("Authentication failed","A sec data for the $package isn't found"); 33 die new IMPL::SecurityException("Authentication failed","A sec data for the $package isn't found");
34 } 34 }
35 35
36 my ($status,$answer) = $auth->DoAuth($challenge); 36 my ($status,$answer) = $auth->DoAuth($challenge);
37 37
38 return { 38 return {
39 status => $status, 39 status => $status,
40 answer => $answer, 40 answer => $answer,
41 context => $this->MakeContext( $user, [$user->roles], $auth ) 41 context => $this->MakeContext( $user, [$user->roles], $auth )
42 } 42 }
43 } 43 }
44 44
45 sub MakeContext { 45 sub MakeContext {
46 my ($this,$principal,$roles,$auth) = @_; 46 my ($this,$principal,$roles,$auth) = @_;
47 47
48 return $this->sourceSession->create( 48 return $this->sourceSession->create(
49 { 49 {
50 principal => $principal, 50 principal => $principal,
51 rolesAssigned => $roles, 51 rolesAssigned => $roles,
52 auth => $auth 52 auth => $auth
53 } 53 }
54 ); 54 );
55 } 55 }
56 56
57 1; 57 1;
58 58
59 __END__ 59 __END__
67 =head1 SINOPSYS 67 =head1 SINOPSYS
68 68
69 =begin code xml 69 =begin code xml
70 70
71 <security type='IMPL::Config::Activator'> 71 <security type='IMPL::Config::Activator'>
72 <factory>IMPL::Web::Security</factory> 72 <factory>IMPL::Web::Security</factory>
73 <parameters type='HASH'> 73 <parameters type='HASH'>
74 <sessionFactory type='IMPL::Object::Factory'> 74 <sessionFactory type='IMPL::Object::Factory'>
75 <factory type='IMPL::Object::Factory'>App::Data::Session</factory> 75 <factory type='IMPL::Object::Factory'>App::Data::Session</factory>
76 <method>insert</method> 76 <method>insert</method>
77 </sessionFactory> 77 </sessionFactory>
78 </parameters> 78 </parameters>
79 </security> 79 </security>
80 80
81 =end code xml 81 =end code xml
82 82
83 =head1 DESCRIPTION 83 =head1 DESCRIPTION