Skip to content

Commit 04907b4

Browse files
committed
Reset the selection order of NameID Format value in the saml frontend
Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent a1f9526 commit 04907b4

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

src/satosa/frontends/saml2.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -198,25 +198,36 @@ def _handle_authn_request(self, context, binding_in, idp):
198198
context.state[self.name] = self._create_state_data(context, idp.response_args(authn_req),
199199
context.request.get("RelayState"))
200200

201-
if authn_req.name_id_policy and authn_req.name_id_policy.format:
202-
name_format = authn_req.name_id_policy.format
203-
else:
204-
# default to name id format from metadata, or just transient name id
205-
name_format_from_metadata = idp.metadata[requester]["spsso_descriptor"][0].get("name_id_format")
206-
if name_format_from_metadata:
207-
name_format = name_format_from_metadata[0]["text"]
208-
else:
209-
name_format = NAMEID_FORMAT_TRANSIENT
210-
211201
subject = authn_req.subject
212-
subject_id = subject.name_id.text if subject else None
213-
# XXX should subject.name_id.format overwrite name_id_policy.format?
214-
subject_type = subject.name_id.format if subject else name_format
202+
name_id_value = subject.name_id.text if subject else None
203+
204+
nameid_formats = {
205+
"from_policy": authn_req.name_id_policy and authn_req.name_id_policy.format,
206+
"from_response": subject and subject.name_id and subject.name_id.format,
207+
"from_metadata": (
208+
idp.metadata[requester]
209+
.get("spsso_descriptor", [{}])[0]
210+
.get("name_id_format", [{}])[0]
211+
.get("text")
212+
),
213+
"default": NAMEID_FORMAT_TRANSIENT,
214+
}
215+
216+
name_id_format = (
217+
nameid_formats["from_policy"]
218+
or (
219+
nameid_formats["from_response"] != NAMEID_FORMAT_UNSPECIFIED
220+
and nameid_formats["from_response"]
221+
)
222+
or nameid_formats["from_metadata"]
223+
or nameid_formats["from_response"]
224+
or nameid_formats["default"]
225+
)
215226

216227
requester_name = self._get_sp_display_name(idp, requester)
217228
internal_req = InternalData(
218-
subject_id=subject_id,
219-
subject_type=subject_type,
229+
subject_id=name_id_value,
230+
subject_type=name_id_format,
220231
requester=requester,
221232
requester_name=requester_name,
222233
)

0 commit comments

Comments
 (0)