« blib/lib/Lemonldap/NG/Portal/Issuer/JitsiMeetTokens.pm
↑ Summary
blib/lib/Lemonldap/NG/Portal/Auth/Combination.pm »
| 1 | package Lemonldap::NG::Portal::Register::AD; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use Mouse; | ||
| 5 | use Encode; | ||
| 6 | use Lemonldap::NG::Portal::Main::Constants qw( | ||
| 7 | PE_OK | ||
| 8 | PE_LDAPERROR | ||
| 9 | ); | ||
| 10 | |||
| 11 | extends 'Lemonldap::NG::Portal::Register::LDAP'; | ||
| 12 | |||
| 13 | our $VERSION = '2.0.14'; | ||
| 14 | |||
| 15 | sub createUser { | ||
| 16 | my ( $self, $req ) = @_; | ||
| 17 | |||
| 18 | my $name = | ||
| 19 | ucfirst $req->data->{registerInfo}->{firstname} . " " | ||
| 20 | . uc $req->data->{registerInfo}->{lastname}; | ||
| 21 | |||
| 22 | my $sn = uc $req->data->{registerInfo}->{lastname}; | ||
| 23 | my $gn = ucfirst $req->data->{registerInfo}->{firstname}; | ||
| 24 | my $password = $req->data->{registerInfo}->{password}; | ||
| 25 | utf8::decode($sn); | ||
| 26 | utf8::decode($gn); | ||
| 27 | utf8::decode($password); | ||
| 28 | my $mesg = $self->ldap->add( | ||
| 29 | "cn=$name," . $self->conf->{ldapBase}, | ||
| 30 | attrs => [ | ||
| 31 | objectClass => [qw/top person organizationalPerson user/], | ||
| 32 | sAMAccountName => $req->data->{registerInfo}->{login}, | ||
| 33 | cn => $name, | ||
| 34 | sn => $sn, | ||
| 35 | givenName => $gn, | ||
| 36 | unicodePwd => encode( "UTF-16LE", chr(34) . $password . chr(34) ), | ||
| 37 | mail => $req->data->{registerInfo}->{mail}, | ||
| 38 | ] | ||
| 39 | ); | ||
| 40 | |||
| 41 | if ( $mesg->is_error ) { | ||
| 42 | $self->userLogger->error( | ||
| 43 | "Can not create entry for " . $req->data->{registerInfo}->{login} ); | ||
| 44 | $self->logger->error( | ||
| 45 | "LDAP error " . $mesg->code . ": " . $mesg->error ); | ||
| 46 | |||
| 47 | $self->ldap->unbind(); | ||
| 48 | return PE_LDAPERROR; | ||
| 49 | } | ||
| 50 | return PE_OK; | ||
| 51 | } | ||
| 52 | |||
| 53 | # PRIVATE METHODS | ||
| 54 | |||
| 55 | # Search if login is already in use | ||
| 56 | sub isLoginUsed { | ||
| 57 | my ( $self, $login ) = @_; | ||
| 58 | |||
| 59 | my $mesg = $self->ldap->search( | ||
| 60 | base => $self->conf->{ldapBase}, | ||
| 61 | filter => "(sAMAccountName=$login)", | ||
| 62 | scope => "sub", | ||
| 63 | attrs => ['1.1'], | ||
| 64 | ); | ||
| 65 | |||
| 66 | if ( $mesg->code() != 0 ) { | ||
| 67 | $self->logger->warn( "LDAP Search error for $login: " . $mesg->error ); | ||
| 68 | return 1; | ||
| 69 | } | ||
| 70 | |||
| 71 | if ( $mesg->count() > 0 ) { | ||
| 72 | $self->logger->debug("Login $login already used in LDAP"); | ||
| 73 | return 1; | ||
| 74 | } | ||
| 75 | |||
| 76 | return 0; | ||
| 77 | } | ||
| 78 | |||
| 79 | 1; |