1015 |
1015 |
attribute = attribute.split(':', 1)[0]
|
1016 |
1016 |
yield attribute
|
1017 |
1017 |
|
|
1018 |
@classmethod
|
|
1019 |
def get_user_filter(cls, block):
|
|
1020 |
user_filter = force_text(block['sync_ldap_users_filter'] or block['user_filter'])
|
|
1021 |
user_filter = user_filter.replace('%s', '*')
|
|
1022 |
return user_filter
|
|
1023 |
|
1018 |
1024 |
@classmethod
|
1019 |
1025 |
def get_ldap_attributes_names(cls, block):
|
1020 |
1026 |
attributes = set()
|
... | ... | |
1309 |
1315 |
logger.warning(u'unable to synchronize with LDAP servers %s', force_text(block['url']))
|
1310 |
1316 |
continue
|
1311 |
1317 |
user_basedn = force_text(block.get('user_basedn') or block['basedn'])
|
1312 |
|
user_filter = force_text(block['sync_ldap_users_filter'] or block['user_filter'])
|
1313 |
|
user_filter = user_filter.replace('%s', '*')
|
|
1318 |
user_filter = cls.get_user_filter(block)
|
1314 |
1319 |
attribute_names = cls.get_ldap_attributes_names(block)
|
1315 |
1320 |
results = cls.paged_search(conn, user_basedn, ldap.SCOPE_SUBTREE, user_filter, attrlist=attribute_names)
|
1316 |
1321 |
backend = cls()
|
... | ... | |
1318 |
1323 |
yield backend._return_user(dn, None, conn, block, attrs)
|
1319 |
1324 |
|
1320 |
1325 |
|
|
1326 |
@classmethod
|
|
1327 |
def deactivate_orphaned_users(cls):
|
|
1328 |
for block in cls.get_config():
|
|
1329 |
conn = cls.get_connection(block)
|
|
1330 |
if conn is None:
|
|
1331 |
continue
|
|
1332 |
eids = list(UserExternalId.objects.filter(user__is_active=True,
|
|
1333 |
source=block['realm']).values_list('external_id', flat=True))
|
|
1334 |
basedn = force_text(block.get('user_basedn') or block['basedn'])
|
|
1335 |
attribute_names = cls.get_ldap_attributes_names(block)
|
|
1336 |
user_filter = cls.get_user_filter(block)
|
|
1337 |
results = cls.paged_search(conn, basedn, ldap.SCOPE_SUBTREE,
|
|
1338 |
user_filter,
|
|
1339 |
attrlist=attribute_names)
|
|
1340 |
for dn, attrs in results:
|
|
1341 |
data = attrs.copy()
|
|
1342 |
data['dn'] = dn
|
|
1343 |
for eid_tuple in map_text(block['external_id_tuples']):
|
|
1344 |
backend = cls()
|
|
1345 |
external_id = backend.build_external_id(eid_tuple, data)
|
|
1346 |
if external_id:
|
|
1347 |
try:
|
|
1348 |
eids.remove(external_id)
|
|
1349 |
except ValueError:
|
|
1350 |
pass
|
|
1351 |
for eid in UserExternalId.objects.filter(external_id__in=eids):
|
|
1352 |
eid.user.mark_as_inactive()
|
|
1353 |
|
|
1354 |
|
1321 |
1355 |
@classmethod
|
1322 |
1356 |
def ad_encoding(cls, s):
|
1323 |
1357 |
'''Encode a string for AD consumption as a password'''
|