Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for multiple LDAP servers #12

Merged
merged 5 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ You will need to set a few options inside your radicale config file. Example:
[auth]
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 base path
Expand Down
13 changes: 11 additions & 2 deletions radicale_auth_ldap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,24 @@
class Auth(BaseAuth):
def is_authenticated(self, user, password):
"""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")
ATTRIBUTE = self.configuration.get("auth", "ldap_attribute")
FILTER = self.configuration.get("auth", "ldap_filter")
BINDDN = self.configuration.get("auth", "ldap_binddn")
PASSWORD = self.configuration.get("auth", "ldap_password")
SCOPE = self.configuration.get("auth", "ldap_scope")
SUPPORT_EXTENDED = self.configuration.getboolean("auth", "ldap_support_extended", fallback=True)

if BINDDN and PASSWORD:
conn = ldap3.Connection(SERVER, BINDDN, PASSWORD)
else:
Expand Down