blib/lib/OpusVL/AppKit/LDAPAuth.pm untested

filter: Statementstmt 0.0% 0 / 26 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 39 CC 2 SCAR 11.5
CC
2
Cov
0%
check_password
6.0
server
2.0
BEGIN
2.0
CRAP 3.1
1 package OpusVL::AppKit::LDAPAuth;
2  
3 use Moose;
4 with 'OpusVL::AppKit::RolesFor::Auth';
5  
6 use Net::LDAP;
7 use Net::LDAP::Util qw/escape_dn_value/;
8 use experimental 'smartmatch';
9  
10 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 has user_base_dn => (is => 'ro', isa => 'Str', default => 'ou=People,dc=opusvl');
15 has user_field => (is => 'ro', isa => 'Str', default => 'uid');
16  
17 sub server
18 {
19 my $self = shift;
20 return Net::LDAP->new($self->ldap_server) || die $@;
21 }
22  
23  
24 sub check_password
25 {
26 my ($self, $username, $password) = @_;
27  
28 my $query = sprintf("(%s=%s)", $self->user_field, escape_dn_value($username));
29 my $mesg = $self->server->search(base => $self->user_base_dn, filter => $query);
30
31 foreach my $entry ($mesg->entries) {
32 my $login = $self->server->bind($entry->dn, password => $password);
33 return 1 unless $login->is_error;
34 }
35
36 return 0;
37 }
38  
39 1;
40  
41 __END__