Skip to content

Commit 01c0def

Browse files
skorandac00kiemon5ter
authored andcommitted
Separate LDAP query return attributes from mapping to internal attributes
The config option search_return_attributes for the LDAP attribute store conflated what attribute values to return from the LDAP query with how those values should be mapped to internal attributes. This commit separates the functionality by introducing two new config options, query_return_attributes and ldap_to_internal_map. The search_return_attributes option is still supported for backwards compatibility.
1 parent d013eb1 commit 01c0def

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

example/plugins/microservices/ldap_attribute_store.yaml.example

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,30 @@ config:
99
read_only : true
1010
version : 3
1111

12-
# see ldap3 client_strategies
12+
# See ldap3 client_strategies.
1313
client_strategy : RESTARTABLE
1414
auto_bind : true
1515
pool_size : 10
1616
pool_keepalive : 10
1717

18+
# Attributes to return from LDAP query.
19+
query_return_attributes:
20+
- sn
21+
- givenName
22+
- mail
23+
- employeeNumber
24+
- isMemberOf
25+
26+
# LDAP attribute to internal attribute mapping.
27+
ldap_to_internal_map:
28+
sn: surname
29+
givenName: givenname
30+
mail: mail
31+
employeeNumber: employeenumber
32+
isMemberOf: ismemberof
33+
34+
# Deprecated. Use query_return_attributes and
35+
# ldap_to_internal_map instead.
1836
search_return_attributes:
1937
# Format is LDAP attribute name : internal attribute name
2038
sn: surname

src/satosa/micro_services/ldap_attribute_store.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ class LdapAttributeStore(ResponseMicroService):
4242
'ignore': False,
4343
'ldap_identifier_attribute': None,
4444
'ldap_url': None,
45+
'ldap_to_internal_map': None,
4546
'on_ldap_search_result_empty': None,
4647
'ordered_identifier_candidates': None,
4748
'search_base': None,
49+
'query_return_attributes': None,
4850
'search_return_attributes': None,
4951
'user_id_from_attrs': [],
5052
'read_only': True,
@@ -328,11 +330,15 @@ def _populate_attributes(self, config, record, context, data):
328330
state = context.state
329331
attributes = data.attributes
330332

331-
search_return_attributes = config['search_return_attributes']
332-
for attr in search_return_attributes.keys():
333+
if config['ldap_to_internal_map']:
334+
ldap_to_internal_map = config['ldap_to_internal_map']
335+
else:
336+
# Deprecated configuration. Will be removed in future.
337+
ldap_to_internal_map = config['search_return_attributes']
338+
for attr in ldap_to_internal_map.keys():
333339
if attr in record["attributes"]:
334340
if record["attributes"][attr]:
335-
internal_attr = search_return_attributes[attr]
341+
internal_attr = ldap_to_internal_map[attr]
336342
value = record["attributes"][attr]
337343
attributes[internal_attr] = value
338344
msg = "Setting internal attribute {} with values {}"
@@ -450,7 +456,11 @@ def process(self, context, data):
450456

451457
try:
452458
# message_id only works in REUSABLE async connection strategy.
453-
attributes = config['search_return_attributes'].keys()
459+
if config['query_return_attributes']:
460+
attributes = config['query_return_attributes']
461+
else:
462+
# Deprecated configuration. Will be removed in future.
463+
attributes = config['search_return_attributes'].keys()
454464
results = connection.search(config['search_base'],
455465
search_filter,
456466
attributes=attributes

0 commit comments

Comments
 (0)