2016-07-18 21:38:14 +02:00
|
|
|
package Lemonldap::NG::Portal::Password::LDAP;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Mouse;
|
2018-01-25 15:53:52 +01:00
|
|
|
use Lemonldap::NG::Portal::Main::Constants
|
|
|
|
qw(PE_PASSWORD_OK PE_LDAPERROR PE_ERROR);
|
2016-07-18 21:38:14 +02:00
|
|
|
|
2017-01-15 14:18:01 +01:00
|
|
|
extends 'Lemonldap::NG::Portal::Lib::LDAP',
|
2016-07-20 22:47:43 +02:00
|
|
|
'Lemonldap::NG::Portal::Password::Base';
|
2016-07-18 21:38:14 +02:00
|
|
|
|
|
|
|
our $VERSION = '2.0.0';
|
|
|
|
|
|
|
|
sub init {
|
|
|
|
my ($self) = @_;
|
2016-07-20 22:47:43 +02:00
|
|
|
$self->ldap
|
|
|
|
and $self->filter
|
|
|
|
and $self->Lemonldap::NG::Portal::Password::Base::init;
|
2016-07-18 21:38:14 +02:00
|
|
|
}
|
|
|
|
|
2017-03-02 07:13:52 +01:00
|
|
|
# Confirmation is done by Lib::Net::LDAP::userModifyPassword
|
2016-07-18 21:38:14 +02:00
|
|
|
sub confirm {
|
2016-07-20 22:47:43 +02:00
|
|
|
return 1;
|
2016-07-18 21:38:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub modifyPassword {
|
|
|
|
my ( $self, $req, $pwd ) = @_;
|
2018-01-25 15:53:52 +01:00
|
|
|
my $dn = $req->userData->{_dn} || $req->sessionInfo->{_dn};
|
|
|
|
unless ($dn) {
|
|
|
|
$self->logger->error('"dn" is not set, aborting password modification');
|
|
|
|
return PE_ERROR;
|
|
|
|
}
|
2016-07-18 21:38:14 +02:00
|
|
|
|
|
|
|
# Call the modify password method
|
2018-01-25 15:53:52 +01:00
|
|
|
my $code =
|
|
|
|
$self->ldap->userModifyPassword( $dn, $pwd, $req->datas->{oldpassword} );
|
2016-07-18 21:38:14 +02:00
|
|
|
|
|
|
|
unless ( $code == PE_PASSWORD_OK ) {
|
|
|
|
$self->ldap->unbind;
|
|
|
|
$self->{flags}->{ldapActive} = 0;
|
|
|
|
return $code;
|
|
|
|
}
|
|
|
|
|
|
|
|
# If password policy and force reset, set reset flag
|
2017-03-02 07:13:52 +01:00
|
|
|
if ( $self->conf->{ldapPpolicyControl}
|
|
|
|
and $req->datas->{forceReset}
|
|
|
|
and $self->conf->{ldapUsePasswordResetAttribute} )
|
2016-07-18 21:38:14 +02:00
|
|
|
{
|
|
|
|
my $result = $self->ldap->modify(
|
2018-01-25 15:53:52 +01:00
|
|
|
$dn,
|
2016-07-18 21:38:14 +02:00
|
|
|
replace => {
|
2017-03-02 07:13:52 +01:00
|
|
|
$self->conf->{ldapPasswordResetAttribute} =>
|
|
|
|
$self->conf->{ldapPasswordResetAttributeValue}
|
2016-07-18 21:38:14 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
unless ( $result->code == 0 ) {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->error( "LDAP modify "
|
2017-10-19 09:01:19 +02:00
|
|
|
. $self->conf->{ldapPasswordResetAttribute}
|
2016-07-18 21:38:14 +02:00
|
|
|
. " error: "
|
2017-02-15 07:41:50 +01:00
|
|
|
. $result->code );
|
2016-07-18 21:38:14 +02:00
|
|
|
$self->ldap->unbind;
|
|
|
|
$self->{flags}->{ldapActive} = 0;
|
|
|
|
return PE_LDAPERROR;
|
|
|
|
}
|
|
|
|
|
2017-03-02 07:13:52 +01:00
|
|
|
$self->logger->debug( $self->conf->{ldapPasswordResetAttribute}
|
2016-07-18 21:38:14 +02:00
|
|
|
. " set to "
|
2017-03-02 07:13:52 +01:00
|
|
|
. $self->conf->{ldapPasswordResetAttributeValue} );
|
2016-07-18 21:38:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $code;
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|