jwutils.ldap: Add module

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2025-07-26 13:51:42 +02:00
commit 1e43cdc715
2 changed files with 300 additions and 17 deletions

View file

@ -5,7 +5,7 @@ from typing import Optional, Union
import ldap
from ...log import *
from ... import Config
from ...ldap import bind
from .. import Access
from .. import Auth as AuthBase
from .. import Group as GroupBase
@ -62,22 +62,7 @@ class Auth(AuthBase): # export
self.__dummy = self.load('dummy', conf)
def __bind(self):
ldap_uri = self.conf['ldap_uri']
bind_dn = self.conf['bind_dn']
bind_pw = self.conf.get('password')
if bind_pw is None:
with open(ldap_secret_file, 'r') as file:
bind_pw = file.read()
file.closed
bind_pw = bind_pw.strip()
ret = ldap.initialize(ldap_uri)
ret.start_tls_s()
try:
rr = ret.bind_s(bind_dn, bind_pw) # method)
except Exception as e:
#pw = f' (pw={bind_pw})'
raise Exception(f'Failed to bind to {ldap_uri} with dn {bind_dn} ({e})')
return ret
return bind(self.conf)
@property
def __users(self) -> User: