50
50
51
51
from saml2 .s_utils import RequestVersionTooLow
52
52
from saml2 .s_utils import RequestVersionTooHigh
53
- from saml2 .saml import attribute_from_string
53
+ from saml2 .saml import attribute_from_string , XSI_TYPE
54
54
from saml2 .saml import SCM_BEARER
55
55
from saml2 .saml import SCM_HOLDER_OF_KEY
56
56
from saml2 .saml import SCM_SENDER_VOUCHES
@@ -201,9 +201,13 @@ def _dummy(_):
201
201
return None
202
202
203
203
204
- def for_me (condition , myself ):
205
- # Am I among the intended audiences
206
- for restriction in condition .audience_restriction :
204
+ def for_me (conditions , myself ):
205
+ """ Am I among the intended audiences """
206
+
207
+ if not conditions .audience_restriction : # No audience restriction
208
+ return True
209
+
210
+ for restriction in conditions .audience_restriction :
207
211
for audience in restriction .audience :
208
212
if audience .text .strip () == myself :
209
213
return True
@@ -443,7 +447,8 @@ class AuthnResponse(StatusResponse):
443
447
def __init__ (self , sec_context , attribute_converters , entity_id ,
444
448
return_addr = None , outstanding_queries = None ,
445
449
timeslack = 0 , asynchop = True , allow_unsolicited = False ,
446
- test = False , allow_unknown_attributes = False ):
450
+ test = False , allow_unknown_attributes = False ,
451
+ ** kwargs ):
447
452
448
453
StatusResponse .__init__ (self , sec_context , return_addr , timeslack ,
449
454
asynchop = asynchop )
@@ -461,6 +466,8 @@ def __init__(self, sec_context, attribute_converters, entity_id,
461
466
self .allow_unsolicited = allow_unsolicited
462
467
self .test = test
463
468
self .allow_unknown_attributes = allow_unknown_attributes
469
+ #
470
+ self .extension_schema = kwargs ["extension_schema" ]
464
471
465
472
def loads (self , xmldata , decode = True , origxml = None ):
466
473
self ._loads (xmldata , decode , origxml )
@@ -506,44 +513,50 @@ def authn_statement_ok(self, optional=False):
506
513
# check authn_statement.session_index
507
514
508
515
def condition_ok (self , lax = False ):
509
- # The Identity Provider MUST include a <saml:Conditions> element
510
- #print "Conditions",assertion.conditions
511
516
if self .test :
512
517
lax = True
518
+
519
+ # The Identity Provider MUST include a <saml:Conditions> element
513
520
assert self .assertion .conditions
514
- condition = self .assertion .conditions
521
+ conditions = self .assertion .conditions
515
522
516
- logger .debug ("condition : %s" % condition )
523
+ logger .debug ("conditions : %s" % conditions )
517
524
518
525
# if no sub-elements or elements are supplied, then the
519
526
# assertion is considered to be valid.
520
- if not condition .keyswv ():
527
+ if not conditions .keyswv ():
521
528
return True
522
529
523
530
# if both are present NotBefore must be earlier than NotOnOrAfter
524
- if condition .not_before and condition .not_on_or_after :
525
- if not later_than (condition .not_on_or_after , condition .not_before ):
531
+ if conditions .not_before and conditions .not_on_or_after :
532
+ if not later_than (conditions .not_on_or_after , conditions .not_before ):
526
533
return False
527
534
528
535
try :
529
- if condition .not_on_or_after :
536
+ if conditions .not_on_or_after :
530
537
self .not_on_or_after = validate_on_or_after (
531
- condition .not_on_or_after , self .timeslack )
532
- if condition .not_before :
533
- validate_before (condition .not_before , self .timeslack )
538
+ conditions .not_on_or_after , self .timeslack )
539
+ if conditions .not_before :
540
+ validate_before (conditions .not_before , self .timeslack )
534
541
except Exception , excp :
535
- logger .error ("Exception on condition : %s" % (excp ,))
542
+ logger .error ("Exception on conditions : %s" % (excp ,))
536
543
if not lax :
537
544
raise
538
545
else :
539
546
self .not_on_or_after = 0
540
547
541
- if not for_me (condition , self .entity_id ):
548
+ if not for_me (conditions , self .entity_id ):
542
549
if not lax :
543
- #print condition
544
- #print self.entity_id
545
550
raise Exception ("Not for me!!!" )
546
-
551
+
552
+ if conditions .condition : # extra conditions
553
+ for cond in conditions .condition :
554
+ try :
555
+ if cond .extension_attributes [XSI_TYPE ] in self .extension_schema :
556
+ pass
557
+ except KeyError :
558
+ raise Exception ("Unknown condition" )
559
+
547
560
return True
548
561
549
562
def decrypt_attributes (self , attribute_statement ):
@@ -924,6 +937,7 @@ def response_factory(xmlstr, conf, return_addr=None, outstanding_queries=None,
924
937
925
938
attribute_converters = conf .attribute_converters
926
939
entity_id = conf .entityid
940
+ extension_schema = conf .extension_schema
927
941
928
942
response = StatusResponse (sec_context , return_addr , timeslack , request_id ,
929
943
asynchop )
@@ -933,7 +947,8 @@ def response_factory(xmlstr, conf, return_addr=None, outstanding_queries=None,
933
947
authnresp = AuthnResponse (sec_context , attribute_converters ,
934
948
entity_id , return_addr ,
935
949
outstanding_queries , timeslack , asynchop ,
936
- allow_unsolicited )
950
+ allow_unsolicited ,
951
+ extension_schema = extension_schema )
937
952
authnresp .update (response )
938
953
return authnresp
939
954
except TypeError :
0 commit comments