2424from saml2 .mdstore import MetadataStore
2525from saml2 .saml import NAME_FORMAT_URI
2626from saml2 .virtual_org import VirtualOrg
27- from saml2 .utility .config import RuleValidator , should_warning , must_error
27+ from saml2 .utility .config import ConfigValidationError
2828
2929logger = logging .getLogger (__name__ )
3030
@@ -583,15 +583,17 @@ def ecp_endpoint(self, ipaddress):
583583
584584
585585class eIDASConfig (Config ):
586- @classmethod
587- def assert_not_declared (cls , error_signal ):
588- return (lambda x : x is None ,
589- partial (error_signal , message = "not be declared" ))
586+ def get_endpoint_element (self , element ):
587+ pass
588+
589+ def get_protocol_version (self ):
590+ pass
590591
591- @classmethod
592- def assert_declared (cls , error_signal ):
593- return (lambda x : x is not None ,
594- partial (error_signal , message = "be declared" ))
592+ def get_application_identifier (self ):
593+ pass
594+
595+ def get_node_country (self ):
596+ pass
595597
596598 @staticmethod
597599 def validate_node_country_format (node_country ):
@@ -613,57 +615,54 @@ class eIDASSPConfig(SPConfig, eIDASConfig):
613615 def get_endpoint_element (self , element ):
614616 return getattr (self , "_sp_endpoints" , {}).get (element , None )
615617
618+ def get_application_identifier (self ):
619+ return getattr (self , "_sp_application_identifier" , None )
620+
621+ def get_protocol_version (self ):
622+ return getattr (self , "_sp_protocol_version" , None )
623+
624+ def get_node_country (self ):
625+ return getattr (self , "_sp_node_country" , None )
626+
616627 def validate (self ):
617- validators = [
618- RuleValidator (
619- "single_logout_service" ,
620- self .get_endpoint_element ("single_logout_service" ),
621- * self .assert_not_declared (should_warning )
622- ),
623- RuleValidator (
624- "artifact_resolution_service" ,
625- self .get_endpoint_element ("artifact_resolution_service" ),
626- * self .assert_not_declared (should_warning )
627- ),
628- RuleValidator (
629- "manage_name_id_service" ,
630- self .get_endpoint_element ("manage_name_id_service" ),
631- * self .assert_not_declared (should_warning )
632- ),
633- RuleValidator (
634- "KeyDescriptor" ,
635- self .cert_file or self .encryption_keypairs ,
636- * self .assert_declared (must_error )
637- ),
638- RuleValidator (
639- "node_country" ,
640- getattr (self , "_sp_node_country" , None ),
641- self .validate_node_country_format ,
642- partial (must_error ,
643- message = "be declared in ISO 3166-1 alpha-2 format" )
644- ),
645- RuleValidator (
646- "application_identifier" ,
647- getattr (self , "_sp_application_identifier" , None ),
648- * self .assert_declared (should_warning )
649- ),
650- RuleValidator (
651- "application_identifier" ,
652- getattr (self , "_sp_application_identifier" , None ),
653- self .validate_application_identifier_format ,
654- partial (must_error ,
655- message = "be in the form <vendor name>:<software identifier>"
656- ":<major-version>.<minor-version>[.<patch-version>]”" )
657- ),
658- RuleValidator (
659- "protocol_version" ,
660- getattr (self , "_sp_protocol_version" , None ),
661- * self .assert_declared (should_warning )
628+ warning_validators = {
629+ "single_logout_service SHOULD NOT be declared" :
630+ self .get_endpoint_element ("single_logout_service" ) is None ,
631+ "artifact_resolution_service SHOULD NOT be declared" :
632+ self .get_endpoint_element ("artifact_resolution_service" ) is None ,
633+ "manage_name_id_service SHOULD NOT be declared" :
634+ self .get_endpoint_element ("manage_name_id_service" ) is None ,
635+ "application_identifier SHOULD be declared" :
636+ self .get_application_identifier () is not None ,
637+ "protocol_version SHOULD be declared" :
638+ self .get_protocol_version () is not None ,
639+ }
640+
641+ if not all (warning_validators .values ()):
642+ logger .warning (
643+ "Configuration validation warnings occurred: {}" .format (
644+ [msg for msg , check in warning_validators .items ()
645+ if check is not True ]
646+ )
662647 )
663- ]
664648
665- for validator in validators :
666- validator .validate ()
649+ error_validators = {
650+ "KeyDescriptor MUST be declared" :
651+ self .cert_file or self .encryption_keypairs ,
652+ "node_country MUST be declared in ISO 3166-1 alpha-2 format" :
653+ self .validate_node_country_format (self .get_node_country ()),
654+ "application_identifier MUST be in the form <vendor name>:<software "
655+ "identifier>:<major-version>.<minor-version>[.<patch-version>]" :
656+ self .validate_application_identifier_format (
657+ self .get_application_identifier ())
658+ }
659+
660+ if not all (error_validators .values ()):
661+ error = "Configuration validation errors occurred:" .format (
662+ [msg for msg , check in error_validators .items ()
663+ if check is not True ])
664+ logger .error (error )
665+ raise ConfigValidationError (error )
667666
668667
669668class IdPConfig (Config ):
0 commit comments