« blib/lib/Lemonldap/NG/Portal/UserDB/DBI.pm
↑ Summary
blib/lib/Lemonldap/NG/Portal/Password/LDAP.pm »
| 1 | package Lemonldap::NG::Portal::Password::AD; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use Mouse; | ||
| 5 | use Lemonldap::NG::Portal::Main::Constants qw( | ||
| 6 | PE_ERROR | ||
| 7 | PE_LDAPERROR | ||
| 8 | PE_PASSWORD_OK | ||
| 9 | PE_LDAPCONNECTFAILED | ||
| 10 | ); | ||
| 11 | |||
| 12 | extends qw( | ||
| 13 | Lemonldap::NG::Portal::Lib::LDAP | ||
| 14 | Lemonldap::NG::Portal::Password::Base | ||
| 15 | ); | ||
| 16 | |||
| 17 | our $VERSION = '2.0.16'; | ||
| 18 | |||
| 19 | sub init { | ||
| 20 | my ($self) = @_; | ||
| 21 | return ( $self->Lemonldap::NG::Portal::Password::Base::init | ||
| 22 | and $self->Lemonldap::NG::Portal::Lib::LDAP::init ); | ||
| 23 | } | ||
| 24 | |||
| 25 | # Confirmation is done by Lib::Net::LDAP::userModifyPassword | ||
| 26 | sub confirm { | ||
| 27 | return 1; | ||
| 28 | } | ||
| 29 | |||
| 30 | sub modifyPassword { | ||
| 31 | my ( $self, $req, $pwd, %args ) = @_; | ||
| 32 | |||
| 33 | # If the password change is done in a different backend, | ||
| 34 | # we need to reload the correct DN | ||
| 35 | $self->getUser( $req, useMail => $args{useMail} ) | ||
| 36 | if $self->conf->{ldapGetUserBeforePasswordChange}; | ||
| 37 | |||
| 38 | my $dn = $req->data->{dn} || $req->sessionInfo->{_dn}; | ||
| 39 | unless ($dn) { | ||
| 40 | $self->logger->error('"dn" is not set, abort password modification'); | ||
| 41 | return PE_ERROR; | ||
| 42 | } | ||
| 43 | |||
| 44 | my $requireOldPassword = ( | ||
| 45 | $req->userData | ||
| 46 | ? $self->requireOldPwdRule->( $req, $req->userData ) | ||
| 47 | : $self->requireOldPwdRule->( $req, $req->sessionInfo ) | ||
| 48 | ); | ||
| 49 | $requireOldPassword = 0 if $args{passwordReset}; | ||
| 50 | |||
| 51 | # Ensure connection is valid | ||
| 52 | $self->bind; | ||
| 53 | return PE_LDAPCONNECTFAILED unless $self->ldap; | ||
| 54 | |||
| 55 | # Call the modify password method | ||
| 56 | my $code = | ||
| 57 | $self->ldap->userModifyPassword( $dn, $pwd, $req->data->{oldpassword}, | ||
| 58 | 1, $requireOldPassword ); | ||
| 59 | return $code unless ( $code == PE_PASSWORD_OK ); | ||
| 60 | |||
| 61 | # If force reset, set reset flag | ||
| 62 | if ( $req->data->{forceReset} ) { | ||
| 63 | my $result = $self->ldap->modify( | ||
| 64 | $dn, | ||
| 65 | replace => { | ||
| 66 | 'pwdLastSet' => '0' | ||
| 67 | } | ||
| 68 | ); | ||
| 69 | |||
| 70 | unless ( $result->code == 0 ) { | ||
| 71 | $self->logger->error( "LDAP modify pwdLastSet error " | ||
| 72 | . $result->code . ": " | ||
| 73 | . $result->error ); | ||
| 74 | return PE_LDAPERROR; | ||
| 75 | } | ||
| 76 | |||
| 77 | $self->logger->debug("pwdLastSet set to 0"); | ||
| 78 | } | ||
| 79 | |||
| 80 | return $code; | ||
| 81 | } | ||
| 82 | |||
| 83 | 1; |