@@ -67,9 +67,12 @@ def destinations(srvs):
6767 return [s ["location" ] for s in srvs ]
6868
6969
70- def attribute_requirement (entity ):
70+ def attribute_requirement (entity , index = None ):
7171 res = {"required" : [], "optional" : []}
7272 for acs in entity ["attribute_consuming_service" ]:
73+ if index is not None and acs ["index" ] != index :
74+ continue
75+
7376 for attr in acs ["requested_attribute" ]:
7477 if "is_required" in attr and attr ["is_required" ] == "true" :
7578 res ["required" ].append (attr )
@@ -133,6 +136,9 @@ def __contains__(self, item):
133136 def __getitem__ (self , item ):
134137 return self .entity [item ]
135138
139+ def __setitem__ (self , key , value ):
140+ self .entity [key ] = value
141+
136142 def do_entity_descriptor (self , entity_descr ):
137143 if self .check_validity :
138144 try :
@@ -221,7 +227,7 @@ def service(self, entity_id, typ, service, binding=None):
221227 """
222228
223229 logger .debug ("service(%s, %s, %s, %s)" % (entity_id , typ , service ,
224- binding ))
230+ binding ))
225231 try :
226232 srvs = []
227233 for t in self [entity_id ][typ ]:
@@ -297,20 +303,22 @@ def bindings(self, entity_id, typ, service):
297303
298304 return self .service (entity_id , typ , service )
299305
300- def attribute_requirement (self , entity_id , index = 0 ):
306+ def attribute_requirement (self , entity_id , index = None ):
301307 """ Returns what attributes the SP requires and which are optional
302308 if any such demands are registered in the Metadata.
303309
304310 :param entity_id: The entity id of the SP
305311 :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.
306314 :return: 2-tuple, list of required and list of optional attributes
307315 """
308316
309317 res = {"required" : [], "optional" : []}
310318
311319 try :
312320 for sp in self [entity_id ]["spsso_descriptor" ]:
313- _res = attribute_requirement (sp )
321+ _res = attribute_requirement (sp , index )
314322 res ["required" ].extend (_res ["required" ])
315323 res ["optional" ].extend (_res ["optional" ])
316324 except KeyError :
@@ -513,6 +521,7 @@ def load(self):
513521
514522class MetadataStore (object ):
515523 def __init__ (self , onts , attrc , config , ca_certs = None ,
524+ check_validity = True ,
516525 disable_ssl_certificate_validation = False ):
517526 """
518527 :params onts:
@@ -523,11 +532,16 @@ def __init__(self, onts, attrc, config, ca_certs=None,
523532 """
524533 self .onts = onts
525534 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+
528541 self .security = security_context (config )
529542 self .ii = 0
530543 self .metadata = {}
544+ self .check_validity = check_validity
531545
532546 def load (self , typ , * args , ** kwargs ):
533547 if typ == "local" :
@@ -539,10 +553,16 @@ def load(self, typ, *args, **kwargs):
539553 _md = MetaData (self .onts , self .attrc , args [0 ], ** kwargs )
540554 elif typ == "remote" :
541555 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+
542563 _md = MetaDataExtern (self .onts , self .attrc ,
543564 kwargs ["url" ], self .security ,
544- kwargs ["cert" ], self .http ,
545- node_name = kwargs .get ('node_name' ))
565+ kwargs ["cert" ], self .http , ** _args )
546566 elif typ == "mdfile" :
547567 key = args [0 ]
548568 _md = MetaDataMD (self .onts , self .attrc , args [0 ])
@@ -559,6 +579,8 @@ def imp(self, spec):
559579 for key , vals in spec .items ():
560580 for val in vals :
561581 if isinstance (val , dict ):
582+ if not self .check_validity :
583+ val ["check_validity" ] = False
562584 self .load (key , ** val )
563585 else :
564586 self .load (key , val )
@@ -633,7 +655,7 @@ def authz_service(self, entity_id, binding=None, typ="pdp"):
633655 if binding is None :
634656 binding = BINDING_SOAP
635657 return self .service (entity_id , "pdp_descriptor" ,
636- "authz_service" , binding )
658+ "authz_service" , binding )
637659
638660 def assertion_id_request_service (self , entity_id , binding = None , typ = None ):
639661 # AuthnAuthority + IDP + PDP + AttributeAuthority
@@ -642,7 +664,7 @@ def assertion_id_request_service(self, entity_id, binding=None, typ=None):
642664 if binding is None :
643665 binding = BINDING_SOAP
644666 return self .service (entity_id , "%s_descriptor" % typ ,
645- "assertion_id_request_service" , binding )
667+ "assertion_id_request_service" , binding )
646668
647669 def single_logout_service (self , entity_id , binding = None , typ = None ):
648670 # IDP + SP
@@ -651,35 +673,35 @@ def single_logout_service(self, entity_id, binding=None, typ=None):
651673 if binding is None :
652674 binding = BINDING_HTTP_REDIRECT
653675 return self .service (entity_id , "%s_descriptor" % typ ,
654- "single_logout_service" , binding )
676+ "single_logout_service" , binding )
655677
656678 def manage_name_id_service (self , entity_id , binding = None , typ = None ):
657679 # IDP + SP
658680 if binding is None :
659681 binding = BINDING_HTTP_REDIRECT
660682 return self .service (entity_id , "%s_descriptor" % typ ,
661- "manage_name_id_service" , binding )
683+ "manage_name_id_service" , binding )
662684
663685 def artifact_resolution_service (self , entity_id , binding = None , typ = None ):
664686 # IDP + SP
665687 if binding is None :
666688 binding = BINDING_HTTP_REDIRECT
667689 return self .service (entity_id , "%s_descriptor" % typ ,
668- "artifact_resolution_service" , binding )
690+ "artifact_resolution_service" , binding )
669691
670692 def assertion_consumer_service (self , entity_id , binding = None , _ = "spsso" ):
671693 # SP
672694 if binding is None :
673695 binding = BINDING_HTTP_POST
674696 return self .service (entity_id , "spsso_descriptor" ,
675- "assertion_consumer_service" , binding )
697+ "assertion_consumer_service" , binding )
676698
677699 def attribute_consuming_service (self , entity_id , binding = None , _ = "spsso" ):
678700 # SP
679701 if binding is None :
680702 binding = BINDING_HTTP_REDIRECT
681703 return self .service (entity_id , "spsso_descriptor" ,
682- "attribute_consuming_service" , binding )
704+ "attribute_consuming_service" , binding )
683705
684706 def discovery_response (self , entity_id , binding = None , _ = "spsso" ):
685707 if binding is None :
@@ -863,7 +885,11 @@ def _providers(self, descriptor):
863885 for _md in self .metadata .values ():
864886 for ent_id , ent_desc in _md .items ():
865887 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 )
867893 return res
868894
869895 def service_providers (self ):
0 commit comments