Apache/OpenInteract2/HttpAuth.pm untested

filter: Statementstmt 0.0% 0 / 46 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 93 CC 6 SCAR 31.7
CC
6
Cov
0%
handler
42.0
BEGIN
2.0
BEGIN
2.0
CRAP 23.8
1 package Apache::OpenInteract2::HttpAuth;
2  
3 # $Id: HttpAuth.pm,v 1.12 2005/03/18 04:09:48 lachoy Exp $
4  
5 use strict;
6 use Apache::Constants qw( FORBIDDEN AUTH_REQUIRED OK );
7 use Log::Log4perl qw( get_logger );
8 use OpenInteract2::Constants qw( :log );
9 use OpenInteract2::Context qw( CTX );
10  
11 $Apache::OpenInteract2::HttpAuth::VERSION = sprintf("%d.%02d", q$Revision: 1.12 $ =~ /(\d+)\.(\d+)/);
12  
13 my ( $log );
14  
15 sub handler {
16 my ( $r ) = @_;
17 $log ||= get_logger( LOG_AUTH );
18  
19 unless ( $r->some_auth_required ) {
20 $log->warn( "Asked to process authentication request ",
21 "but no authentication configured" );
22 $r->log_reason( "No authentication has been configured" );
23 return FORBIDDEN;
24 }
25  
26 my ( $res, $password_sent ) = $r->get_basic_auth_pw;
27  
28 # e.g., HTTP_UNAUTHORIZED
29 if ( $res ) {
30 $log->is_debug && $log->debug( "Got result '$res' from auth" );
31 return $res;
32 }
33  
34 my $user_sent = $r->connection->user;
35 $log->is_debug && $log->debug( "Trying to authenticate '$user_sent'" );
36 unless ( $user_sent ) {
37 return AUTH_REQUIRED;
38 }
39  
40 my $user = CTX->lookup_object( 'user' )
41 ->fetch_by_login_name( $user_sent, { skip_security => 1 } );
42 unless ( $user ) {
43 my $msg = "User '$user_sent' is not an OpenInteract user.";
44 $log->is_info && $log->info( $msg );
45 $r->log_reason( $msg );
46 return AUTH_REQUIRED;
47 }
48 unless ( $user->check_password( $password_sent ) ) {
49 my $msg = "User '$user_sent' found but password does not match";
50 $log->is_info && $log->info( $msg );
51 $r->log_reason( $msg );
52 return AUTH_REQUIRED;
53 }
54 $log->is_debug && $log->debug( "User '$user_sent' auth ok" );
55 $r->pnotes( 'login_user', $user );
56 return OK;
57 }
58  
59 1;
60  
61 __END__