line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTTP::Server::Simple::Authen; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
32154
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
54
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
99
|
|
7
|
1
|
|
|
1
|
|
927
|
use MIME::Base64; |
|
1
|
|
|
|
|
1134
|
|
|
1
|
|
|
|
|
471
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub do_authenticate { |
10
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
11
|
0
|
0
|
0
|
|
|
|
if (($ENV{HTTP_AUTHORIZATION} || '') =~ /^Basic (.*?)$/) { |
12
|
0
|
|
0
|
|
|
|
my($user, $pass) = split /:/, (MIME::Base64::decode($1) || ':'); |
13
|
0
|
0
|
|
|
|
|
if ($self->authen_handler->authenticate($user, $pass)) { |
14
|
0
|
|
|
|
|
|
return $user; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
return; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
0
|
1
|
|
sub authen_realm { "Authorized area" } |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub authen_handler { |
24
|
0
|
|
|
0
|
1
|
|
my $class = ref(shift); |
25
|
0
|
|
|
|
|
|
Carp::croak("You have to override $class\::authen_handler to return Authen::Simple object"); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub authenticate { |
29
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
30
|
0
|
|
|
|
|
|
my $user = $self->do_authenticate(); |
31
|
0
|
0
|
|
|
|
|
unless (defined $user) { |
32
|
0
|
|
|
|
|
|
my $realm = $self->authen_realm(); |
33
|
0
|
|
|
|
|
|
print "HTTP/1.0 401\r\n"; |
34
|
0
|
|
|
|
|
|
print qq(WWW-Authenticate: Basic realm="$realm"\r\n\r\n); |
35
|
0
|
|
|
|
|
|
print "Authentication required."; |
36
|
0
|
|
|
|
|
|
return; |
37
|
|
|
|
|
|
|
} |
38
|
0
|
|
|
|
|
|
return $user; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1; |
42
|
|
|
|
|
|
|
__END__ |