Mercurial > pub > Impl
comparison Lib/IMPL/Web/Security.pm @ 81:077357224bec
IMPL::Web::Security alpha version
IMPL::Security improovements
author | Sergey |
---|---|
date | Wed, 07 Apr 2010 14:45:34 +0400 |
parents | 2d1c3f713280 |
children | 74bae30eb25e |
comparison
equal
deleted
inserted
replaced
80:f017c0d7527c | 81:077357224bec |
---|---|
1 package IMPL::Web::Security; | 1 package IMPL::Web::Security; |
2 | 2 use strict; |
3 use base qw(IMPL::Object IMPL::Security IMPL::Object::Autofill); | 3 use base qw(IMPL::Object IMPL::Security IMPL::Object::Autofill); |
4 | 4 |
5 require IMPL::Web::Security::Session; | |
6 | |
5 use IMPL::Class::Property; | 7 use IMPL::Class::Property; |
8 use IMPL::Security::Auth qw(:Const); | |
6 | 9 |
7 __PACKAGE__->PassThroughArgs; | 10 __PACKAGE__->PassThroughArgs; |
8 | 11 |
9 BEGIN { | 12 BEGIN { |
10 public property source => prop_all; | 13 public property sourceUser => prop_all; |
14 public property sourceSession => prop_all; | |
11 } | 15 } |
12 | 16 |
13 sub CTOR { | 17 sub AuthUser { |
14 my ($this) = @_; | 18 my ($this,$name,$package,$challenge) = @_; |
15 | 19 |
16 $this->dataSource or die new IMPL::InvalidArgumentException("The argument is required",'dataSource'); | 20 my $user = $this->sourceUser->search({name => $name}); |
21 | |
22 my $auth; | |
23 if ( my $secData = $user->secData($package) ) { | |
24 $auth = $package->new($secData); | |
25 } else { | |
26 die new IMPL::SecurityException("Authentication failed","A sec data for the $package isn't found"); | |
27 } | |
28 | |
29 my ($status,$answer) = $auth->DoAuth($challenge); | |
30 | |
31 if ($status == AUTH_FAIL) { | |
32 die new IMPL::SecurityException("Authentication failed","DoAuth failed"); | |
33 } | |
34 | |
35 return { | |
36 status => $status, | |
37 answer => $answer, | |
38 context => $this->MakeContext( $user, $user->roles, $auth ) | |
39 } | |
17 } | 40 } |
18 | 41 |
19 sub RetrSession { | 42 sub MakeContext { |
20 my ($this,$sid) = @_; | 43 my ($this,$principal,$roles,$auth) = @_; |
21 | 44 |
22 return $this->source->RetrSession(id => $sid); | 45 return $this->sourceSession->insert( |
23 } | 46 { |
24 | 47 principal => $principal, |
25 sub RetrSecData { | 48 rolesAssigned => $roles, |
26 my ($this,$user,$secPackage) = @_; | 49 auth => $auth |
27 | 50 } |
28 $user = ref $user ? $user->name : $user; | 51 ); |
29 | |
30 return | |
31 $this->source->RetrSecData(user => $user, package => $secPackage); | |
32 } | 52 } |
33 | 53 |
34 1; | 54 1; |
35 | 55 |
36 __END__ | 56 __END__ |