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

ldaps WIP #84

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 8 additions & 1 deletion config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@
import ldap
from django_auth_ldap.config import LDAPSearch

ldap.set_option(ldap.OPT_DEBUG_LEVEL, 255)
# Temporarily disable cert checking
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)

# Default values
LDAP_DEFAULT_CONN_OPTIONS = {ldap.OPT_REFERRALS: 0}
LDAP_DEFAULT_FILTERSTR = "(sAMAccountName=%(user)s)"
Expand All @@ -335,8 +339,10 @@
AUTH_LDAP_SERVER_URI = env.str("AUTH_LDAP_SERVER_URI", None)
AUTH_LDAP_BIND_DN = env.str("AUTH_LDAP_BIND_DN", None)
AUTH_LDAP_BIND_PASSWORD = env.str("AUTH_LDAP_BIND_PASSWORD", None)
AUTH_LDAP_CONNECTION_OPTIONS = LDAP_DEFAULT_CONN_OPTIONS
AUTH_LDAP_START_TLS = env.bool("AUTH_LDAP_START_TLS", False)
AUTH_LDAP_CONNECTION_OPTIONS = {**LDAP_DEFAULT_CONN_OPTIONS}

AUTH_LDAP_USER_FILTER = env.str("AUTH_LDAP_USER_FILTER", "(sAMAccountName=%(user)s)")
AUTH_LDAP_USER_SEARCH_BASE = env.str("AUTH_LDAP_USER_SEARCH_BASE", None)
AUTH_LDAP_USER_SEARCH = LDAPSearch(
AUTH_LDAP_USER_SEARCH_BASE, ldap.SCOPE_SUBTREE, LDAP_DEFAULT_FILTERSTR
Expand All @@ -354,6 +360,7 @@
AUTH_LDAP2_SERVER_URI = env.str("AUTH_LDAP2_SERVER_URI", None)
AUTH_LDAP2_BIND_DN = env.str("AUTH_LDAP2_BIND_DN", None)
AUTH_LDAP2_BIND_PASSWORD = env.str("AUTH_LDAP2_BIND_PASSWORD", None)
AUTH_LDAP_START_TLS = env.bool("AUTH_LDAP_START_TLS", False)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be LDAP2, right?

AUTH_LDAP2_CONNECTION_OPTIONS = LDAP_DEFAULT_CONN_OPTIONS

AUTH_LDAP2_USER_SEARCH_BASE = env.str("AUTH_LDAP2_USER_SEARCH_BASE", None)
Expand Down
2 changes: 2 additions & 0 deletions fileboxes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ def _form_valid_ldap(self, accounts):
ldap_conn = ldap.initialize(settings.AUTH_LDAP_SERVER_URI)
ldap_conn.set_option(ldap.OPT_REFERRALS, ldap.OPT_OFF)
ldap_conn.set_option(ldap.OPT_TIMEOUT, 5)
ldap_conn.start_tls_s()
ldap_conn.simple_bind_s(settings.AUTH_LDAP_BIND_DN, settings.AUTH_LDAP_BIND_PASSWORD)
ldap_conns.append(
(settings.AUTH_LDAP_USERNAME_DOMAIN, settings.AUTH_LDAP_USER_SEARCH_BASE, ldap_conn)
Expand All @@ -279,6 +280,7 @@ def _form_valid_ldap(self, accounts):
ldap_conn = ldap.initialize(settings.AUTH_LDAP2_SERVER_URI)
ldap_conn.set_option(ldap.OPT_REFERRALS, ldap.OPT_OFF)
ldap_conn.set_option(ldap.OPT_TIMEOUT, 5)
ldap_conn.start_tls_s()
ldap_conn.simple_bind_s(settings.AUTH_LDAP2_BIND_DN, settings.AUTH_LDAP2_BIND_PASSWORD)
ldap_conns.append(
(
Expand Down
2 changes: 1 addition & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ selenium==4.1.0
beautifulsoup4==4.10.0

# Black for formatting
black==22.1.0
black==22.3.0