Skip to content

Commit 4601181

Browse files
author
Roland Hedberg
committed
Allow adding an AuthnStatement instance to the Assertion construct and Server authn_response methods.
1 parent 7bb9d0a commit 4601181

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/saml2/assertion.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ def construct(self, sp_entity_id, in_response_to, consumer_url,
666666
name_id, attrconvs, policy, issuer, authn_class=None,
667667
authn_auth=None, authn_decl=None, encrypt=None,
668668
sec_context=None, authn_decl_ref=None, authn_instant="",
669-
subject_locality=""):
669+
subject_locality="", authn_statem=None):
670670
""" Construct the Assertion
671671
672672
:param sp_entity_id: The entityid of the SP
@@ -687,6 +687,7 @@ def construct(self, sp_entity_id, in_response_to, consumer_url,
687687
:param subject_locality: Specifies the DNS domain name and IP address
688688
for the system from which the assertion subject was apparently
689689
authenticated.
690+
:param authn_statem: A AuthnStatement instance
690691
:return: An Assertion instance
691692
"""
692693

@@ -711,15 +712,16 @@ def construct(self, sp_entity_id, in_response_to, consumer_url,
711712
# start using now and for some time
712713
conds = policy.conditions(sp_entity_id)
713714

714-
if authn_auth or authn_class or authn_decl or authn_decl_ref:
715+
if authn_statem:
716+
_authn_statement = authn_statem
717+
elif authn_auth or authn_class or authn_decl or authn_decl_ref:
715718
_authn_statement = authn_statement(authn_class, authn_auth,
716719
authn_decl, authn_decl_ref,
717720
authn_instant,
718721
subject_locality)
719722
else:
720723
_authn_statement = None
721724

722-
723725
_ass = assertion_factory(
724726
issuer=issuer,
725727
conditions=conds,

src/saml2/server.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,8 @@ def _authn_response(self, in_response_to, consumer_url,
282282
sp_entity_id, identity=None, name_id=None,
283283
status=None, authn=None, issuer=None, policy=None,
284284
sign_assertion=False, sign_response=False,
285-
best_effort=False, encrypt_assertion=False, encrypt_cert=None):
285+
best_effort=False, encrypt_assertion=False,
286+
encrypt_cert=None, authn_statement=None):
286287
""" Create a response. A layer of indirection.
287288
288289
:param in_response_to: The session identifier of the request
@@ -328,6 +329,12 @@ def _authn_response(self, in_response_to, consumer_url,
328329
self.config.attribute_converters,
329330
policy, issuer=_issuer,
330331
**authn_args)
332+
elif authn_statement: # Got a complete AuthnStatement
333+
assertion = ast.construct(sp_entity_id, in_response_to,
334+
consumer_url, name_id,
335+
self.config.attribute_converters,
336+
policy, issuer=_issuer,
337+
authn_statem=authn_statement)
331338
else:
332339
assertion = ast.construct(sp_entity_id, in_response_to,
333340
consumer_url, name_id,
@@ -427,7 +434,8 @@ def create_attribute_response(self, identity, in_response_to, destination,
427434
def create_authn_response(self, identity, in_response_to, destination,
428435
sp_entity_id, name_id_policy=None, userid=None,
429436
name_id=None, authn=None, issuer=None,
430-
sign_response=None, sign_assertion=None, encrypt_cert=None, encrypt_assertion=None,
437+
sign_response=None, sign_assertion=None,
438+
encrypt_cert=None, encrypt_assertion=None,
431439
**kwargs):
432440
""" Constructs an AuthenticationResponse
433441

0 commit comments

Comments
 (0)