2017-01-16 10:11:29 +01:00
|
|
|
package Lemonldap::NG::Portal::Register::AD;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Mouse;
|
|
|
|
use Lemonldap::NG::Portal::Main::Constants qw(
|
|
|
|
PE_OK
|
2020-11-04 16:48:43 +01:00
|
|
|
PE_LDAPERROR
|
2017-01-16 10:11:29 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
extends 'Lemonldap::NG::Portal::Register::LDAP';
|
|
|
|
|
2020-11-04 16:48:43 +01:00
|
|
|
our $VERSION = '2.0.10';
|
2017-01-16 10:11:29 +01:00
|
|
|
|
|
|
|
sub createUser {
|
|
|
|
my ( $self, $req ) = @_;
|
|
|
|
|
|
|
|
my $name =
|
2018-07-05 22:56:16 +02:00
|
|
|
ucfirst $req->data->{registerInfo}->{firstname} . " "
|
|
|
|
. uc $req->data->{registerInfo}->{lastname};
|
2017-01-16 10:11:29 +01:00
|
|
|
|
2018-07-05 22:56:16 +02:00
|
|
|
my $sn = uc $req->data->{registerInfo}->{lastname};
|
|
|
|
my $gn = ucfirst $req->data->{registerInfo}->{firstname};
|
2017-12-20 23:19:57 +01:00
|
|
|
utf8::decode($sn);
|
|
|
|
utf8::decode($gn);
|
2017-01-16 10:11:29 +01:00
|
|
|
my $mesg = $self->ldap->add(
|
|
|
|
"cn=$name," . $self->conf->{ldapBase},
|
|
|
|
attrs => [
|
|
|
|
objectClass => [qw/top person organizationalPerson user/],
|
2018-07-05 22:56:16 +02:00
|
|
|
sAMAccountName => $req->data->{registerInfo}->{login},
|
2017-01-16 10:11:29 +01:00
|
|
|
cn => $name,
|
2017-12-20 23:19:57 +01:00
|
|
|
sn => $sn,
|
|
|
|
givenName => $gn,
|
2017-01-16 10:11:29 +01:00
|
|
|
unicodePwd => utf8(
|
2018-07-05 22:56:16 +02:00
|
|
|
chr(34) . $req->data->{registerInfo}->{password} . chr(34)
|
2018-11-26 14:40:21 +01:00
|
|
|
)->utf16le(),
|
2018-07-05 22:56:16 +02:00
|
|
|
mail => $req->data->{registerInfo}->{mail},
|
2017-01-16 10:11:29 +01:00
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( $mesg->is_error ) {
|
2018-07-05 23:00:40 +02:00
|
|
|
$self->userLogger->error(
|
|
|
|
"Can not create entry for " . $req->data->{registerInfo}->{login} );
|
2019-09-30 17:19:57 +02:00
|
|
|
$self->logger->error(
|
|
|
|
"LDAP error " . $mesg->code . ": " . $mesg->error );
|
2017-01-16 10:11:29 +01:00
|
|
|
|
|
|
|
$self->ldap->unbind();
|
|
|
|
$self->{flags}->{ldapActive} = 0;
|
|
|
|
|
|
|
|
return PE_LDAPERROR;
|
|
|
|
}
|
|
|
|
return PE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
# PRIVATE METHODS
|
|
|
|
|
|
|
|
# Search if login is already in use
|
|
|
|
sub isLoginUsed {
|
|
|
|
my ( $self, $login ) = @_;
|
|
|
|
|
|
|
|
my $mesg = $self->ldap->search(
|
|
|
|
base => $self->conf->{ldapBase},
|
|
|
|
filter => "(sAMAccountName=$login)",
|
|
|
|
scope => "sub",
|
|
|
|
attrs => ['1.1'],
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( $mesg->code() != 0 ) {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->warn( "LDAP Search error for $login: " . $mesg->error );
|
2017-01-16 10:11:29 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $mesg->count() > 0 ) {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug("Login $login already used in LDAP");
|
2017-01-16 10:11:29 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|