@@ -578,7 +578,8 @@ def _authn_context_decl_ref(self, decl_ref, authn_auth=None):
578
578
authenticating_authority = factory (
579
579
saml .AuthenticatingAuthority , text = authn_auth ))
580
580
581
- def _authn_context_class_ref (self , authn_class , authn_auth = None ):
581
+ @staticmethod
582
+ def _authn_context_class_ref (authn_class , authn_auth = None ):
582
583
"""
583
584
Construct the authn context with a authn context class reference
584
585
:param authn_class: The authn context class reference
@@ -596,45 +597,62 @@ def _authn_context_class_ref(self, authn_class, authn_auth=None):
596
597
authn_context_class_ref = cntx_class )
597
598
598
599
def _authn_statement (self , authn_class = None , authn_auth = None ,
599
- authn_decl = None , authn_decl_ref = None ):
600
+ authn_decl = None , authn_decl_ref = None , authn_instant = "" ,
601
+ subject_locality = "" ):
600
602
"""
601
603
Construct the AuthnStatement
602
604
:param authn_class: Authentication Context Class reference
603
605
:param authn_auth: Authenticating Authority
604
606
:param authn_decl: Authentication Context Declaration
605
607
:param authn_decl_ref: Authentication Context Declaration reference
608
+ :param authn_instant: When the Authentication was performed.
609
+ Assumed to be seconds since the Epoch.
610
+ :param subject_locality: Specifies the DNS domain name and IP address
611
+ for the system from which the assertion subject was apparently
612
+ authenticated.
606
613
:return: An AuthnContext instance
607
614
"""
615
+ if authn_instant :
616
+ _instant = instant (time_stamp = authn_instant )
617
+ else :
618
+ _instant = instant ()
619
+
608
620
if authn_class :
609
- return factory (
621
+ res = factory (
610
622
saml .AuthnStatement ,
611
- authn_instant = instant () ,
623
+ authn_instant = _instant ,
612
624
session_index = sid (),
613
625
authn_context = self ._authn_context_class_ref (
614
626
authn_class , authn_auth ))
615
627
elif authn_decl :
616
- return factory (
628
+ res = factory (
617
629
saml .AuthnStatement ,
618
- authn_instant = instant () ,
630
+ authn_instant = _instant ,
619
631
session_index = sid (),
620
632
authn_context = self ._authn_context_decl (authn_decl , authn_auth ))
621
633
elif authn_decl_ref :
622
- return factory (
634
+ res = factory (
623
635
saml .AuthnStatement ,
624
- authn_instant = instant () ,
636
+ authn_instant = _instant ,
625
637
session_index = sid (),
626
638
authn_context = self ._authn_context_decl_ref (authn_decl_ref ,
627
639
authn_auth ))
628
640
else :
629
- return factory (
641
+ res = factory (
630
642
saml .AuthnStatement ,
631
- authn_instant = instant () ,
643
+ authn_instant = _instant ,
632
644
session_index = sid ())
633
645
646
+ if subject_locality :
647
+ res .subject_locality = saml .SubjectLocality (text = subject_locality )
648
+
649
+ return res
650
+
634
651
def construct (self , sp_entity_id , in_response_to , consumer_url ,
635
652
name_id , attrconvs , policy , issuer , authn_class = None ,
636
653
authn_auth = None , authn_decl = None , encrypt = None ,
637
- sec_context = None , authn_decl_ref = None ):
654
+ sec_context = None , authn_decl_ref = None , authn_instant = "" ,
655
+ subject_locality = "" ):
638
656
""" Construct the Assertion
639
657
640
658
:param sp_entity_id: The entityid of the SP
@@ -651,6 +669,10 @@ def construct(self, sp_entity_id, in_response_to, consumer_url,
651
669
:param encrypt: Whether to encrypt parts or all of the Assertion
652
670
:param sec_context: The security context used when encrypting
653
671
:param authn_decl_ref: An Authentication Context declaration reference
672
+ :param authn_instant: When the Authentication was performed
673
+ :param subject_locality: Specifies the DNS domain name and IP address
674
+ for the system from which the assertion subject was apparently
675
+ authenticated.
654
676
:return: An Assertion instance
655
677
"""
656
678
@@ -677,7 +699,9 @@ def construct(self, sp_entity_id, in_response_to, consumer_url,
677
699
678
700
if authn_auth or authn_class or authn_decl or authn_decl_ref :
679
701
_authn_statement = self ._authn_statement (authn_class , authn_auth ,
680
- authn_decl , authn_decl_ref )
702
+ authn_decl , authn_decl_ref ,
703
+ authn_instant ,
704
+ subject_locality )
681
705
else :
682
706
_authn_statement = None
683
707
0 commit comments