line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Application::Plugin::Authentication::Driver::Generic; |
2
|
|
|
|
|
|
|
|
3
|
14
|
|
|
14
|
|
88
|
use strict; |
|
14
|
|
|
|
|
57
|
|
|
14
|
|
|
|
|
559
|
|
4
|
14
|
|
|
14
|
|
87
|
use warnings; |
|
14
|
|
|
|
|
37
|
|
|
14
|
|
|
|
|
750
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.20'; |
6
|
|
|
|
|
|
|
|
7
|
14
|
|
|
14
|
|
119
|
use base qw(CGI::Application::Plugin::Authentication::Driver); |
|
14
|
|
|
|
|
30
|
|
|
14
|
|
|
|
|
11764
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
CGI::Application::Plugin::Authentication::Driver::Generic - Generic Authentication driver |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
This document describes CGI::Application::Plugin::Authentication::Driver::Generic version 0.20 |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use base qw(CGI::Application); |
20
|
|
|
|
|
|
|
use CGI::Application::Plugin::Authentication; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
__PACKAGE__->authen->config( |
23
|
|
|
|
|
|
|
DRIVER => [ 'Generic', { user1 => '123', user2 => '123' } ], |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 DESCRIPTION |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
This Driver offers a simple way to provide a user database to the |
29
|
|
|
|
|
|
|
L plugin. It offers three ways |
30
|
|
|
|
|
|
|
to provide a list of users to the plugin by providing a hash of username/password pairs, |
31
|
|
|
|
|
|
|
an array of arrays containing the username and password pairs, or a code |
32
|
|
|
|
|
|
|
reference that returns back the username, or undef on success or failure. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 EXAMPLE |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my %users = ( |
37
|
|
|
|
|
|
|
user1 => '123', |
38
|
|
|
|
|
|
|
user2 => '123', |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
__PACKAGE__->authen->config( |
41
|
|
|
|
|
|
|
DRIVER => [ 'Generic', \%users ], |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
- or - |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my @users = ( |
47
|
|
|
|
|
|
|
['example.com', 'user1', '123'], |
48
|
|
|
|
|
|
|
['example.com', 'user2', '123'], |
49
|
|
|
|
|
|
|
['foobar.com', 'user1', '123'], |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
__PACKAGE__->authen->config( |
52
|
|
|
|
|
|
|
DRIVER => [ 'Generic', \@users ], |
53
|
|
|
|
|
|
|
CREDENTIALS => [ 'authen_domain', 'authen_username', 'authen_password' ] |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
- or - |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub check_password { |
59
|
|
|
|
|
|
|
my @credentials = @_; |
60
|
|
|
|
|
|
|
if ($credentials[0] eq 'test' && $credentials[1] eq 'secret') { |
61
|
|
|
|
|
|
|
return 'testuser'; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
return; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
__PACKAGE__->authen->config( |
67
|
|
|
|
|
|
|
DRIVER => [ 'Generic', \&check_password ], |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 METHODS |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 verify_credentials |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
This method will test the provided credentials against either the hash ref, array ref or code ref |
76
|
|
|
|
|
|
|
that the driver was configured with. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub verify_credentials { |
81
|
84
|
|
|
84
|
1
|
153
|
my $self = shift; |
82
|
84
|
|
|
|
|
209
|
my @creds = @_; |
83
|
84
|
|
|
|
|
480
|
my @options = $self->options; |
84
|
84
|
|
|
|
|
179
|
my $data = $options[0]; |
85
|
|
|
|
|
|
|
|
86
|
84
|
100
|
|
|
|
356
|
if ( ref $data eq 'HASH' ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
87
|
55
|
100
|
100
|
|
|
540
|
return undef unless( defined( $creds[0] ) && defined( $creds[1] ) ); |
88
|
40
|
100
|
100
|
|
|
578
|
return ( defined $data->{ $creds[0] } && $data->{ $creds[0] } eq $creds[1] ) ? $creds[0] : undef; |
89
|
|
|
|
|
|
|
} elsif ( ref $data eq 'ARRAY' ) { |
90
|
15
|
|
|
|
|
45
|
foreach my $row (@$data) { |
91
|
29
|
100
|
|
|
|
77
|
return $creds[0] unless grep { !defined $creds[$_] || $creds[$_] ne $row->[$_] } 0..$#$row; |
|
58
|
100
|
|
|
|
366
|
|
92
|
|
|
|
|
|
|
} |
93
|
13
|
|
|
|
|
74
|
return undef; |
94
|
|
|
|
|
|
|
} elsif ( ref $data eq 'CODE' ) { |
95
|
13
|
|
|
|
|
62
|
return $data->(@creds); |
96
|
|
|
|
|
|
|
} |
97
|
1
|
|
|
|
|
12
|
die "Unknown options for Generic Driver"; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 SEE ALSO |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
L, L, perl(1) |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 LICENCE AND COPYRIGHT |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Copyright (c) 2005, SiteSuite. All rights reserved. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 DISCLAIMER OF WARRANTY |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
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. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
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. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |