Skip to content

Commit 92fc670

Browse files
committed
Redo _populate_attributes
Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent 39bbbc7 commit 92fc670

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

src/satosa/micro_services/ldap_attribute_store.py

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -329,32 +329,24 @@ def _ldap_connection_factory(self, config):
329329

330330
return connection
331331

332-
def _populate_attributes(self, config, record, context, data):
332+
def _populate_attributes(self, config, record):
333333
"""
334334
Use a record found in LDAP to populate attributes.
335335
"""
336-
state = context.state
337-
attributes = data.attributes
338-
339-
if config["ldap_to_internal_map"]:
340-
ldap_to_internal_map = config["ldap_to_internal_map"]
341-
else:
336+
ldap_to_internal_map = (
337+
config["ldap_to_internal_map"]
338+
if config["ldap_to_internal_map"]
342339
# Deprecated configuration. Will be removed in future.
343-
ldap_to_internal_map = config["search_return_attributes"]
344-
for attr in ldap_to_internal_map.keys():
345-
if attr in record["attributes"]:
346-
if record["attributes"][attr]:
347-
internal_attr = ldap_to_internal_map[attr]
348-
value = record["attributes"][attr]
349-
attributes[internal_attr] = value
350-
msg = "Setting internal attribute {} with values {}"
351-
msg = msg.format(internal_attr, value)
352-
satosa_logging(logger, logging.DEBUG, msg, state)
353-
else:
354-
msg = "Not setting internal attribute {} because value {}"
355-
msg = msg + " is null or empty"
356-
msg = msg.format(internal_attr, value)
357-
satosa_logging(logger, logging.DEBUG, msg, state)
340+
else config["search_return_attributes"]
341+
)
342+
343+
new_attr_values = {
344+
internal_attr: value
345+
for attr, internal_attr in ldap_to_internal_map.items()
346+
for value in [record["attributes"].get(attr)]
347+
if value
348+
}
349+
return new_attr_values
358350

359351
def _populate_input_for_name_id(self, config, record, context, data):
360352
"""
@@ -546,7 +538,9 @@ def process(self, context, data):
546538
satosa_logging(logger, logging.DEBUG, msg, state)
547539

548540
# Populate attributes as configured.
549-
self._populate_attributes(config, record, context, data)
541+
new_attrs = self._populate_attributes(config, record)
542+
msg = "Updating internal attributes with new values {}".format(new_attrs)
543+
satosa_logging(logger, logging.DEBUG, msg, None)
550544

551545
# Populate input for NameID if configured. SATOSA core does the
552546
# hashing of input to create a persistent NameID.

0 commit comments

Comments
 (0)