2008-12-26 20:18:23 +01:00
|
|
|
##@file
|
|
|
|
# LDAP authentication backend file
|
|
|
|
|
|
|
|
##@class
|
|
|
|
# LDAP authentication backend class
|
2008-06-06 14:42:35 +02:00
|
|
|
package Lemonldap::NG::Portal::AuthLDAP;
|
|
|
|
|
|
|
|
use Lemonldap::NG::Portal::Simple;
|
2009-02-15 09:53:44 +01:00
|
|
|
use Lemonldap::NG::Portal::_LDAP 'ldap'; #link protected ldap
|
2008-11-24 15:06:54 +01:00
|
|
|
use Lemonldap::NG::Portal::_WebForm;
|
2009-04-07 10:26:12 +02:00
|
|
|
use Lemonldap::NG::Portal::UserDBLDAP; #inherits
|
2008-06-06 14:42:35 +02:00
|
|
|
|
2014-06-23 14:45:27 +02:00
|
|
|
our $VERSION = '1.4.0';
|
2008-12-03 17:43:31 +01:00
|
|
|
use base qw(Lemonldap::NG::Portal::_WebForm);
|
2008-06-06 14:42:35 +02:00
|
|
|
|
2008-12-03 17:43:31 +01:00
|
|
|
*_formateFilter = *Lemonldap::NG::Portal::UserDBLDAP::formateFilter;
|
2009-02-14 16:21:58 +01:00
|
|
|
*_search = *Lemonldap::NG::Portal::UserDBLDAP::search;
|
2008-12-03 17:43:31 +01:00
|
|
|
|
2014-06-23 14:45:27 +02:00
|
|
|
## @apmethod int authInit()
|
2010-09-01 18:06:01 +02:00
|
|
|
# Set _authnLevel
|
2009-04-08 12:32:33 +02:00
|
|
|
# @return Lemonldap::NG::Portal constant
|
|
|
|
sub authInit {
|
2010-09-01 18:06:01 +02:00
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
$self->{_authnLevel} = $self->{ldapAuthnLevel};
|
|
|
|
|
2009-04-08 12:32:33 +02:00
|
|
|
PE_OK;
|
2009-04-07 10:26:12 +02:00
|
|
|
}
|
|
|
|
|
2009-02-17 15:56:38 +01:00
|
|
|
## @apmethod int authenticate()
|
2008-12-26 18:58:48 +01:00
|
|
|
# Authenticate user by LDAP mechanism.
|
2008-12-28 09:36:52 +01:00
|
|
|
# @return Lemonldap::NG::Portal constant
|
2008-06-06 14:42:35 +02:00
|
|
|
sub authenticate {
|
|
|
|
my $self = shift;
|
2010-09-23 17:09:27 +02:00
|
|
|
|
2008-10-07 22:15:48 +02:00
|
|
|
unless ( $self->ldap ) {
|
|
|
|
return PE_LDAPCONNECTFAILED;
|
|
|
|
}
|
|
|
|
|
2008-12-03 17:43:31 +01:00
|
|
|
# Set the dn unless done before
|
2009-02-12 20:48:53 +01:00
|
|
|
unless ( $self->{dn} ) {
|
2008-12-03 17:43:31 +01:00
|
|
|
my $tmp = $self->_subProcess(qw(_formateFilter _search));
|
2010-09-13 16:09:07 +02:00
|
|
|
$self->{sessionInfo}->{dn} = $self->{dn};
|
2009-02-12 20:48:53 +01:00
|
|
|
return $tmp if ($tmp);
|
2008-12-03 17:43:31 +01:00
|
|
|
}
|
2011-05-20 11:45:18 +02:00
|
|
|
|
|
|
|
my $res =
|
|
|
|
$self->ldap->userBind( $self->{dn}, password => $self->{password} );
|
|
|
|
|
|
|
|
# Remember password if password reset needed
|
|
|
|
$self->{oldpassword} = $self->{password}
|
|
|
|
if ( $res == PE_PP_CHANGE_AFTER_RESET );
|
|
|
|
|
2014-06-23 14:45:27 +02:00
|
|
|
# Unbind if there was an error
|
|
|
|
unless ( $res == PE_OK ) {
|
|
|
|
$self->ldap->unbind;
|
|
|
|
$self->{flags}->{ldapActive} = 0;
|
|
|
|
}
|
|
|
|
|
2011-05-20 11:45:18 +02:00
|
|
|
return $res;
|
2008-06-06 14:42:35 +02:00
|
|
|
}
|
|
|
|
|
2010-09-01 10:59:39 +02:00
|
|
|
## @apmethod int authFinish()
|
|
|
|
# Unbind.
|
|
|
|
# @return Lemonldap::NG::Portal constant
|
|
|
|
sub authFinish {
|
|
|
|
my $self = shift;
|
|
|
|
|
2014-06-25 13:53:09 +02:00
|
|
|
if ( ref( $self->{ldap} ) && $self->{flags}->{ldapActive} ) {
|
|
|
|
$self->ldap->unbind();
|
|
|
|
$self->{flags}->{ldapActive} = 0;
|
|
|
|
}
|
2010-09-01 10:59:39 +02:00
|
|
|
|
|
|
|
PE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
## @apmethod int authLogout()
|
|
|
|
# Does nothing
|
|
|
|
# @return Lemonldap::NG::Portal constant
|
|
|
|
sub authLogout {
|
|
|
|
PE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
## @apmethod boolean authForce()
|
|
|
|
# Does nothing
|
|
|
|
# @return result
|
|
|
|
sub authForce {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-24 15:47:47 +01:00
|
|
|
## @method string getDisplayType
|
|
|
|
# @return display type
|
|
|
|
sub getDisplayType {
|
|
|
|
return "standardform";
|
|
|
|
}
|
|
|
|
|
2008-06-06 14:42:35 +02:00
|
|
|
1;
|