annotate Lib/Engine/Security/IPSession.pm @ 30:dd4d72600c69

ORM in works
author Sergey
date Tue, 03 Nov 2009 16:31:47 +0300
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::IPSession;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
2 use strict;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
3 use Digest::MD5 qw(md5_hex);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
4
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
5 our %IPMap; # { IP_ADDR => {user => 'name', ClientSecData => 'ClientData', InitSecData => 'ServerData'} }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
6
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
7 sub ReadSecData {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
8
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
9 return $IPMap{$ENV{REMOTE_ADDR} || ''} ? $IPMap{$ENV{REMOTE_ADDR} || ''}->{ClientSecData} : undef; # avoid from create hash item
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
10 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
11
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
12 sub WriteSecData {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
13 my ($class,$data) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
14 # does nothing
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
15 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
16
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
17 sub ReadSSID {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
18 my ($class,$authEngineObj) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
19
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
20 my $ip = $ENV{REMOTE_ADDR};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
21 return undef if not $IPMap{$ip || ''};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
22 my $SSID = md5_hex($ip);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
23
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
24 if (not my $session = $authEngineObj->AuthMod->DS->LoadSession($SSID)) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
25 my $User = $authEngineObj->AuthMod->DS->FindUser($IPMap{$ip}->{user}) or warn "can't authenticate the $ip: user not found" and return undef;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
26 $authEngineObj->AuthMod->DS->CreateSession($SSID,$User,$authEngineObj->AuthMod->SecPackage->NewAuthData($IPMap{$ip}->{InitSecData}));
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
27 } elsif ($session->User->Name ne $IPMap{$ip}->{user}) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
28 # update user
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
29 my $User = $authEngineObj->AuthMod->DS->FindUser($IPMap{$ip}->{user});
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
30 if ($User) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
31 $session->User($User);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
32 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
33 warn "can't authenticate the $ip: user not found";
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
34 $authEngineObj->AuthMod->DS->CloseSession($session);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
35 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
36 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
37
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
38 return $SSID;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
39 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
40
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
41 sub WriteSSID {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
42 my ($class,$data) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
43
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
44 #do nothing
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
45 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
46
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
47
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
48 1;