File Coverage

blib/lib/PlugAuth/Client/Tiny/Apache2AuthzHandler.pm
Criterion Covered Total %
statement 15 17 88.2
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 21 23 91.3


line stmt bran cond sub pod time code
1             package PlugAuth::Client::Tiny::Apache2AuthzHandler;
2              
3 2     2   1779 use strict;
  2         4  
  2         62  
4 2     2   12 use warnings;
  2         5  
  2         67  
5 2     2   52 use 5.012;
  2         6  
6 2     2   372 use PlugAuth::Client::Tiny;
  1         2  
  1         87  
7 1     1   7 use Apache2::Access ();
  1         2  
  1         21  
8 1     1   425 use Apache2::RequestRec ();
  0            
  0            
9             use Apache2::RequestUtil ();
10             use Apache2::Const -compile => qw(OK HTTP_UNAUTHORIZED);
11              
12             # ABSTRACT: Apache authorization handler for PlugAuth
13             our $VERSION = '0.01'; # VERSION
14              
15              
16             sub handler
17             {
18             my($r) = @_;
19            
20             my $auth = PlugAuth::Client::Tiny->new(url => $ENV{PLUGAUTH_URL});
21             my $prefix = $ENV{PLUGAUTH_PREFIX} // '';
22            
23             my $user = $r->user;
24             if($user && $auth->authz($user, $r->method, $prefix . $r->uri))
25             {
26             return Apache2::Const::OK;
27             }
28             else
29             {
30             $r->note_basic_auth_failure;
31             return Apache2::Const::HTTP_UNAUTHORIZED;
32             }
33             }
34              
35             1;
36              
37             __END__