line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Application::Plugin::Authentication::Driver::CDBI; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
2237929
|
use warnings; |
|
5
|
|
|
|
|
16
|
|
|
5
|
|
|
|
|
169
|
|
4
|
5
|
|
|
5
|
|
29
|
use strict; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
176
|
|
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
28
|
use base 'CGI::Application::Plugin::Authentication::Driver'; |
|
5
|
|
|
|
|
16
|
|
|
5
|
|
|
|
|
5707
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
THIS MODULE IS UNSUPPORTED! YOU CAN ADOPT IT IF YOU LIKE IT! WRITE TO |
11
|
|
|
|
|
|
|
modules@perl.org IF YOU WANT TO MAINTAIN IT. |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
CGI::Application::Plugin::Authentication::Driver::CDBI - Class::DBI Authentication Driver |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 VERSION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Version 0.03 |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
THIS MODULE IS UNSUPPORTED! YOU CAN ADOPT IT IF YOU LIKE IT! WRITE TO |
20
|
|
|
|
|
|
|
modules@perl.org IF YOU WANT TO MAINTAIN IT. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=cut |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SYNOPSIS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use base qw(CGI::Application); |
29
|
|
|
|
|
|
|
use CGI::Application::Plugin::Authentication; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
__PACKAGE__->authen->config( |
32
|
|
|
|
|
|
|
DRIVER => [ 'CDBI', |
33
|
|
|
|
|
|
|
CLASS => 'My::CDBI::Users', |
34
|
|
|
|
|
|
|
FIELD_METHODS => [qw(user MD5:passphrase)] |
35
|
|
|
|
|
|
|
], |
36
|
|
|
|
|
|
|
CREDENTIALS => [qw(auth_username auth_password)], |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 DESCRIPTION |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
This Authentication driver uses the Class::DBI module to allow you to |
42
|
|
|
|
|
|
|
authenticate against any Class::DBI class. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 PARAMETERS |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
The Class::DBI authentication driver accepts the following required |
47
|
|
|
|
|
|
|
parameters. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 CLASS (required) |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Specifies the Class::DBI class to use for authentication. This class must |
52
|
|
|
|
|
|
|
be loaded prior to use. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 FIELD_METHODS (required) |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
FIELD_METHODS is an arrayref of the methods in the Class::DBI class |
57
|
|
|
|
|
|
|
specified by CLASS to be used during authentication. The order of these |
58
|
|
|
|
|
|
|
methods needs to match the order of the CREDENTIALS. For example, if |
59
|
|
|
|
|
|
|
CREDENTIALS is set to: |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
CREDENTIALS => [qw(auth_user auth_domain auth_password)] |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Then FIELD_METHODS must be set to: |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
FIELD_METHODS => [qw(userid domain password)] |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
FIELD_METHODS supports filters as specified by |
68
|
|
|
|
|
|
|
CGI::Application::Plugin::Authentication::Driver |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 METHODS |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 verify_credentials |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
This method will test the provided credentials against the values found in |
75
|
|
|
|
|
|
|
the database, according to the Driver configuration. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub verify_credentials { |
80
|
5
|
|
|
5
|
1
|
74669
|
my $self = shift; |
81
|
5
|
|
|
|
|
13
|
my @creds = @_; |
82
|
|
|
|
|
|
|
|
83
|
5
|
|
|
|
|
38
|
my @_options=$self->options; |
84
|
5
|
50
|
|
|
|
56
|
die "The Class::DBI driver requires a hash of options" if @_options % 2; |
85
|
5
|
|
|
|
|
19
|
my %options=@_options; |
86
|
|
|
|
|
|
|
|
87
|
5
|
|
|
|
|
11
|
my $cdbiclass=$options{CLASS}; |
88
|
5
|
50
|
|
|
|
20
|
die "CLASS option must be set." unless($cdbiclass); |
89
|
|
|
|
|
|
|
|
90
|
5
|
100
|
|
|
|
11
|
return unless(scalar(@creds) eq scalar(@{$options{FIELD_METHODS}})); |
|
5
|
|
|
|
|
35
|
|
91
|
|
|
|
|
|
|
|
92
|
4
|
|
|
|
|
8
|
my @crednames=@{$self->authen->credentials}; |
|
4
|
|
|
|
|
32
|
|
93
|
|
|
|
|
|
|
|
94
|
4
|
|
|
|
|
99
|
my %search; |
95
|
|
|
|
|
|
|
my %compare; |
96
|
4
|
|
|
|
|
8
|
my $i=0; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# There's a lot of remapping lists/arrays into hashes here |
99
|
|
|
|
|
|
|
# Most of this is due to needing a hash to perform a search, |
100
|
|
|
|
|
|
|
# and another hash to perform comparisions if the search is |
101
|
|
|
|
|
|
|
# encrypted. Also verify that columns that exist have been specified. |
102
|
4
|
|
|
|
|
7
|
for(@{$options{FIELD_METHODS}}) { |
|
4
|
|
|
|
|
13
|
|
103
|
8
|
100
|
|
|
|
41
|
$search{$_}=$creds[$i] unless /:/; |
104
|
8
|
100
|
|
|
|
30
|
$compare{$_}=$creds[$i] if /:/; |
105
|
8
|
|
|
|
|
44
|
my $column=$self->strip_field_names($_); |
106
|
8
|
50
|
|
|
|
227
|
die "Column $column not in $cdbiclass" unless($cdbiclass->can($column)); |
107
|
8
|
|
|
|
|
22
|
$i++; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
4
|
|
|
|
|
48
|
my @users=$options{CLASS}->search( %search ); |
111
|
4
|
100
|
|
|
|
22335
|
return unless(@users); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# We want to return the value of the first column specified. |
114
|
|
|
|
|
|
|
# Could probably just return $creds[0] as that value should match |
115
|
|
|
|
|
|
|
# but I've chosen to return what's in the DB. |
116
|
3
|
|
|
|
|
11
|
my $field = ( @{ $options{FIELD_METHODS} } )[0]; |
|
3
|
|
|
|
|
16
|
|
117
|
3
|
100
|
|
|
|
13
|
if (%compare) { |
118
|
2
|
|
|
|
|
7
|
foreach my $encoded ( keys(%compare) ) { |
119
|
2
|
|
|
|
|
14
|
my $column = $self->strip_field_names($encoded); |
120
|
|
|
|
|
|
|
# No point checking the rest of the columns if any of the encoded ones |
121
|
|
|
|
|
|
|
# do not match. |
122
|
|
|
|
|
|
|
return |
123
|
|
|
|
|
|
|
unless ( |
124
|
2
|
50
|
|
|
|
46
|
$self->check_filtered( |
125
|
|
|
|
|
|
|
$encoded, $compare{$encoded}, $users[0]->$column |
126
|
|
|
|
|
|
|
) |
127
|
|
|
|
|
|
|
); |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
# If we've made it this far, we have a valid user. Set the user object and |
131
|
|
|
|
|
|
|
# Return the value of the first credentail. |
132
|
3
|
|
|
|
|
5033
|
return $users[0]->$field; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 SEE ALSO |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
L, |
138
|
|
|
|
|
|
|
L, perl(1) |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 AUTHOR |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Shawn Sorichetti, C<< >> |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 BUGS |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
147
|
|
|
|
|
|
|
C, or through the web interface at |
148
|
|
|
|
|
|
|
L. |
149
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
150
|
|
|
|
|
|
|
your bug as I make changes. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Special thanks to Cees Hek for writing CGI::Application::Plugin::Authentication |
155
|
|
|
|
|
|
|
and his assistance in writing this module. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
THIS MODULE IS UNSUPPORTED! YOU CAN ADOPT IT IF YOU LIKE IT! WRITE TO |
160
|
|
|
|
|
|
|
modules@perl.org IF YOU WANT TO MAINTAIN IT. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Copyright 2005 Shawn Sorichetti, all rights reserved. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
165
|
|
|
|
|
|
|
under the same terms as Perl itself. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=cut |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
1; # End of CGI::Application::Plugin::Authentication::Driver::CDBI |