@@ -67,9 +67,12 @@ def destinations(srvs):
67
67
return [s ["location" ] for s in srvs ]
68
68
69
69
70
- def attribute_requirement (entity ):
70
+ def attribute_requirement (entity , index = None ):
71
71
res = {"required" : [], "optional" : []}
72
72
for acs in entity ["attribute_consuming_service" ]:
73
+ if index is not None and acs ["index" ] != index :
74
+ continue
75
+
73
76
for attr in acs ["requested_attribute" ]:
74
77
if "is_required" in attr and attr ["is_required" ] == "true" :
75
78
res ["required" ].append (attr )
@@ -133,6 +136,9 @@ def __contains__(self, item):
133
136
def __getitem__ (self , item ):
134
137
return self .entity [item ]
135
138
139
+ def __setitem__ (self , key , value ):
140
+ self .entity [key ] = value
141
+
136
142
def do_entity_descriptor (self , entity_descr ):
137
143
if self .check_validity :
138
144
try :
@@ -221,7 +227,7 @@ def service(self, entity_id, typ, service, binding=None):
221
227
"""
222
228
223
229
logger .debug ("service(%s, %s, %s, %s)" % (entity_id , typ , service ,
224
- binding ))
230
+ binding ))
225
231
try :
226
232
srvs = []
227
233
for t in self [entity_id ][typ ]:
@@ -297,20 +303,22 @@ def bindings(self, entity_id, typ, service):
297
303
298
304
return self .service (entity_id , typ , service )
299
305
300
- def attribute_requirement (self , entity_id , index = 0 ):
306
+ def attribute_requirement (self , entity_id , index = None ):
301
307
""" Returns what attributes the SP requires and which are optional
302
308
if any such demands are registered in the Metadata.
303
309
304
310
:param entity_id: The entity id of the SP
305
311
:param index: which of the attribute consumer services its all about
312
+ if index=None then return all attributes expected by all
313
+ attribute_consuming_services.
306
314
:return: 2-tuple, list of required and list of optional attributes
307
315
"""
308
316
309
317
res = {"required" : [], "optional" : []}
310
318
311
319
try :
312
320
for sp in self [entity_id ]["spsso_descriptor" ]:
313
- _res = attribute_requirement (sp )
321
+ _res = attribute_requirement (sp , index )
314
322
res ["required" ].extend (_res ["required" ])
315
323
res ["optional" ].extend (_res ["optional" ])
316
324
except KeyError :
@@ -513,6 +521,7 @@ def load(self):
513
521
514
522
class MetadataStore (object ):
515
523
def __init__ (self , onts , attrc , config , ca_certs = None ,
524
+ check_validity = True ,
516
525
disable_ssl_certificate_validation = False ):
517
526
"""
518
527
:params onts:
@@ -523,11 +532,16 @@ def __init__(self, onts, attrc, config, ca_certs=None,
523
532
"""
524
533
self .onts = onts
525
534
self .attrc = attrc
526
- self .http = HTTPBase (verify = disable_ssl_certificate_validation ,
527
- ca_bundle = ca_certs )
535
+
536
+ if disable_ssl_certificate_validation :
537
+ self .http = HTTPBase (verify = False , ca_bundle = ca_certs )
538
+ else :
539
+ self .http = HTTPBase (verify = True , ca_bundle = ca_certs )
540
+
528
541
self .security = security_context (config )
529
542
self .ii = 0
530
543
self .metadata = {}
544
+ self .check_validity = check_validity
531
545
532
546
def load (self , typ , * args , ** kwargs ):
533
547
if typ == "local" :
@@ -539,10 +553,16 @@ def load(self, typ, *args, **kwargs):
539
553
_md = MetaData (self .onts , self .attrc , args [0 ], ** kwargs )
540
554
elif typ == "remote" :
541
555
key = kwargs ["url" ]
556
+ _args = {}
557
+ for _key in ["node_name" , "check_validity" ]:
558
+ try :
559
+ _args [_key ] = kwargs [_key ]
560
+ except KeyError :
561
+ pass
562
+
542
563
_md = MetaDataExtern (self .onts , self .attrc ,
543
564
kwargs ["url" ], self .security ,
544
- kwargs ["cert" ], self .http ,
545
- node_name = kwargs .get ('node_name' ))
565
+ kwargs ["cert" ], self .http , ** _args )
546
566
elif typ == "mdfile" :
547
567
key = args [0 ]
548
568
_md = MetaDataMD (self .onts , self .attrc , args [0 ])
@@ -559,6 +579,8 @@ def imp(self, spec):
559
579
for key , vals in spec .items ():
560
580
for val in vals :
561
581
if isinstance (val , dict ):
582
+ if not self .check_validity :
583
+ val ["check_validity" ] = False
562
584
self .load (key , ** val )
563
585
else :
564
586
self .load (key , val )
@@ -633,7 +655,7 @@ def authz_service(self, entity_id, binding=None, typ="pdp"):
633
655
if binding is None :
634
656
binding = BINDING_SOAP
635
657
return self .service (entity_id , "pdp_descriptor" ,
636
- "authz_service" , binding )
658
+ "authz_service" , binding )
637
659
638
660
def assertion_id_request_service (self , entity_id , binding = None , typ = None ):
639
661
# AuthnAuthority + IDP + PDP + AttributeAuthority
@@ -642,7 +664,7 @@ def assertion_id_request_service(self, entity_id, binding=None, typ=None):
642
664
if binding is None :
643
665
binding = BINDING_SOAP
644
666
return self .service (entity_id , "%s_descriptor" % typ ,
645
- "assertion_id_request_service" , binding )
667
+ "assertion_id_request_service" , binding )
646
668
647
669
def single_logout_service (self , entity_id , binding = None , typ = None ):
648
670
# IDP + SP
@@ -651,35 +673,35 @@ def single_logout_service(self, entity_id, binding=None, typ=None):
651
673
if binding is None :
652
674
binding = BINDING_HTTP_REDIRECT
653
675
return self .service (entity_id , "%s_descriptor" % typ ,
654
- "single_logout_service" , binding )
676
+ "single_logout_service" , binding )
655
677
656
678
def manage_name_id_service (self , entity_id , binding = None , typ = None ):
657
679
# IDP + SP
658
680
if binding is None :
659
681
binding = BINDING_HTTP_REDIRECT
660
682
return self .service (entity_id , "%s_descriptor" % typ ,
661
- "manage_name_id_service" , binding )
683
+ "manage_name_id_service" , binding )
662
684
663
685
def artifact_resolution_service (self , entity_id , binding = None , typ = None ):
664
686
# IDP + SP
665
687
if binding is None :
666
688
binding = BINDING_HTTP_REDIRECT
667
689
return self .service (entity_id , "%s_descriptor" % typ ,
668
- "artifact_resolution_service" , binding )
690
+ "artifact_resolution_service" , binding )
669
691
670
692
def assertion_consumer_service (self , entity_id , binding = None , _ = "spsso" ):
671
693
# SP
672
694
if binding is None :
673
695
binding = BINDING_HTTP_POST
674
696
return self .service (entity_id , "spsso_descriptor" ,
675
- "assertion_consumer_service" , binding )
697
+ "assertion_consumer_service" , binding )
676
698
677
699
def attribute_consuming_service (self , entity_id , binding = None , _ = "spsso" ):
678
700
# SP
679
701
if binding is None :
680
702
binding = BINDING_HTTP_REDIRECT
681
703
return self .service (entity_id , "spsso_descriptor" ,
682
- "attribute_consuming_service" , binding )
704
+ "attribute_consuming_service" , binding )
683
705
684
706
def discovery_response (self , entity_id , binding = None , _ = "spsso" ):
685
707
if binding is None :
@@ -863,7 +885,11 @@ def _providers(self, descriptor):
863
885
for _md in self .metadata .values ():
864
886
for ent_id , ent_desc in _md .items ():
865
887
if descriptor in ent_desc :
866
- res .append (ent_id )
888
+ if ent_id in res :
889
+ #print "duplicated entity_id: %s" % res
890
+ pass
891
+ else :
892
+ res .append (ent_id )
867
893
return res
868
894
869
895
def service_providers (self ):
0 commit comments