comparison Lib/IMPL/Web/Security.pm @ 239:23daf2fae33a

*security subsytem bugfixes *HttpResponse: cookies which values are set to undefined will be deleted from browser
author sergey
date Tue, 16 Oct 2012 20:14:11 +0400
parents 3cebcf6fdb9b
children 63709a4e6da0
comparison
equal deleted inserted replaced
238:b8c724f6de36 239:23daf2fae33a
11 }; 11 };
12 12
13 use constant { 13 use constant {
14 ERR_NO_SUCH_USER => -1, 14 ERR_NO_SUCH_USER => -1,
15 ERR_NO_SEC_DATA => -2, 15 ERR_NO_SEC_DATA => -2,
16 ERR_AUTH_FAIL => -3 16 ERR_NO_AUTHORITY => -3,
17 ERR_NO_SEC_CONTEXT => -4,
18 ERR_AUTH_FAIL => -5
17 }; 19 };
18 20
19 sub AuthUser { 21 sub AuthUser {
20 my ($this,$name,$package,$challenge) = @_; 22 my ($this,$name,$package,$challenge) = @_;
21 23
22 my $user = $this->FindUserByName($name) 24 my $user = $this->FindUserByName($name)
23 or return { 25 or return {
24 status => AUTH_FAIL, 26 status => AUTH_FAIL,
25 code => ERR_NO_SUCH_USER 27 code => ERR_NO_SUCH_USER
26 }; 28 };
27 29
28 my $auth; 30 my $auth;
29 if ( my $secData = $user->GetSecData($package) ) { 31 if ( my $secData = $user->GetSecData($package) ) {
30 $auth = $package->new($secData); 32 $auth = $package->new($secData);
31 } else { 33 } else {
32 return { 34 return {
34 code => ERR_NO_SEC_DATA, 36 code => ERR_NO_SEC_DATA,
35 user => $user 37 user => $user
36 }; 38 };
37 } 39 }
38 40
41 return {
42 status => AUTH_FAIL,
43 code => ERR_NO_SEC_CONTEXT
44 } unless SecurityContext->current;
45
46 return {
47 status => AUTH_FAIL,
48 code => ERR_NO_AUTHORITY
49 } unless SecurityContext->current->authority;
50
39 my $status = SecurityContext->current->authority->InitSession( 51 my $status = SecurityContext->current->authority->InitSession(
40 $user, 52 $user,
53 [$user->roles],
41 $auth, 54 $auth,
42 [$user->roles] 55 $challenge
43 ); 56 );
44 57
45 return { 58 return {
46 status => $status, 59 status => $status,
47 code => ($status == AUTH_FAIL ? ERR_AUTH_FAIL : 0), 60 code => ($status == AUTH_FAIL ? ERR_AUTH_FAIL : 0),
48 user => $user 61 user => $user
49 }; 62 };
63 }
64
65 sub Logout {
66 my ($this) = @_;
67
68 my $session = SecurityContext->current;
69 if($session && $session->authority) {
70 $session->authority->CloseSession($session);
71
72 $this->CloseSession($session);
73 }
50 } 74 }
51 75
52 sub FindUserByName { 76 sub FindUserByName {
53 die NotImplementedException->new(); 77 die NotImplementedException->new();
54 } 78 }
61 die NotImplementedException->new(); 85 die NotImplementedException->new();
62 } 86 }
63 87
64 sub SaveSession { 88 sub SaveSession {
65 die NotImplementedException->new(); 89 die NotImplementedException->new();
90 }
91
92 sub CloseSession {
93 die NotImplementedException->new();
66 } 94 }
67 95
68 1; 96 1;
69 97
70 __END__ 98 __END__