Mercurial > pub > Impl
comparison Lib/IMPL/Security/Auth/Simple.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 |
---|---|
5 use Digest::MD5; | 5 use Digest::MD5; |
6 | 6 |
7 use IMPL::Class::Property; | 7 use IMPL::Class::Property; |
8 use IMPL::Security::Auth qw(:Const); | 8 use IMPL::Security::Auth qw(:Const); |
9 | 9 |
10 BEGIN { | 10 BEGIN { |
11 private property _passwordImage => prop_all; | 11 private property _passwordImage => prop_all; |
12 private property _sessionCookie => prop_all; | 12 private property _sessionCookie => prop_all; |
13 } | 13 } |
14 | 14 |
15 sub CTOR { | 15 sub CTOR { |
16 my ($this,$secData) = @_; | 16 my ($this,$secData) = @_; |
17 | 17 |
18 my ($passImg,$cookie) = split /\|/,$secData; | 18 my ($passImg,$cookie) = split /\|/,$secData; |
19 | 19 |
20 $this->_passwordImage($passImg); | 20 $this->_passwordImage($passImg); |
21 $this->_sessionCookie($cookie); | 21 $this->_sessionCookie($cookie); |
22 } | 22 } |
23 | 23 |
24 sub secData { | 24 sub secData { |
25 my ($this) = @_; | 25 my ($this) = @_; |
26 | 26 |
27 if ($this->_sessionCookie) { | 27 if ($this->_sessionCookie) { |
28 return join ('|',$this->_passwordImage, $this->_sessionCookie ); | 28 return join ('|',$this->_passwordImage, $this->_sessionCookie ); |
29 } else { | 29 } else { |
30 return $this->_passwordImage; | 30 return $this->_passwordImage; |
31 } | 31 } |
32 } | 32 } |
33 | 33 |
34 sub isTrusted { | 34 sub isTrusted { |
35 my ($this) = @_; | 35 my ($this) = @_; |
36 | 36 |
37 $this->_sessionCookie ? 1 : 0; | 37 $this->_sessionCookie ? 1 : 0; |
38 } | 38 } |
39 | 39 |
40 sub DoAuth { | 40 sub DoAuth { |
41 my ($this,$challenge) = @_; | 41 my ($this,$challenge) = @_; |
42 | 42 |
43 if (Digest::MD5::md5_hex($challenge) eq $this->_passwordImage) { | 43 if (Digest::MD5::md5_hex($challenge) eq $this->_passwordImage) { |
44 return (AUTH_SUCCESS,$this->_sessionCookie($this->GenSSID)); | 44 return (AUTH_SUCCESS,$this->_sessionCookie($this->GenSSID)); |
45 } elsee { | 45 } elsee { |
46 return (AUTH_FAIL,$this->_sessionCookie(undef)); | 46 return (AUTH_FAIL,$this->_sessionCookie(undef)); |
47 } | 47 } |
48 } | 48 } |
49 | 49 |
50 sub ValidateSession { | 50 sub ValidateSession { |
51 my ($this,$cookie) = @_; | 51 my ($this,$cookie) = @_; |
52 | 52 |
53 die new IMPL::InvalidOperationException("The context is untrusted") unless $this->_sessionCookie; | 53 die new IMPL::InvalidOperationException("The context is untrusted") unless $this->_sessionCookie; |
54 | 54 |
55 if ($cookie eq $this->_sessionCookie) { | 55 if ($cookie eq $this->_sessionCookie) { |
56 return (AUTH_SUCCESS,undef); | 56 return (AUTH_SUCCESS,undef); |
57 } else { | 57 } else { |
58 return (AUTH_FAIL,undef); | 58 return (AUTH_FAIL,undef); |
59 } | 59 } |
60 } | 60 } |
61 | 61 |
62 sub CreateSecData { | 62 sub CreateSecData { |
63 my ($self,%args) = @_; | 63 my ($self,%args) = @_; |
64 | 64 |
65 die new IMPL::InvalidArgumentException("The parameter is required",'password') unless $args{password}; | 65 die new IMPL::InvalidArgumentException("The parameter is required",'password') unless $args{password}; |
66 | 66 |
67 return Digest::MD5::md5_hex($args{password}); | 67 return Digest::MD5::md5_hex($args{password}); |
68 } | 68 } |
69 | 69 |
70 sub SecDataArgs { | 70 sub SecDataArgs { |
71 password => 'SCALAR' | 71 password => 'SCALAR' |
72 } | 72 } |
73 | 73 |
74 1; | 74 1; |
75 | 75 |
76 __END__ | 76 __END__ |