sources/ldap: fix error during event creation
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
963af1ac1e
commit
1494394a78
|
@ -4,7 +4,7 @@ from typing import Any
|
||||||
from django.db.models.signals import post_save
|
from django.db.models.signals import post_save
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from ldap3.core.exceptions import LDAPException
|
from ldap3.core.exceptions import LDAPException, LDAPOperationResult
|
||||||
from rest_framework.serializers import ValidationError
|
from rest_framework.serializers import ValidationError
|
||||||
|
|
||||||
from authentik.core.models import User
|
from authentik.core.models import User
|
||||||
|
@ -55,10 +55,10 @@ def ldap_sync_password(sender, user: User, password: str, **_):
|
||||||
changer = LDAPPasswordChanger(source)
|
changer = LDAPPasswordChanger(source)
|
||||||
try:
|
try:
|
||||||
changer.change_password(user, password)
|
changer.change_password(user, password)
|
||||||
except LDAPException as exc:
|
except LDAPOperationResult as exc:
|
||||||
Event.new(
|
Event.new(
|
||||||
EventAction.CONFIGURATION_ERROR,
|
EventAction.CONFIGURATION_ERROR,
|
||||||
message=str(exc),
|
message=f"Result: {exc.result}, Description {exc.description}",
|
||||||
source=source,
|
source=source,
|
||||||
).set_user(user).save()
|
).set_user(user).save()
|
||||||
raise ValidationError("Failed to set password") from exc
|
raise ValidationError("Failed to set password") from exc
|
||||||
|
|
Reference in New Issue