2121from satosa .frontends .base import FrontendModule
2222from satosa .internal_data import InternalRequest , DataConverter , UserIdHashType
2323from satosa .logging_util import satosa_logging
24+ from satosa .response import MetadataResponse
2425from satosa .util import response , get_saml_name_id_format , saml_name_format_to_hash_type
2526
2627LOGGER = logging .getLogger (__name__ )
@@ -35,7 +36,8 @@ def __init__(self, auth_req_callback_func, internal_attributes, conf):
3536 self ._validate_config (conf )
3637
3738 super (SamlFrontend , self ).__init__ (auth_req_callback_func , internal_attributes )
38- self .config = conf ["idp_config" ]
39+ self .config = conf
40+ self .idp_config = conf ["idp_config" ]
3941 self .endpoints = conf ["endpoints" ]
4042 self .base = conf ["base" ]
4143 self .state_id = conf ["state_id" ]
@@ -82,9 +84,9 @@ def register_endpoints(self, providers):
8284 :rtype: list[(str, ((satosa.context.Context, Any) -> satosa.response.Response, Any))]
8385 """
8486 self ._validate_providers (providers )
85- self .config = self ._build_idp_config_endpoints (self .config , providers )
87+ self .idp_config = self ._build_idp_config_endpoints (self .idp_config , providers )
8688 # Create the idp
87- idp_config = IdPConfig ().load (copy .deepcopy (self .config ), metadata_construction = False )
89+ idp_config = IdPConfig ().load (copy .deepcopy (self .idp_config ), metadata_construction = False )
8890 self .idp = Server (config = idp_config )
8991 return self ._register_endpoints (providers )
9092
@@ -446,6 +448,18 @@ def _validate_providers(self, providers):
446448 LOGGER .error (msg )
447449 raise TypeError (msg )
448450
451+ def _metadata (self , context ):
452+ """
453+ Endpoint for retrieving the backend metadata
454+ :type context: satosa.context.Context
455+ :rtype: satosa.backends.saml2.MetadataResponse
456+
457+ :param context: The current context
458+ :return: response with metadata
459+ """
460+ satosa_logging (LOGGER , logging .DEBUG , "Sending metadata response" , context .state )
461+ return MetadataResponse (self .idp .config )
462+
449463 def _register_endpoints (self , providers ):
450464 """
451465 Register methods to endpoints
@@ -468,6 +482,10 @@ def _register_endpoints(self, providers):
468482 url_map .append (("(%s)/%s/(.*)$" % (valid_providers , parsed_endp .path ),
469483 (self .handle_authn_request , binding )))
470484
485+ if "publish_metadata" in self .config :
486+ metadata_path = urlparse (self .config ["publish_metadata" ])
487+ url_map .append (("^%s$" % metadata_path .path [1 :], self ._metadata ))
488+
471489 return url_map
472490
473491 def _build_idp_config_endpoints (self , config , providers ):
@@ -573,7 +591,7 @@ def _load_idp_dynamic_endpoints(self, context):
573591 """
574592 target_entity_id = self ._get_target_entity_id (context )
575593 context .internal_data ["mirror.target_entity_id" ] = target_entity_id
576- idp_conf_file = self ._load_endpoints_to_config (self .config , self .endpoints , self .base ,
594+ idp_conf_file = self ._load_endpoints_to_config (self .idp_config , self .endpoints , self .base ,
577595 context .target_backend , target_entity_id )
578596 idp_config = IdPConfig ().load (idp_conf_file , metadata_construction = False )
579597 return Server (config = idp_config )
@@ -632,7 +650,7 @@ def handle_backend_error(self, exception):
632650 :type exception: satosa.exception.SATOSAAuthenticationError
633651 :rtype: satosa.response.Response
634652 """
635- idp = self ._load_idp_dynamic_entity_id (self .config , exception .state )
653+ idp = self ._load_idp_dynamic_entity_id (self .idp_config , exception .state )
636654 return self ._handle_backend_error (exception , idp )
637655
638656 def handle_authn_response (self , context , internal_response ):
@@ -642,7 +660,7 @@ def handle_authn_response(self, context, internal_response):
642660 :param internal_response:
643661 :return:
644662 """
645- idp = self ._load_idp_dynamic_entity_id (self .config , context .state )
663+ idp = self ._load_idp_dynamic_entity_id (self .idp_config , context .state )
646664 return self ._handle_authn_response (context , internal_response , idp )
647665
648666 def register_endpoints (self , providers ):
0 commit comments