Commit 9beaac9c authored by Xavier Guimard's avatar Xavier Guimard

Improvements (#1496)

parent 76768d8e
...@@ -21,24 +21,23 @@ sub newLdap { ...@@ -21,24 +21,23 @@ sub newLdap {
my $ldap; my $ldap;
# Build object and test LDAP connexion # Build object and test LDAP connexion
if ( unless (
$ldap = Lemonldap::NG::Portal::Lib::Net::LDAP->new( $ldap = Lemonldap::NG::Portal::Lib::Net::LDAP->new(
{ p => $self->{p}, conf => $self->{conf} } { p => $self->{p}, conf => $self->{conf} }
) )
and my $msg = $ldap->bind
) )
{ {
if ( $msg->code != 0 ) { $self->error("LDAP initialization error: $@");
$self->logger->error( "LDAP error: " . $msg->error ); return undef;
} }
else {
if ( $self->{conf}->{ldapPpolicyControl} and not $ldap->loadPP() ) { # Test connection
$self->logger->error("LDAP password policy error"); my $msg = $ldap->bind;
} if ( $msg->code ) {
} $self->logger->error( 'LDAP test has failed: ' . $msg->error );
} }
else { elsif ( $self->{conf}->{ldapPpolicyControl} and not $ldap->loadPP() ) {
$self->logger->error("LDAP error: $@"); $self->logger->error("LDAP password policy error");
} }
return $ldap; return $ldap;
} }
...@@ -69,17 +68,22 @@ sub buildMailFilter { ...@@ -69,17 +68,22 @@ sub buildMailFilter {
} }
sub _buildFilter { sub _buildFilter {
my $conf = $_[0]->{conf}; my ( $self, $filter ) = @_;
$_[0]->{p}->logger->debug("LDAP Search base: $_[0]->{conf}->{ldapBase}"); my $conf = $self->{conf};
my $filter = $_[1]; $self->{p}->logger->debug("LDAP Search base: $_[0]->{conf}->{ldapBase}");
$filter =~ s/"/\\"/g; $filter =~ s/"/\\"/g;
$filter =~ s/\$(\w+)/".\$req->{sessionInfo}->{$1}."/g; $filter =~ s/\$(\w+)/".\$req->{sessionInfo}->{$1}."/g;
$filter =~ s/\$req->\{sessionInfo\}->\{user\}/\$req->{user}/g; $filter =~ s/\$req->\{sessionInfo\}->\{user\}/\$req->{user}/g;
$filter =~ $filter =~
s/\$req->\{sessionInfo\}->\{(_?password|mail)\}/\$req->{data}->{$1}/g; s/\$req->\{sessionInfo\}->\{(_?password|mail)\}/\$req->{data}->{$1}/g;
$_[0]->{p}->logger->debug("LDAP transformed filter: $filter"); $self->{p}->logger->debug("LDAP transformed filter: $filter");
$filter = "sub{my(\$req)=\$_[0];return \"$filter\";}"; $filter = "sub{my(\$req)=\$_[0];return \"$filter\";}";
return eval $filter; my $res = eval $filter;
if ($@) {
$self->error("Unable to build fiter: $@");
}
return $res;
} }
# INITIALIZATION # INITIALIZATION
......
...@@ -347,7 +347,8 @@ sub display { ...@@ -347,7 +347,8 @@ sub display {
# Choose what form to display if not in a loop # Choose what form to display if not in a loop
else { else {
my $displayType = $self->_authentication->getDisplayType($req); my $displayType =
eval { $self->_authentication->getDisplayType($req) };
$self->logger->debug("Display type $displayType "); $self->logger->debug("Display type $displayType ");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment