Merge pull request #12 from holczert/master

Support for multiple LDAP servers
This commit is contained in:
Marco Huenseler 2020-06-18 12:28:20 +02:00 committed by GitHub
commit 3f9e1bf08f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View File

@ -8,7 +8,7 @@ You will need to set a few options inside your radicale config file. Example:
[auth] [auth]
type = radicale_auth_ldap type = radicale_auth_ldap
# LDAP server URL, with protocol and port # LDAP server URL, with protocol and port (multiple servers can be separated by spaces)
ldap_url = ldap://ldap:389 ldap_url = ldap://ldap:389
# LDAP base path # LDAP base path

View File

@ -37,7 +37,16 @@ import radicale_auth_ldap.ldap3imports
class Auth(BaseAuth): class Auth(BaseAuth):
def is_authenticated(self, user, password): def is_authenticated(self, user, password):
"""Check if ``user``/``password`` couple is valid.""" """Check if ``user``/``password`` couple is valid."""
SERVER = ldap3.Server(self.configuration.get("auth", "ldap_url")) servers = self.configuration.get("auth", "ldap_url")
if ' ' in servers: # Handle for multiple LDAP server defined in ldap_url with space separation
servers = servers.split(' ')
self.logger.debug("Multiple servers: %s" % servers)
SERVER = ldap3.ServerPool(None)
for s in servers:
SERVER.add(ldap3.Server(s))
else: # only one server is defined
self.logger.debug("Single server: %s" % servers)
SERVER = ldap3.Server(servers)
BASE = self.configuration.get("auth", "ldap_base") BASE = self.configuration.get("auth", "ldap_base")
ATTRIBUTE = self.configuration.get("auth", "ldap_attribute") ATTRIBUTE = self.configuration.get("auth", "ldap_attribute")
FILTER = self.configuration.get("auth", "ldap_filter") FILTER = self.configuration.get("auth", "ldap_filter")