|
@@ -170,6 +170,7 @@ async def ldap_auth(request: Request, response: Response, form_data: LdapForm):
|
|
|
LDAP_SERVER_LABEL = request.app.state.config.LDAP_SERVER_LABEL
|
|
|
LDAP_SERVER_HOST = request.app.state.config.LDAP_SERVER_HOST
|
|
|
LDAP_SERVER_PORT = request.app.state.config.LDAP_SERVER_PORT
|
|
|
+ LDAP_ATTRIBUTE_FOR_MAIL = request.app.state.config.LDAP_ATTRIBUTE_FOR_MAIL
|
|
|
LDAP_ATTRIBUTE_FOR_USERNAME = request.app.state.config.LDAP_ATTRIBUTE_FOR_USERNAME
|
|
|
LDAP_SEARCH_BASE = request.app.state.config.LDAP_SEARCH_BASE
|
|
|
LDAP_SEARCH_FILTERS = request.app.state.config.LDAP_SEARCH_FILTERS
|
|
@@ -218,7 +219,11 @@ async def ldap_auth(request: Request, response: Response, form_data: LdapForm):
|
|
|
search_success = connection_app.search(
|
|
|
search_base=LDAP_SEARCH_BASE,
|
|
|
search_filter=f"(&({LDAP_ATTRIBUTE_FOR_USERNAME}={escape_filter_chars(form_data.user.lower())}){LDAP_SEARCH_FILTERS})",
|
|
|
- attributes=[f"{LDAP_ATTRIBUTE_FOR_USERNAME}", "mail", "cn"],
|
|
|
+ attributes=[
|
|
|
+ f"{LDAP_ATTRIBUTE_FOR_USERNAME}",
|
|
|
+ f"{LDAP_ATTRIBUTE_FOR_MAIL}",
|
|
|
+ "cn",
|
|
|
+ ],
|
|
|
)
|
|
|
|
|
|
if not search_success:
|
|
@@ -226,7 +231,9 @@ async def ldap_auth(request: Request, response: Response, form_data: LdapForm):
|
|
|
|
|
|
entry = connection_app.entries[0]
|
|
|
username = str(entry[f"{LDAP_ATTRIBUTE_FOR_USERNAME}"]).lower()
|
|
|
- mail = str(entry["mail"])
|
|
|
+ mail = str(entry[f"{LDAP_ATTRIBUTE_FOR_MAIL}"])
|
|
|
+ if not mail or mail == "" or mail == "[]":
|
|
|
+ raise HTTPException(400, f"User {form_data.user} does not have mail.")
|
|
|
cn = str(entry["cn"])
|
|
|
user_dn = entry.entry_dn
|
|
|
|
|
@@ -691,6 +698,7 @@ class LdapServerConfig(BaseModel):
|
|
|
label: str
|
|
|
host: str
|
|
|
port: Optional[int] = None
|
|
|
+ attribute_for_mail: str = "mail"
|
|
|
attribute_for_username: str = "uid"
|
|
|
app_dn: str
|
|
|
app_dn_password: str
|
|
@@ -707,6 +715,7 @@ async def get_ldap_server(request: Request, user=Depends(get_admin_user)):
|
|
|
"label": request.app.state.config.LDAP_SERVER_LABEL,
|
|
|
"host": request.app.state.config.LDAP_SERVER_HOST,
|
|
|
"port": request.app.state.config.LDAP_SERVER_PORT,
|
|
|
+ "attribute_for_mail": request.app.state.config.LDAP_ATTRIBUTE_FOR_MAIL,
|
|
|
"attribute_for_username": request.app.state.config.LDAP_ATTRIBUTE_FOR_USERNAME,
|
|
|
"app_dn": request.app.state.config.LDAP_APP_DN,
|
|
|
"app_dn_password": request.app.state.config.LDAP_APP_PASSWORD,
|
|
@@ -725,6 +734,7 @@ async def update_ldap_server(
|
|
|
required_fields = [
|
|
|
"label",
|
|
|
"host",
|
|
|
+ "attribute_for_mail",
|
|
|
"attribute_for_username",
|
|
|
"app_dn",
|
|
|
"app_dn_password",
|
|
@@ -743,6 +753,7 @@ async def update_ldap_server(
|
|
|
request.app.state.config.LDAP_SERVER_LABEL = form_data.label
|
|
|
request.app.state.config.LDAP_SERVER_HOST = form_data.host
|
|
|
request.app.state.config.LDAP_SERVER_PORT = form_data.port
|
|
|
+ request.app.state.config.LDAP_ATTRIBUTE_FOR_MAIL = form_data.attribute_for_mail
|
|
|
request.app.state.config.LDAP_ATTRIBUTE_FOR_USERNAME = (
|
|
|
form_data.attribute_for_username
|
|
|
)
|
|
@@ -758,6 +769,7 @@ async def update_ldap_server(
|
|
|
"label": request.app.state.config.LDAP_SERVER_LABEL,
|
|
|
"host": request.app.state.config.LDAP_SERVER_HOST,
|
|
|
"port": request.app.state.config.LDAP_SERVER_PORT,
|
|
|
+ "attribute_for_mail": request.app.state.config.LDAP_ATTRIBUTE_FOR_MAIL,
|
|
|
"attribute_for_username": request.app.state.config.LDAP_ATTRIBUTE_FOR_USERNAME,
|
|
|
"app_dn": request.app.state.config.LDAP_APP_DN,
|
|
|
"app_dn_password": request.app.state.config.LDAP_APP_PASSWORD,
|