blib/lib/Net/Squid/Auth/Plugin/UserList.pm

filter: Statementstmt 47.8% 11 / 23 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 3 / 6 Podpod 100% 3 / 3 totaltotal 47.2% 17 / 36 CC 4 SCAR 13.0
CC
4
Cov
41%
new
6.0
initialize
6.0
is_valid
3.0
CRAP 3.7
↑ Summary
1 package Net::Squid::Auth::Plugin::UserList;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 Net::Squid::Auth::Plugin::UserList - A User List-Based Credentials Validation Plugin for L<Net::Squid::Auth::Engine>
9  
10 =head1 VERSION
11  
12 Version 0.02
13  
14 =cut
15  
16 2 our $VERSION = 0.02;
17  
18 =head1 SYNOPSIS
19  
20 If you're a system administrator trying to use L<Net::Squid::Auth::Engine> to
21 validate your user's credentials using a user:password list as credentials
22 repository, do as described here:
23  
24 On C<$Config{InstallScript}/squid-auth-engine>'s configuration file:
25  
26 plugin = UserList
27 <UserList>
28 users = <<EOF
29 joe_average:secret
30 john_manager:terces
31 EOF
32 </UserList>
33  
34 On your Squid HTTP Cache configuration:
35  
36 auth_param basic /usr/bin/squid-auth-engine /etc/squid-auth-engine.conf
37  
38 And you're ready to use this module.
39  
40 If you're a developer, you might be interested in reading through the source
41 code of this module, in order to learn about it's internals and how it works.
42 It may give you ideas about how to implement other plugin modules for
43 L<Net::Squid::Auth::Engine>.
44  
45 =head1 FUNCTIONS
46  
47 =head2 new( $config_hash )
48  
49 Constructor. Expects a hash reference with all the configuration under the
50 section I<< <UserList> >> in the C<$Config{InstallScript}/squid-auth-engine> as
51 parameter. Returns a plugin instance.
52  
53 =cut
54  
55 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
56 0 my ( $class, $config ) = @_;
57 0 ▶ return unless UNIVERSAL::isa( $config, 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($config, "HASH") 0 0 0
58 0 return bless { _config => $config }, $class;
59 }
60  
61 =head2 initialize()
62  
63 Initialization function. Gets a user list from the 'users' parameter in the
64 configuration hash passed in to C<new()> and parses it using "\n" as user
65 record split and ":" as user / password separator inside of every record.
66 Returns nothing, as specified by the plugin interface.
67  
68 =cut
69  
70 0 ▶sub initialize {
Subroutine initialize: not called CC=2 SCAR=17.9
Pod documented
71 0 my $self = shift;
72 0 my @users = split "\n", $self->{_config}{users};
73 0 foreach my $record (@users) {
74 0 my ( $username, $password ) = split ':', $record;
75 0 $self->{_usermap}{$username} = $password;
76 }
77 0 return;
78 }
79  
80 =head2 is_valid( $username, $password )
81  
82 This is the credential validation interface. It expects a username and password
83 as parameters and returns a boolean indicating if the credentials are valid
84 (i.e., are listed in the configuration file) or not.
85  
86 =cut
87  
88 0 ▶sub is_valid {
Subroutine is_valid: not called CC=2 SCAR=10.9
Pod documented
89 0 my ( $self, $username, $password ) = @_;
90 0 ▶ return 0 unless exists $self->{_usermap}{$username};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"_usermap"}{$username} 0 0 0
91 2 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
92 0 return $self->{_usermap}{$username} eq $password;
93 }
94  
95 =head1 OTHER IMPLEMENTATIONS
96  
97 =head2 L<Net::Squid::Auth::Plugin::SimpleLDAP>
98  
99 A simple LDAP-based credentials validation plugin for L<Net::Squid::Auth::Engine>.
100  
101 =head1 AUTHOR
102  
103 Luis Motta Campos, C<< <lmc at cpan.org> >>
104  
105 =head1 BUGS
106  
107 Please report any bugs or feature requests to
108 C<bug-net-squid-auth-plugin-userlist at rt.cpan.org>, or through the web
109 interface at
110 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Squid-Auth-Plugin-UserList>.
111 I will be notified, and then you'll automatically be notified of progress on
112 your bug as I make changes.
113  
114 =head1 SUPPORT
115  
116 You can find documentation for this module with the perldoc command.
117  
118 perldoc Net::Squid::Auth::Plugin::UserList
119  
120  
121 You can also look for information at:
122  
123 =over 4
124  
125 =item * RT: CPAN's request tracker
126  
127 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Squid-Auth-Plugin-UserList>
128  
129 =item * AnnoCPAN: Annotated CPAN documentation
130  
131 L<http://annocpan.org/dist/Net-Squid-Auth-Plugin-UserList>
132  
133 =item * CPAN Ratings
134  
135 L<http://cpanratings.perl.org/d/Net-Squid-Auth-Plugin-UserList>
136  
137 =item * Search CPAN
138  
139 L<http://search.cpan.org/dist/Net-Squid-Auth-Plugin-UserList>
140  
141 =back
142  
143  
144 =head1 COPYRIGHT & LICENSE
145  
146 Copyright 2008 Luis Motta Campos, all rights reserved.
147  
148 This program is free software; you can redistribute it and/or modify it
149 under the same terms as Perl itself.
150  
151  
152 =cut
153  
154 2 1; # End of Net::Squid::Auth::Plugin::UserList
↑ Summary