lemonldap-ng/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Password/LDAP.pm

69 lines
1.8 KiB
Perl
Raw Normal View History

2016-07-18 21:38:14 +02:00
package Lemonldap::NG::Portal::Password::LDAP;
use strict;
use Mouse;
use Lemonldap::NG::Portal::Main::Constants qw(PE_PASSWORD_OK PE_LDAPERROR);
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 ) = @_;
# Call the modify password method
my $code = $self->ldap->userModifyPassword( $req->userData->{_dn},
2017-03-03 18:25:03 +01:00
$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(
2017-03-02 07:35:15 +01:00
$req->datas->{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 "
2016-07-18 21:38:14 +02:00
. $self->{ldapPasswordResetAttribute}
. " 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;