blib/lib/OpusVL/AppKit/LDAPAuth.pm

filter: Statementstmt 65.3% 17 / 26 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 66.6% 4 / 6 Podpod 50.0% 1 / 2 totaltotal 56.4% 22 / 39 CC 4 SCAR 17.5
CC
4
Cov
57%
check_password
12.0
server
6.0
BEGIN
1.0
CRAP 5.8
« lib/OpusVL/AppKit/Action/AppKitForm.pm ↑ Summary blib/lib/OpusVL/AppKit/View/SimpleXML.pm »
1 package OpusVL::AppKit::LDAPAuth;
2  
3 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 with 'OpusVL::AppKit::RolesFor::Auth';
5  
6 2 ▶use Net::LDAP;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Net::LDAP::Util qw/escape_dn_value/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use experimental 'smartmatch';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 has ldap_server => (is => 'rw', isa => 'Str', default => 'ldap');
11  
12 # NOTE: we assume that the dn parts we're given are already correctly escaped if
13 # necessary.
14 2 has user_base_dn => (is => 'ro', isa => 'Str', default => 'ou=People,dc=opusvl');
15 2 has user_field => (is => 'ro', isa => 'Str', default => 'uid');
16  
17 sub server
18 {
19 0 ▶ my $self = shift;
Subroutine server: not called CC=2 SCAR=17.9
Pod undocumented
20 0 ▶ return Net::LDAP->new($self->ldap_server) || die $@;
Condition0%0/2
'Net::LDAP'->new($self->ldap_server) || die($@)
l!l
00
MC/DC0%0/1
'Net::LDAP'->new($self->ldap_server) || die($@)
'Net::LDAP'->new($self->ldap_server)
Truth table0%0/2
A
A= 'Net::LDAP'->new($self->ldap_server)
Aresult
11
00
21 }
22  
23  
24 sub check_password
25 {
26 0 ▶ my ($self, $username, $password) = @_;
Subroutine check_password: not called CC=3 SCAR=24.8
Pod documented
27  
28 0 my $query = sprintf("(%s=%s)", $self->user_field, escape_dn_value($username));
29 0 my $mesg = $self->server->search(base => $self->user_base_dn, filter => $query);
30
31 0 foreach my $entry ($mesg->entries) {
32 0 my $login = $self->server->bind($entry->dn, password => $password);
33 0 ▶ return 1 unless $login->is_error;
Branch: 1 branch
BranchTrueFalseTotal
unless $login->is_error 0 0 0
34 }
35
36 0 return 0;
37 }
38  
39 2 1;
40  
41 __END__
42  
43 =pod
44  
45 =encoding UTF-8
46  
47 =head1 NAME
48  
49 OpusVL::AppKit::LDAPAuth
50  
51 =head1 VERSION
52  
53 version 2.24
54  
55 =head1 SYNOPSIS
56  
57 my $test = OpusVL::AppKit::LDAPAuth->new({
58 ldap_server => 'ldap',
59 user_base_dn => 'ou=People,dc=opusvl',
60 user_field => 'uid',
61 });
62 ok $test->check_password($user, $password);
63  
64 =head1 DESCRIPTION
65  
66 This class implements the OpusVL::AppKit::RolesFor::Auth to provide a mechanism to
67 check a users password via LDAP.
68  
69 =head2 check_password
70  
71 Check password is correct for user.
72  
73 =head1 NAME
74  
75 OpusVL::AppKit::LDAPAuth
76  
77 =head1 METHODS
78  
79 =head2 check_password
80  
81 This method checks the password for the user using the user_base_dn and user_field
82 along with the username to construct the dn. The username will be escaped for you
83 but the configuration parameters you supply to the object are assumed to already be
84 escaped. i.e. a username of "user.name" should just work.
85  
86 =head1 SEE ALSO
87  
88 To integrate this with Catalyst you need to add the trait
89 L<OpusVL::AppKit::RolesFor::Model::LDAPAuth> to your model and apply the role
90 L<OpusVL::AppKit::RolesFor::Schema::LDAPAuth> to your schema class.
91  
92 =head1 AUTHOR
93  
94 OpusVL - www.opusvl.com
95  
96 =head1 COPYRIGHT AND LICENSE
97  
98 This software is copyright (c) 2010 by OpusVL - www.opusvl.com.
99  
100 This is free software; you can redistribute it and/or modify it under
101 the same terms as the Perl 5 programming language system itself.
102  
103 =cut
« lib/OpusVL/AppKit/Action/AppKitForm.pm ↑ Summary blib/lib/OpusVL/AppKit/View/SimpleXML.pm »