blib/lib/CGI/Application/Plugin/Authentication/Driver/Generic.pm

filter: Statementstmt 100% 23 / 23 Branchbran 100% 14 / 14 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 100% 52 / 52 CC 11 SCAR 21.8
CC
11
Cov
100%
verify_credentials
11.0
BEGIN
1.0
BEGIN
1.0
CRAP 8.9
« blib/lib/CGI/Application/Plugin/Authentication/Display/Classic.pm ↑ Summary blib/lib/CGI/Application/Plugin/Authentication/Driver/Filter/md5.pm »
1 package CGI::Application::Plugin::Authentication::Driver::Generic;
2  
3 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 14 ▶use base qw(CGI::Application::Plugin::Authentication::Driver);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 CGI::Application::Plugin::Authentication::Driver::Generic - Generic Authentication driver
11  
12  
13 =head1 SYNOPSIS
14  
15 use base qw(CGI::Application);
16 use CGI::Application::Plugin::Authentication;
17  
18 __PACKAGE__->authen->config(
19 DRIVER => [ 'Generic', { user1 => '123', user2 => '123' } ],
20 );
21  
22 =head1 DESCRIPTION
23  
24 This Driver offers a simple way to provide a user database to the
25 L<CGI::Application::Plugin::Authentication> plugin. It offers three ways
26 to provide a list of users to the plugin by providing a hash of username/password pairs,
27 an array of arrays containing the username and password pairs, or a code
28 reference that returns back the username, or undef on success or failure.
29  
30 =head1 EXAMPLE
31  
32 my %users = (
33 user1 => '123',
34 user2 => '123',
35 );
36 __PACKAGE__->authen->config(
37 DRIVER => [ 'Generic', \%users ],
38 );
39  
40 - or -
41  
42 my @users = (
43 ['example.com', 'user1', '123'],
44 ['example.com', 'user2', '123'],
45 ['foobar.com', 'user1', '123'],
46 );
47 __PACKAGE__->authen->config(
48 DRIVER => [ 'Generic', \@users ],
49 CREDENTIALS => [ 'authen_domain', 'authen_username', 'authen_password' ]
50 );
51  
52 - or -
53  
54 sub check_password {
55 my @credentials = @_;
56 if ($credentials[0] eq 'test' && $credentials[1] eq 'secret') {
57 return 'testuser';
58 }
59 return;
60 }
61  
62 __PACKAGE__->authen->config(
63 DRIVER => [ 'Generic', \&check_password ],
64 );
65  
66  
67 =head1 METHODS
68  
69 =head2 verify_credentials
70  
71 This method will test the provided credentials against either the hash ref, array ref or code ref
72 that the driver was configured with.
73  
74 =cut
75  
76 sub verify_credentials {
77 79 ▶ my $self = shift;
Subroutine verify_credentials: called CC=11 SCAR=24.0
Pod documented
78 79 my @creds = @_;
79 79 my @options = $self->options;
80 79 my $data = $options[0];
81  
82 79 ▶ if ( ref $data eq 'HASH' ) {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $data eq 'HASH') { } 50 29 79
elsif (ref $data eq 'ARRAY') { } 15 14 29
elsif (ref $data eq 'CODE') { } 13 1 14
83 50 ▶ return undef unless( defined( $creds[0] ) && defined( $creds[1] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $creds[0] and defined $creds[1] 13 37 50
Condition100%3/3
defined $creds[0] and defined $creds[1]
!ll&&!rl&&r
11237
MC/DC100%2/2
defined $creds[0] and defined $creds[1]
defined $creds[0] defined $creds[1]
Truth table100%3/3
A and B
A= defined $creds[0]B= defined $creds[1]
ABresult
0X0
100
111
84 37 ▶ return ( defined $data->{ $creds[0] } && $data->{ $creds[0] } eq $creds[1] ) ? $creds[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $$data{$creds[0]} && $$data{$creds[0]} eq $creds[1] ? : 18 19 37
Condition100%3/3
defined $$data{$creds[0]} and $$data{$creds[0]} eq $creds[1]
!ll&&!rl&&r
11818
MC/DC100%2/2
defined $$data{$creds[0]} and $$data{$creds[0]} eq $creds[1]
defined $$data{$creds[0]} $$data{$creds[0]} eq $creds[1]
Truth table100%3/3
A and B
A= defined $$data{$creds[0]}B= $$data{$creds[0]} eq $creds[1]
ABresult
0X0
100
111
85 } elsif ( ref $data eq 'ARRAY' ) {
86 15 foreach my $row (@$data) {
87 29 ▶ return $creds[0] unless grep { !defined $creds[$_] || $creds[$_] ne $row->[$_] } 0..$#$row;
Branch: 2 branches
BranchTrueFalseTotal
unless grep {not defined $creds[$_] or $creds[$_] ne $row->[$_];} 0 .. $row->$#* 2 27 29
not defined $creds[$_] or $creds[$_] ne $row->[$_] 50 8 58
88 }
89 13 return undef;
90 } elsif ( ref $data eq 'CODE' ) {
91 13 return $data->(@creds);
92 }
93 1 die "Unknown options for Generic Driver";
94 }
95  
96  
97 =head1 SEE ALSO
98  
99 L<CGI::Application::Plugin::Authentication::Driver>, L<CGI::Application::Plugin::Authentication>, perl(1)
100  
101  
102 =head1 LICENCE AND COPYRIGHT
103  
104 Copyright (c) 2005, SiteSuite. All rights reserved.
105  
106 This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
107  
108  
109 =head1 DISCLAIMER OF WARRANTY
110  
111 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.
112  
113 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.
114  
115 =cut
116  
117 14 1;
« blib/lib/CGI/Application/Plugin/Authentication/Display/Classic.pm ↑ Summary blib/lib/CGI/Application/Plugin/Authentication/Driver/Filter/md5.pm »