« blib/lib/Lemonldap/NG/Portal/2F/TOTP.pm
↑ Summary
blib/lib/Lemonldap/NG/Portal/Plugins/CheckEntropy.pm »
| 1 | package Lemonldap::NG::Portal::CertificateResetByMail::LDAP; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use Mouse; | ||
| 5 | use Lemonldap::NG::Portal::Main::Constants qw( | ||
| 6 | PE_LDAPCONNECTFAILED | ||
| 7 | PE_LDAPERROR | ||
| 8 | PE_OK | ||
| 9 | PE_ERROR | ||
| 10 | ); | ||
| 11 | |||
| 12 | extends 'Lemonldap::NG::Portal::Lib::LDAP'; | ||
| 13 | |||
| 14 | our $VERSION = '2.0.14'; | ||
| 15 | |||
| 16 | # PRIVATE METHOD | ||
| 17 | sub modifCertificate { | ||
| 18 | my ( $self, $req, $newCertif, $userCertif ) = @_; | ||
| 19 | my $ceaAttribute = $self->conf->{certificateResetByMailCeaAttribute} | ||
| 20 | || "description"; | ||
| 21 | my $certificateAttribute = | ||
| 22 | $self->conf->{certificateResetByMailCertificateAttribute} | ||
| 23 | || "userCertificate;binary"; | ||
| 24 | |||
| 25 | # Set the dn unless done before | ||
| 26 | my $dn; | ||
| 27 | if ( $req->userData->{_dn} ) { | ||
| 28 | $dn = $req->userData->{_dn}; | ||
| 29 | $self->logger->debug("Get DN from request data: $dn"); | ||
| 30 | } | ||
| 31 | else { | ||
| 32 | $dn = $req->sessionInfo->{_dn}; | ||
| 33 | $self->logger->debug("Get DN from session data: $dn"); | ||
| 34 | } | ||
| 35 | unless ($dn) { | ||
| 36 | $self->logger->error('"dn" is not set, aborting certificate reset'); | ||
| 37 | return PE_ERROR; | ||
| 38 | } | ||
| 39 | |||
| 40 | #my $dn = "uid=" . $req->{user}. "," . $self->conf->{ldapBase}; | ||
| 41 | |||
| 42 | my $result = $self->ldap->modify( | ||
| 43 | $dn, | ||
| 44 | replace => [ | ||
| 45 | $ceaAttribute => $newCertif, | ||
| 46 | "$certificateAttribute" => [$userCertif] | ||
| 47 | ] | ||
| 48 | ); | ||
| 49 | |||
| 50 | unless ( $result->code == 0 ) { | ||
| 51 | $self->logger->debug( "LDAP modify Error: " . $result->code ); | ||
| 52 | $self->ldap->unbind; | ||
| 53 | return PE_LDAPERROR; | ||
| 54 | } | ||
| 55 | |||
| 56 | $self->logger->debug("$ceaAttribute set to $newCertif"); | ||
| 57 | |||
| 58 | return PE_OK; | ||
| 59 | } | ||
| 60 | |||
| 61 | 1; |