-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"""Module for interacting with LDAP identity provider.""" | ||
|
||
import ldap | ||
from django.conf import settings | ||
|
||
|
||
def get_uid_from_ldap(username: str) -> int: | ||
"""Retrieve the UID from LDAP for a given username. | ||
Args: | ||
username: The username to search for in LDAP. | ||
Returns: | ||
The UID number associated with the given username. | ||
""" | ||
conn = ldap.initialize(settings.LDAP_SERVER_URI) | ||
conn.set_option(ldap.OPT_REFERRALS, 0) | ||
conn.set_option(ldap.OPT_PROTOCOL_VERSION, 3) | ||
conn.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_ALLOW) | ||
result = conn.search_s( | ||
settings.LDAP_SEARCH_BASE, ldap.SCOPE_SUBTREE, f"(cn={username})", ["uidNumber"] | ||
) | ||
return int(result[0][1]["uidNumber"][0].decode("utf-8")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
"""Plugin settings that are imported into the global settings namespace of Coldfront.""" | ||
|
||
from coldfront.config.env import ENV | ||
|
||
LDAP_SERVER_URI = ENV.str("LDAP_SERVER_URI", default="") | ||
LDAP_SEARCH_BASE = ENV.str("LDAP_SEARCH_BASE", default="") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters