Ignore:
Timestamp:
05/30/12 23:09:17 (12 years ago)
Author:
nanardon
Message:

Add authentication support to ldap

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Ldap.pm

    r1023 r1032  
    229229} 
    230230 
     231sub authenticate_user { 
     232    my ($self, $username, $passwd) = @_; 
     233    $username or return; 
     234 
     235    # Basically, connect and if bind succeed, user is authenticated ! 
     236    my $ldapurl = $self->ldap->uri; 
     237    my $ldap = Net::LDAP->new($ldapurl); 
     238 
     239    my $obj = $self->get_object('user', $username) or do { 
     240        $self->log(LA_ERR, "Cannot find user %s", $username); 
     241        return; 
     242    }; 
     243 
     244    if ($ldap) { 
     245        $self->log(LA_DEBUG, "Connected to ldap server %s", $ldapurl); 
     246    } else { 
     247        $self->log(LA_ERR, "Cannot connect to %s", $ldapurl); 
     248        return; # cannot connect to any ldap :\ 
     249    }; 
     250 
     251 
     252    my $msg = $ldap->bind($obj->get_attributes('dn'), password => $passwd); 
     253    if ($msg->code) { 
     254        $self->log(LA_ERR, "Cannot bind ldap: %s", $msg->error); 
     255        return; 
     256    } else { 
     257        return 1; # Success !! \o/ 
     258    } 
     259} 
     260 
    2312611; 
    232262 
Note: See TracChangeset for help on using the changeset viewer.