sources/ldap: use dn attribute for distinguishedName, ignore users with no distinguishedName

closes #527
This commit is contained in:
Jens Langhammer 2021-02-04 12:10:57 +01:00
parent add20de8de
commit cc3fccb27e
2 changed files with 10 additions and 3 deletions

View File

@ -185,7 +185,10 @@ class LDAPSynchronizer:
properties["attributes"]["ldap_uniq"] = attributes.get( properties["attributes"]["ldap_uniq"] = attributes.get(
self._source.object_uniqueness_field self._source.object_uniqueness_field
) )
properties["attributes"]["distinguishedName"] = attributes.get( distinguished_name = attributes.get("distinguishedName", attributes.get("dn"))
"distinguishedName" if not distinguished_name:
raise IntegrityError(
"Object does not have a distinguishedName or dn field."
) )
properties["attributes"]["distinguishedName"] = distinguished_name
return properties return properties

View File

@ -53,6 +53,7 @@ def _build_mock_connection(password: str) -> Connection:
"objectSid": "user0", "objectSid": "user0",
"objectCategory": "Person", "objectCategory": "Person",
"memberOf": "cn=group1,ou=groups,DC=AD2012,DC=LAB", "memberOf": "cn=group1,ou=groups,DC=AD2012,DC=LAB",
"distinguishedName": "cn=user0,ou=users,DC=AD2012,DC=LAB",
}, },
) )
# User without SID # User without SID
@ -64,6 +65,7 @@ def _build_mock_connection(password: str) -> Connection:
"name": "user1_sn", "name": "user1_sn",
"revision": 0, "revision": 0,
"objectCategory": "Person", "objectCategory": "Person",
"distinguishedName": "cn=user1,ou=users,DC=AD2012,DC=LAB",
}, },
) )
# Duplicate users # Duplicate users
@ -76,6 +78,7 @@ def _build_mock_connection(password: str) -> Connection:
"revision": 0, "revision": 0,
"objectSid": "unique-test2222", "objectSid": "unique-test2222",
"objectCategory": "Person", "objectCategory": "Person",
"distinguishedName": "cn=user2,ou=users,DC=AD2012,DC=LAB",
}, },
) )
connection.strategy.add_entry( connection.strategy.add_entry(
@ -87,6 +90,7 @@ def _build_mock_connection(password: str) -> Connection:
"revision": 0, "revision": 0,
"objectSid": "unique-test2222", "objectSid": "unique-test2222",
"objectCategory": "Person", "objectCategory": "Person",
"distinguishedName": "cn=user3,ou=users,DC=AD2012,DC=LAB",
}, },
) )
connection.bind() connection.bind()