annotate Lib/Engine/Security/Auth.pm @ 11:75980091813b

DOM и навигация
author Sergey
date Wed, 02 Sep 2009 17:47:44 +0400
parents 03e58a454b20
children 16ada169ca75
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
1 package Engine::Security::Auth;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
2 use strict;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
3 use Common;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
4 our @ISA = qw(Object);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
5 use Security;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
6 use Security::Auth;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
7 use Engine::Security::AccessDeniedException;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
8
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
9 BEGIN {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
10 DeclareProperty ClientSecData => ACCESS_READ;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
11 DeclareProperty SecPackage => ACCESS_READ;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
12 DeclareProperty DataSource => ACCESS_READ;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
13 DeclareProperty DefaultUser => ACCESS_READ;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
14 DeclareProperty _AuthMod => ACCESS_NONE; # construct on demand
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
15 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
16
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
17 sub CTOR {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
18 my $this = shift;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
19 $this->SUPER::CTOR(@_);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
20 eval "require $this->{$ClientSecData};" or warn $@;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
21 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
22
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
23 sub DoAuth {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
24 my ($this) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
25
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
26 my $data = $this->{$ClientSecData}->ReadSecData($this);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
27 my $SSID = $this->{$ClientSecData}->ReadSSID($this);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
28
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
29 my $AuthResult;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
30
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
31 if ($SSID) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
32 $AuthResult = $this->AuthMod->AuthenticateSession($SSID,$data);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
33 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
34 $AuthResult = new Security::AuthResult(State => Security::AUTH_NOAUTH);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
35 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
36
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
37 if ($AuthResult->State == Security::AUTH_SUCCESS) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
38 #warn "Session authenticated: ".$AuthResult->Session->User->Name;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
39 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
40 #warn "Session is not authenticated: ".$AuthResult->State;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
41 if ($this->{$DefaultUser}) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
42 $AuthResult = $this->AuthMod->AuthenticateUser($this->{$DefaultUser},undef);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
43 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
44 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
45
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
46 return $AuthResult;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
47 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
48
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
49 sub SetAuthResult {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
50 my ($this,$AuthResult) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
51
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
52 if ($AuthResult and $AuthResult->State == Security::AUTH_SUCCESS) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
53 $this->_CurrentSession($AuthResult->Session);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
54 $this->{$ClientSecData}->WriteSecData($AuthResult->ClientSecData,$this);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
55 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
56 $this->_CurrentSession(undef);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
57 $this->{$ClientSecData}->WriteSecData(undef,$this);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
58 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
59 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
60
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
61 sub _CurrentSession {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
62 my ($this,$Session) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
63
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
64 if (@_ >= 2) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
65 $this->AuthMod->DS->CloseSession(Security->CurrentSession) if Security->CurrentSession;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
66
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
67 $this->{$ClientSecData}->WriteSSID($Session ? $Session->SSID : undef);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
68 Security->CurrentSession($Session);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
69 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
70 return Security->CurrentSession;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
71 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
72 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
73
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
74 sub AuthMod {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
75 my ($this) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
76 if (not $this->{$_AuthMod}) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
77 if ($this->{$DataSource} and $this->{$SecPackage}) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
78 eval qq {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
79 require $this->{$DataSource};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
80 require $this->{$SecPackage};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
81 } or warn $@;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
82 $this->{$_AuthMod} = Security::Auth->new(
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
83 DS => $this->{$DataSource},
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
84 SecPackage => $this->{$SecPackage}
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
85 );
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
86 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
87 #construct default
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
88 $this->{$_AuthMod} = Security::Auth->construct;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
89 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
90 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
91 return $this->{$_AuthMod};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
92 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
93
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
94 1;