File Coverage

blib/lib/CGI/Application/Plugin/Authorization/Driver/Generic.pm
Criterion Covered Total %
statement 17 17 100.0
branch 4 4 100.0
condition 3 3 100.0
subroutine 4 4 100.0
pod 1 1 100.0
total 29 29 100.0


line stmt bran cond sub pod time code
1             package CGI::Application::Plugin::Authorization::Driver::Generic;
2              
3 5     5   3171 use strict;
  5         9  
  5         202  
4 5     5   28 use warnings;
  5         8  
  5         171  
5              
6 5     5   28 use base qw(CGI::Application::Plugin::Authorization::Driver);
  5         10  
  5         3145  
7              
8              
9             =head1 NAME
10              
11             CGI::Application::Plugin::Authorization::Driver::Generic - Generic Authorization driver
12              
13              
14             =head1 SYNOPSIS
15              
16             use base qw(CGI::Application);
17             use CGI::Application::Plugin::Authorization;
18              
19             my %groupmap = (
20             testuser => 'testgroup',
21             );
22              
23             # See docs for authorize_user below for an explanation
24             __PACKAGE__->authz->config(
25             DRIVER => [ 'Generic', sub {
26             my ($username,$group) = @_;
27             return ($groupmap{$username} eq $group);
28             } ],
29             );
30              
31              
32             =head1 METHODS
33              
34             =head2 authorize_user
35              
36             This method accepts a username followed by a list of group names and will
37             return true if the user belongs to at least one of the groups.
38              
39             It does this by calling the provided callback with the username and a
40             single group until a match is found.
41              
42             =cut
43              
44             sub authorize_user {
45 25     25 1 65 my $self = shift;
46 25         32 my $username = shift;
47 25         45 my @groups = @_;
48              
49             # verify that all the options are OK
50 25         118 my ($check) = $self->options;
51 25 100 100     155 die "The Generic driver requires a subroutine reference as its only option" unless $check && ref $check eq 'CODE';
52              
53 23         37 foreach my $group (@groups) {
54 25 100       73 return 1 if $check->($username, $group);
55             }
56 15         171 return 0;
57             }
58              
59              
60             =head1 SEE ALSO
61              
62             L, L, perl(1)
63              
64              
65             =head1 LICENCE AND COPYRIGHT
66              
67             Copyright (c) 2005, SiteSuite. All rights reserved.
68              
69             This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
70              
71              
72             =head1 DISCLAIMER OF WARRANTY
73              
74             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.
75              
76             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.
77              
78             =cut
79              
80             1;