File Coverage

blib/lib/CGI/Application/Plugin/Authorization/Driver/HTGroup.pm
Criterion Covered Total %
statement 22 22 100.0
branch 4 4 100.0
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 32 32 100.0


line stmt bran cond sub pod time code
1             package CGI::Application::Plugin::Authorization::Driver::HTGroup;
2              
3 2     2   3115 use strict;
  2         5  
  2         88  
4 2     2   80 use warnings;
  2         4  
  2         76  
5              
6 2     2   11 use base qw(CGI::Application::Plugin::Authorization::Driver);
  2         4  
  2         1031  
7 2     2   744 use Apache::Htgroup;
  2         1065  
  2         24  
8              
9              
10             =head1 NAME
11              
12             CGI::Application::Plugin::Authorization::Driver::HTGroup - HTGroup Authorization driver
13              
14              
15             =head1 SYNOPSIS
16              
17             use base qw(CGI::Application);
18             use CGI::Application::Plugin::Authorization;
19              
20             __PACKAGE__->authz->config(
21             DRIVER => [ 'HTGroup', '/etc/apache/myapp/htgroup', '/etc/apache/htgroup' ],
22             );
23              
24              
25             =head1 METHODS
26              
27             =head2 authorize_user
28              
29             This method accepts a username followed by a list of group names and will return
30             true if the user belongs to at least one of the groups.
31              
32             =cut
33              
34             sub authorize_user {
35 6     6 1 26 my $self = shift;
36 6         7 my $username = shift;
37 6         11 my @groups = @_;
38              
39             # verify that all the options are OK
40 6         24 my @files = $self->options;
41 6 100       29 die "The HTGroup driver requires at least one htgroup file" unless @files;
42              
43 5         8 foreach my $file (@files) {
44 8         58 my $htgroup = Apache::Htgroup->load($file); #dies if it can't load the file
45 8         935 foreach my $group (@groups) {
46 11 100       57 return 1 if $htgroup->ismember($username, $group);
47             }
48             }
49 2         32 return 0;
50             }
51              
52              
53             =head1 SEE ALSO
54              
55             L, L, perl(1)
56              
57              
58             =head1 LICENCE AND COPYRIGHT
59              
60             Copyright (c) 2005, SiteSuite. All rights reserved.
61              
62             This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
63              
64              
65             =head1 DISCLAIMER OF WARRANTY
66              
67             BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
68              
69             IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
70              
71             =cut
72              
73             1;