sources/ldap: better handle property mapping evaluation errors

This commit is contained in:
Jens Langhammer 2020-02-18 10:13:05 +01:00
parent 813b2676de
commit 95416623b3
1 changed files with 9 additions and 4 deletions

View File

@ -5,8 +5,9 @@ import ldap3
import ldap3.core.exceptions import ldap3.core.exceptions
from structlog import get_logger from structlog import get_logger
from passbook.core.exceptions import PropertyMappingExpressionException
from passbook.core.models import Group, User from passbook.core.models import Group, User
from passbook.sources.ldap.models import LDAPSource, LDAPPropertyMapping from passbook.sources.ldap.models import LDAPPropertyMapping, LDAPSource
LOGGER = get_logger() LOGGER = get_logger()
@ -155,9 +156,13 @@ class Connector:
properties = {"attributes": {}} properties = {"attributes": {}}
for mapping in self._source.property_mappings.all().select_subclasses(): for mapping in self._source.property_mappings.all().select_subclasses():
mapping: LDAPPropertyMapping mapping: LDAPPropertyMapping
try:
properties[mapping.object_field] = mapping.evaluate( properties[mapping.object_field] = mapping.evaluate(
user=None, request=None, ldap=attributes user=None, request=None, ldap=attributes
) )
except PropertyMappingExpressionException as exc:
LOGGER.warning(exc)
continue
if self._source.object_uniqueness_field in attributes: if self._source.object_uniqueness_field in attributes:
properties["attributes"]["ldap_uniq"] = attributes.get( properties["attributes"]["ldap_uniq"] = attributes.get(
self._source.object_uniqueness_field self._source.object_uniqueness_field