@@ -131,7 +131,9 @@ def __init__(self, config, *args, **kwargs):
131
131
msg = "LDAP Attribute Store microservice initialized"
132
132
satosa_logging (logger , logging .INFO , msg , None )
133
133
134
- def _construct_filter_value (self , candidate , data ):
134
+ def _construct_filter_value (
135
+ self , candidate , name_id_value , name_id_format , issuer , attributes
136
+ ):
135
137
"""
136
138
Construct and return a LDAP directory search filter value from the
137
139
candidate identifier.
@@ -162,40 +164,30 @@ def _construct_filter_value(self, candidate, data):
162
164
entityID for the IdP will be concatenated to "scope" the value. If the
163
165
string is any other value it will be directly concatenated.
164
166
"""
165
- context = self .context
166
- state = context .state
167
-
168
- attributes = data .attributes
169
- msg = "Input attributes {}" .format (attributes )
170
- satosa_logging (logger , logging .DEBUG , msg , state )
171
-
172
167
# Get the values configured list of identifier names for this candidate
173
168
# and substitute None if there are no values for a configured
174
169
# identifier.
175
- values = []
176
- for identifier_name in candidate ["attribute_names" ]:
177
- v = attributes .get (identifier_name , None )
178
- if isinstance (v , list ):
179
- v = v [0 ]
180
- values .append (v )
170
+ values = [
171
+ attr_value [0 ] if isinstance (attr_value , list ) else attr_value
172
+ for identifier_name in candidate ["attribute_names" ]
173
+ for attr_value in [attributes .get (identifier_name )]
174
+ ]
181
175
msg = "Found candidate values {}" .format (values )
182
- satosa_logging (logger , logging .DEBUG , msg , state )
176
+ satosa_logging (logger , logging .DEBUG , msg , None )
183
177
184
178
# If one of the configured identifier names is name_id then if there is
185
179
# also a configured name_id_format add the value for the NameID of that
186
180
# format if it was asserted by the IdP or else add the value None.
187
181
if "name_id" in candidate ["attribute_names" ]:
188
182
candidate_nameid_value = None
189
183
candidate_name_id_format = candidate .get ("name_id_format" )
190
- name_id_value = data .subject_id
191
- name_id_format = data .subject_type
192
184
if (
193
185
name_id_value
194
186
and candidate_name_id_format
195
187
and candidate_name_id_format == name_id_format
196
188
):
197
189
msg = "IdP asserted NameID {}" .format (name_id_value )
198
- satosa_logging (logger , logging .DEBUG , msg , state )
190
+ satosa_logging (logger , logging .DEBUG , msg , None )
199
191
candidate_nameid_value = name_id_value
200
192
201
193
# Only add the NameID value asserted by the IdP if it is not
@@ -206,37 +198,38 @@ def _construct_filter_value(self, candidate, data):
206
198
if candidate_nameid_value not in values :
207
199
msg = "Added NameID {} to candidate values"
208
200
msg = msg .format (candidate_nameid_value )
209
- satosa_logging (logger , logging .DEBUG , msg , state )
201
+ satosa_logging (logger , logging .DEBUG , msg , None )
210
202
values .append (candidate_nameid_value )
211
203
else :
212
204
msg = "NameID {} value also asserted as attribute value"
213
205
msg = msg .format (candidate_nameid_value )
214
- satosa_logging (logger , logging .WARN , msg , state )
206
+ satosa_logging (logger , logging .WARN , msg , None )
215
207
216
208
# If no value was asserted by the IdP for one of the configured list of
217
209
# identifier names for this candidate then go onto the next candidate.
218
210
if None in values :
219
211
msg = "Candidate is missing value so skipping"
220
- satosa_logging (logger , logging .DEBUG , msg , state )
212
+ satosa_logging (logger , logging .DEBUG , msg , None )
221
213
return None
222
214
223
215
# All values for the configured list of attribute names are present
224
216
# so we can create a value. Add a scope if configured
225
217
# to do so.
226
218
if "add_scope" in candidate :
227
- if candidate ["add_scope" ] == "issuer_entityid" :
228
- scope = data .auth_info .issuer
229
- else :
230
- scope = candidate ["add_scope" ]
219
+ scope = (
220
+ issuer
221
+ if candidate ["add_scope" ] == "issuer_entityid"
222
+ else candidate ["add_scope" ]
223
+ )
231
224
msg = "Added scope {} to values" .format (scope )
232
- satosa_logging (logger , logging .DEBUG , msg , state )
225
+ satosa_logging (logger , logging .DEBUG , msg , None )
233
226
values .append (scope )
234
227
235
228
# Concatenate all values to create the filter value.
236
229
value = "" .join (values )
237
230
238
231
msg = "Constructed filter value {}" .format (value )
239
- satosa_logging (logger , logging .DEBUG , msg , state )
232
+ satosa_logging (logger , logging .DEBUG , msg , None )
240
233
241
234
return value
242
235
@@ -443,7 +436,13 @@ def process(self, context, data):
443
436
# and find asserted values to construct the ordered list of values for
444
437
# the LDAP search filters.
445
438
for candidate in config ["ordered_identifier_candidates" ]:
446
- value = self ._construct_filter_value (candidate , data )
439
+ value = self ._construct_filter_value (
440
+ candidate ,
441
+ data .subject_id ,
442
+ data .subject_type ,
443
+ data .auth_info .issuer ,
444
+ data .attriutes ,
445
+ )
447
446
448
447
# If we have constructed a non empty value then add it as the next
449
448
# filter value to use when searching for the user record.
0 commit comments