Compare commits
No commits in common. "feat/ldap" and "7dc733630b0c959618f2c2bf2d46ecccdef87cdb" have entirely different histories.
feat/ldap
...
7dc733630b
@ -172,8 +172,6 @@ if any(os.path.isfile(x) for x in config_locations):
|
|||||||
LDAP_FILTER = ldap.get("filter", "")
|
LDAP_FILTER = ldap.get("filter", "")
|
||||||
LDAP_BIND_DN = ldap.get("bind_dn", "")
|
LDAP_BIND_DN = ldap.get("bind_dn", "")
|
||||||
LDAP_BIND_PW = ldap.get("bind_pw", "")
|
LDAP_BIND_PW = ldap.get("bind_pw", "")
|
||||||
LDAP_BIND_PW_FILE = ldap.get("bind_pw_file", "")
|
|
||||||
LDAP_CACHE_TTL = ldap.get("cache_ttl", "")
|
|
||||||
|
|
||||||
# Configure EteBase to use LDAP
|
# Configure EteBase to use LDAP
|
||||||
ETEBASE_CREATE_USER_FUNC = "myauth.ldap.create_user"
|
ETEBASE_CREATE_USER_FUNC = "myauth.ldap.create_user"
|
||||||
|
@ -36,25 +36,9 @@ class LDAPConnection:
|
|||||||
self.__LDAP_FILTER = ldap_setting("FILTER", "")
|
self.__LDAP_FILTER = ldap_setting("FILTER", "")
|
||||||
self.__LDAP_SEARCH_BASE = ldap_setting("SEARCH_BASE", "")
|
self.__LDAP_SEARCH_BASE = ldap_setting("SEARCH_BASE", "")
|
||||||
|
|
||||||
# The time a cache entry is valid (in hours)
|
|
||||||
try:
|
|
||||||
self.__LDAP_CACHE_TTL = int(ldap_setting("CACHE_TTL", ""))
|
|
||||||
except ValueError:
|
|
||||||
logging.error("Invalid value for cache_ttl. Defaulting to 1 hour")
|
|
||||||
self.__LDAP_CACHE_TTL = 1
|
|
||||||
|
|
||||||
password = ldap_setting("BIND_PW", "")
|
|
||||||
if not password:
|
|
||||||
pw_file = ldap_setting("BIND_PW_FILE", "")
|
|
||||||
if pw_file:
|
|
||||||
with open(pw_file, "r") as f:
|
|
||||||
password = f.read().replace("\n", "")
|
|
||||||
else:
|
|
||||||
logging.error("No bind password specified")
|
|
||||||
|
|
||||||
self.__ldap_connection = ldap.initialize(ldap_setting("SERVER", ""))
|
self.__ldap_connection = ldap.initialize(ldap_setting("SERVER", ""))
|
||||||
try:
|
try:
|
||||||
self.__ldap_connection.simple_bind_s(ldap_setting("BIND_DN", ""), password)
|
self.__ldap_connection.simple_bind_s(ldap_setting("BIND_DN", ""), ldap_setting("BIND_PW", ""))
|
||||||
except ldap.LDAPError as err:
|
except ldap.LDAPError as err:
|
||||||
logging.error(f"LDAP Error occuring during bind: {err.desc}")
|
logging.error(f"LDAP Error occuring during bind: {err.desc}")
|
||||||
|
|
||||||
@ -91,7 +75,7 @@ class LDAPConnection:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
if len(result) == 1:
|
if len(result) == 1:
|
||||||
self.__user_cache[username] = timezone.now() + timezone.timedelta(hours=self.__LDAP_CACHE_TTL)
|
self.__user_cache[username] = timezone.now() + timezone.timedelta(hours=1)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user