From 881305cc870087f88d40c18454e0446d84997899 Mon Sep 17 00:00:00 2001 From: MichaelDaum Date: Fri, 24 Nov 2017 09:50:18 +0100 Subject: [PATCH] Item14538: simplified patch, added config settings --- data/System/LdapContrib.txt | 2 ++ lib/Foswiki/Contrib/LdapContrib.pm | 35 +++++++++------------ lib/Foswiki/Contrib/LdapContrib/Config.spec | 11 +++++-- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/data/System/LdapContrib.txt b/data/System/LdapContrib.txt index 0182ae0..eb62866 100644 --- a/data/System/LdapContrib.txt +++ b/data/System/LdapContrib.txt @@ -499,6 +499,8 @@ This work is partly sponsored by ---++ Change History %TABLE{columnwidths="7em" tablewidth="100%"}% +| 25 Nov 2017: | added feature to specify multiple LDAP servers; \ + added connection timeout | | 10 Oct 2017: | fixed encoding errors of uncicode DN paths | | 30 Aug 2017: | fixed checking local groups; fixed recoding values coming from the LDAP directory | | 16 Jan 2017: | fixed logging in via email using an ldap-apache login manager | diff --git a/lib/Foswiki/Contrib/LdapContrib.pm b/lib/Foswiki/Contrib/LdapContrib.pm index 8061e34..4d971ac 100644 --- a/lib/Foswiki/Contrib/LdapContrib.pm +++ b/lib/Foswiki/Contrib/LdapContrib.pm @@ -30,8 +30,8 @@ use Encode (); use Foswiki::Func (); use Foswiki::Plugins (); -our $VERSION = '7.80'; -our $RELEASE = '10 Oct 2017'; +our $VERSION = '7.90'; +our $RELEASE = '24 Nov 2017'; our $SHORTDESCRIPTION = 'LDAP services for Foswiki'; our $NO_PREFS_IN_TOPIC = 1; our %sharedLdapContrib; @@ -155,6 +155,7 @@ sub new { host => $Foswiki::cfg{Ldap}{Host} || 'localhost', base => $Foswiki::cfg{Ldap}{Base} || '', port => $Foswiki::cfg{Ldap}{Port} || 389, + timeout => $Foswiki::cfg{Ldap}{Timeout} || 5, version => $Foswiki::cfg{Ldap}{Version} || 3, ipv6 => $Foswiki::cfg{Ldap}{IPv6} || 0, ignoreReferrals => $Foswiki::cfg{Ldap}{IgnoreReferrals} || 0, @@ -355,25 +356,17 @@ sub connect { if ( $host =~ /,/) { # This server preference list relies on the behaviour of Net::LDAP # ldap://, ldaps:// URIs or host:port pairs are valid - my @hosts = split (/,/, $host); - $this->{ldap} = Net::LDAP->new( - \@hosts, - port => $port, - version => $this->{version}, - inet4 => ($this->{ipv6}?0:1), - inet6 => ($this->{ipv6}?1:0), - timeout => 5, # TODO: make configurable - ); - } else { - $this->{ldap} = Net::LDAP->new( - $host, - port => $port, - version => $this->{version}, - inet4 => ($this->{ipv6}?0:1), - inet6 => ($this->{ipv6}?1:0), - timeout => 5, # TODO: make configurable - ); - } + $host = [split (/\s*,\s*/, $host)]; + } + + $this->{ldap} = Net::LDAP->new( + $host, + port => $port, + version => $this->{version}, + inet4 => ($this->{ipv6}?0:1), + inet6 => ($this->{ipv6}?1:0), + timeout => $this->{timeout}, + ); unless ($this->{ldap}) { $this->{error} = "failed to connect to $this->{host}"; diff --git a/lib/Foswiki/Contrib/LdapContrib/Config.spec b/lib/Foswiki/Contrib/LdapContrib/Config.spec index b8d4d81..57bdd7e 100644 --- a/lib/Foswiki/Contrib/LdapContrib/Config.spec +++ b/lib/Foswiki/Contrib/LdapContrib/Config.spec @@ -11,13 +11,20 @@ # ---+++ Connection settings # **STRING** -# IP address (or hostname) of the LDAP server +# IP address (or hostname) of one or multiple LDAP servers. Multiple server URIs may be specified +# comma separated. Each will be tried in order until a connection is made. Please note that the +# system might slow down considerably if some of the servers are not reachable. $Foswiki::cfg{Ldap}{Host} = 'ldap.my.domain.com'; # **NUMBER** -# Port used when binding to the LDAP server +# Port used when binding to the LDAP server. Note that this setting is overridden by any port specification +# part of the Host URI(s). $Foswiki::cfg{Ldap}{Port} = 389; +# **NUMBER** +# Connection timeout talking to the LDAP server. +$Foswiki::cfg{Ldap}{Timeout} = 5; + # **BOOLEAN** # Switch on this flag to enable IPv6 support when connecting to the LDAP server. # Note that IPv6+SSL is still considered experimental. When disabled a normal IPv4 connection is established.