Skip to content

Commit 3fd7839

Browse files
committed
Refactor do_subject_confirmation and do_subject for policy info
Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent 2987a4e commit 3fd7839

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

src/saml2/assertion.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -709,11 +709,10 @@ def authn_statement(authn_class=None, authn_auth=None,
709709
return res
710710

711711

712-
def do_subject_confirmation(policy, sp_entity_id, key_info=None, **treeargs):
712+
def do_subject_confirmation(not_on_or_after, key_info=None, **treeargs):
713713
"""
714714
715-
:param policy: Policy instance
716-
:param sp_entity_id: The entityid of the SP
715+
:param not_on_or_after: not_on_or_after policy
717716
:param subject_confirmation_method: How was the subject confirmed
718717
:param address: The network address/location from which an attesting entity
719718
can present the assertion.
@@ -730,21 +729,21 @@ def do_subject_confirmation(policy, sp_entity_id, key_info=None, **treeargs):
730729
_sc = factory(saml.SubjectConfirmation, **treeargs)
731730

732731
_scd = _sc.subject_confirmation_data
733-
_scd.not_on_or_after = policy.not_on_or_after(sp_entity_id)
732+
_scd.not_on_or_after = not_on_or_after
734733

735734
if _sc.method == saml.SCM_HOLDER_OF_KEY:
736735
_scd.add_extension_element(key_info)
737736

738737
return _sc
739738

740739

741-
def do_subject(policy, sp_entity_id, name_id, **farg):
740+
def do_subject(not_on_or_after, name_id, **farg):
742741
specs = farg['subject_confirmation']
743742

744743
if isinstance(specs, list):
745-
res = [do_subject_confirmation(policy, sp_entity_id, **s) for s in specs]
744+
res = [do_subject_confirmation(not_on_or_after, **s) for s in specs]
746745
else:
747-
res = [do_subject_confirmation(policy, sp_entity_id, **specs)]
746+
res = [do_subject_confirmation(not_on_or_after, **specs)]
748747

749748
return factory(saml.Subject, name_id=name_id, subject_confirmation=res)
750749

@@ -784,13 +783,11 @@ def construct(self, sp_entity_id, attrconvs, policy, issuer, farg,
784783
:return: An Assertion instance
785784
"""
786785

787-
if policy:
788-
_name_format = policy.get_name_form(sp_entity_id)
789-
else:
790-
_name_format = NAME_FORMAT_URI
786+
_name_format = policy.get_name_form(sp_entity_id)
791787

792-
attr_statement = saml.AttributeStatement(attribute=from_local(
793-
attrconvs, self, _name_format))
788+
attr_statement = saml.AttributeStatement(
789+
attribute=from_local(attrconvs, self, _name_format)
790+
)
794791

795792
if encrypt == "attributes":
796793
for attr in attr_statement.attribute:
@@ -816,11 +813,10 @@ def construct(self, sp_entity_id, attrconvs, policy, issuer, farg,
816813
else:
817814
_authn_statement = None
818815

819-
subject = do_subject(policy, sp_entity_id, name_id,
820-
**farg['subject'])
821-
822-
_ass = assertion_factory(issuer=issuer, conditions=conds,
823-
subject=subject)
816+
subject = do_subject(
817+
policy.not_on_or_after(sp_entity_id), name_id, **farg['subject']
818+
)
819+
_ass = assertion_factory(issuer=issuer, conditions=conds, subject=subject)
824820

825821
if _authn_statement:
826822
_ass.authn_statement = [_authn_statement]

0 commit comments

Comments
 (0)