@@ -483,7 +483,7 @@ def _metadata_endpoint(self, context):
483483 :param context: The current context
484484 :return: response with metadata
485485 """
486- msg = "Sending metadata response"
486+ msg = "Sending metadata response for entityId = {}" . format ( self . idp . config . entityid )
487487 logline = lu .LOG_FMT .format (id = lu .get_session_id (context .state ), message = msg )
488488 logger .debug (logline )
489489 metadata_string = create_metadata_string (None , self .idp .config , 4 , None , None , None , None ,
@@ -523,6 +523,7 @@ def _register_endpoints(self, providers):
523523 functools .partial (self .handle_authn_request , binding_in = binding )))
524524
525525 if self .expose_entityid_endpoint ():
526+ logger .debug ("Exposing frontend entity endpoint = {}" .format (self .idp .config .entityid ))
526527 parsed_entity_id = urlparse (self .idp .config .entityid )
527528 url_map .append (("^{0}" .format (parsed_entity_id .path [1 :]),
528529 self ._metadata_endpoint ))
@@ -959,30 +960,39 @@ def _add_endpoints_to_config(self, config, co_name, backend_name):
959960
960961 return config
961962
962- def _add_entity_id (self , config , co_name ):
963+ def _add_entity_id (self , config , co_name , backend_name ):
963964 """
964965 Use the CO name to construct the entity ID for the virtual IdP
965966 for the CO and add it to the config. Also add it to the
966967 context.
967968
968969 The entity ID has the form
969970
970- {base_entity_id}/{co_name}
971+ {base_entity_id}/{backend_name}/{ co_name}
971972
972973 :type context: The current context
973974 :type config: satosa.satosa_config.SATOSAConfig
974975 :type co_name: str
976+ :type backend_name: str
975977 :rtype: satosa.satosa_config.SATOSAConfig
976978
977979 :param context:
978980 :param config: satosa proxy config
979981 :param co_name: CO name
982+ :param backend_name: Backend name
980983
981984 :return: config with updated entity ID
982985 """
983986 base_entity_id = config ['entityid' ]
984- co_entity_id = "{}/{}" .format (base_entity_id , quote_plus (co_name ))
985- config ['entityid' ] = co_entity_id
987+
988+ replace = [
989+ ("<backend_name>" , quote_plus (backend_name )),
990+ ("<co_name>" , quote_plus (co_name ))
991+ ]
992+ for _replace in replace :
993+ base_entity_id = base_entity_id .replace (_replace [0 ], _replace [1 ])
994+
995+ config ['entityid' ] = base_entity_id
986996
987997 return config
988998
@@ -1035,7 +1045,7 @@ def _co_names_from_config(self):
10351045
10361046 return co_names
10371047
1038- def _create_co_virtual_idp (self , context ):
1048+ def _create_co_virtual_idp (self , context , co_name = None ):
10391049 """
10401050 Create a virtual IdP to represent the CO.
10411051
@@ -1045,7 +1055,7 @@ def _create_co_virtual_idp(self, context):
10451055 :param context:
10461056 :return: An idp server
10471057 """
1048- co_name = self ._get_co_name (context )
1058+ co_name = co_name or self ._get_co_name (context )
10491059 context .decorate (self .KEY_CO_NAME , co_name )
10501060
10511061 # Verify that we are configured for this CO. If the CO was not
@@ -1068,7 +1078,7 @@ def _create_co_virtual_idp(self, context):
10681078 idp_config = self ._add_endpoints_to_config (
10691079 idp_config , co_name , backend_name
10701080 )
1071- idp_config = self ._add_entity_id (idp_config , co_name )
1081+ idp_config = self ._add_entity_id (idp_config , co_name , backend_name )
10721082 context .decorate (self .KEY_CO_ENTITY_ID , idp_config ['entityid' ])
10731083
10741084 # Use the overwritten IdP config to generate a pysaml2 config object
@@ -1155,4 +1165,30 @@ def _register_endpoints(self, backend_names):
11551165 logline = "Adding mapping {}" .format (mapping )
11561166 logger .debug (logline )
11571167
1168+ if self .expose_entityid_endpoint ():
1169+ for backend_name in backend_names :
1170+ for co_name in co_names :
1171+ idp_config = self ._add_entity_id (copy .deepcopy (self .idp_config ), co_name , backend_name )
1172+ entity_id = idp_config ['entityid' ]
1173+ logger .debug ("Exposing frontend entity endpoint = {}" .format (entity_id ))
1174+ parsed_entity_id = urlparse (entity_id )
1175+ metadata_endpoint = "^{0}" .format (parsed_entity_id .path [1 :])
1176+ the_callable = functools .partial (self ._metadata_endpoint , co_name = co_name )
1177+ url_to_callable_mappings .append ((metadata_endpoint , the_callable ))
1178+
11581179 return url_to_callable_mappings
1180+
1181+ def _metadata_endpoint (self , context , co_name ):
1182+ """
1183+ Endpoint for retrieving the virtual frontend metadata
1184+ :type context: satosa.context.Context
1185+ :rtype: satosa.response.Response
1186+
1187+ :param context: The current context
1188+ :return: response with metadata
1189+ """
1190+ # Using the context of the current request and saved state from the
1191+ # authentication request dynamically create an IdP instance.
1192+ self .idp = self ._create_co_virtual_idp (context , co_name = co_name )
1193+ return super ()._metadata_endpoint (context = context );
1194+
0 commit comments