51
+ − 1 package IMPL::Security::Auth::Simple;
71
+ − 2 use strict;
51
+ − 3
81
+ − 4 use base qw(IMPL::Object IMPL::Security::Auth);
51
+ − 5 use Digest::MD5;
52
+ − 6
+ − 7 use IMPL::Class::Property;
81
+ − 8 use IMPL::Security::Auth qw(:Const);
52
+ − 9
81
+ − 10 BEGIN {
52
+ − 11 private property _passwordImage => prop_all;
+ − 12 private property _sessionCookie => prop_all;
+ − 13 }
+ − 14
+ − 15 sub CTOR {
+ − 16 my ($this,$secData) = @_;
+ − 17
87
+ − 18 my ($passImg,$cookie) = split /\|/,$secData;
81
+ − 19
+ − 20 $this->_passwordImage($passImg);
+ − 21 $this->_sessionCookie($cookie);
+ − 22 }
+ − 23
+ − 24 sub secData {
+ − 25 my ($this) = @_;
+ − 26
+ − 27 if ($this->_sessionCookie) {
+ − 28 return join ('|',$this->_passwordImage, $this->_sessionCookie );
+ − 29 } else {
+ − 30 return $this->_passwordImage;
+ − 31 }
+ − 32 }
+ − 33
+ − 34 sub isTrusted {
+ − 35 my ($this) = @_;
+ − 36
+ − 37 $this->_sessionCookie ? 1 : 0;
52
+ − 38 }
51
+ − 39
+ − 40 sub DoAuth {
52
+ − 41 my ($this,$challenge) = @_;
51
+ − 42
52
+ − 43 if (Digest::MD5::md5_hex($challenge) eq $this->_passwordImage) {
72
+ − 44 return (AUTH_SUCCESS,$this->_sessionCookie($this->GenSSID));
51
+ − 45 } elsee {
81
+ − 46 return (AUTH_FAIL,$this->_sessionCookie(undef));
52
+ − 47 }
+ − 48 }
+ − 49
+ − 50 sub ValidateSession {
+ − 51 my ($this,$cookie) = @_;
+ − 52
81
+ − 53 die new IMPL::InvalidOperationException("The context is untrusted") unless $this->_sessionCookie;
+ − 54
52
+ − 55 if ($cookie eq $this->_sessionCookie) {
72
+ − 56 return (AUTH_SUCCESS,undef);
52
+ − 57 } else {
72
+ − 58 return (AUTH_FAIL,undef);
51
+ − 59 }
+ − 60 }
+ − 61
71
+ − 62 sub CreateSecData {
+ − 63 my ($self,%args) = @_;
+ − 64
+ − 65 die new IMPL::InvalidArgumentException("The parameter is required",'password') unless $args{password};
+ − 66
87
+ − 67 return Digest::MD5::md5_hex($args{password});
71
+ − 68 }
+ − 69
+ − 70 sub SecDataArgs {
72
+ − 71 password => 'SCALAR'
71
+ − 72 }
+ − 73
51
+ − 74 1;
+ − 75
+ − 76 __END__
+ − 77
+ − 78 =pod
+ − 79
71
+ − 80 =head1 NAME
+ − 81
+ − 82 C<IMPL::Security::Auth::Simple> ������ ������� �����������.
+ − 83
51
+ − 84 =head1 DESCRIPTION
+ − 85
72
+ − 86 ���������� �������� MD5 ��� �������� ������ ������.
71
+ − 87
72
+ − 88 =head1 MEMBERS
71
+ − 89
72
+ − 90 =over
+ − 91
81
+ − 92 =item C<CTOR($secData)>
+ − 93
+ − 94 ������� ������ ��������������, ��������� ��� ������ ��� �������������.
+ − 95
+ − 96 =item C<[get]secData>
+ − 97
+ − 98 ���������� ������ ������������, ������� ����� ������������ ��� ��������������
+ − 99 ��������� �������.
+ − 100
+ − 101 =item C<[get]isTrusted>
+ − 102
+ − 103 �������� �� ������ ���������� ��� �������������� ������ (������ ������ ������
+ − 104 ��� �������������� ������).
+ − 105
72
+ − 106 =item C<DoAuth($challenge)>
+ − 107
+ − 108 ��������������� ������������. ������������ ���� ����. C<$challenge>
+ − 109 �������� ������ ������������.
+ − 110
+ − 111 ���������� C<($status,$challenge)>
+ − 112
+ − 113 =over
+ − 114
+ − 115 =item C<$status>
+ − 116
+ − 117 ��������� ���� C<AUTH_SUCCESS>, ���� C<AUTH_FAIL>
+ − 118
73
+ − 119 =item C<$challenge>
+ − 120
+ − 121 � ������ ������ ���������� cookie (���������� �����) ������
+ − 122
+ − 123 =back
+ − 124
+ − 125 =item C<ValidateSession($challenge)>
+ − 126
+ − 127 ��������� ������������� ������. ���������� ���� ����. C<$challenge> cookie
+ − 128 ������, ���������� ��� ���������� ������ C<DoAuth>.
+ − 129
+ − 130 ���������� C<($status,$challenge)>
+ − 131
+ − 132 =over
+ − 133
+ − 134 =item C<$status>
+ − 135
+ − 136 ��������� ���� C<AUTH_SUCCESS>, ���� C<AUTH_FAIL>
+ − 137
+ − 138 =item C<$challenge>
+ − 139
+ − 140 ������ C<undef>
72
+ − 141
+ − 142 =back
+ − 143
+ − 144 =back
51
+ − 145
+ − 146 =cut