@@ -483,7 +483,7 @@ def _metadata_endpoint(self, context):
483
483
:param context: The current context
484
484
:return: response with metadata
485
485
"""
486
- msg = "Sending metadata response"
486
+ msg = "Sending metadata response for entityId = {}" . format ( self . idp . config . entityid )
487
487
logline = lu .LOG_FMT .format (id = lu .get_session_id (context .state ), message = msg )
488
488
logger .debug (logline )
489
489
metadata_string = create_metadata_string (None , self .idp .config , 4 , None , None , None , None ,
@@ -523,6 +523,7 @@ def _register_endpoints(self, providers):
523
523
functools .partial (self .handle_authn_request , binding_in = binding )))
524
524
525
525
if self .expose_entityid_endpoint ():
526
+ logger .debug ("Exposing frontend entity endpoint = {}" .format (self .idp .config .entityid ))
526
527
parsed_entity_id = urlparse (self .idp .config .entityid )
527
528
url_map .append (("^{0}" .format (parsed_entity_id .path [1 :]),
528
529
self ._metadata_endpoint ))
@@ -959,30 +960,39 @@ def _add_endpoints_to_config(self, config, co_name, backend_name):
959
960
960
961
return config
961
962
962
- def _add_entity_id (self , config , co_name ):
963
+ def _add_entity_id (self , config , co_name , backend_name ):
963
964
"""
964
965
Use the CO name to construct the entity ID for the virtual IdP
965
966
for the CO and add it to the config. Also add it to the
966
967
context.
967
968
968
969
The entity ID has the form
969
970
970
- {base_entity_id}/{co_name}
971
+ {base_entity_id}/{backend_name}/{ co_name}
971
972
972
973
:type context: The current context
973
974
:type config: satosa.satosa_config.SATOSAConfig
974
975
:type co_name: str
976
+ :type backend_name: str
975
977
:rtype: satosa.satosa_config.SATOSAConfig
976
978
977
979
:param context:
978
980
:param config: satosa proxy config
979
981
:param co_name: CO name
982
+ :param backend_name: Backend name
980
983
981
984
:return: config with updated entity ID
982
985
"""
983
986
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
986
996
987
997
return config
988
998
@@ -1035,7 +1045,7 @@ def _co_names_from_config(self):
1035
1045
1036
1046
return co_names
1037
1047
1038
- def _create_co_virtual_idp (self , context ):
1048
+ def _create_co_virtual_idp (self , context , co_name = None ):
1039
1049
"""
1040
1050
Create a virtual IdP to represent the CO.
1041
1051
@@ -1045,7 +1055,7 @@ def _create_co_virtual_idp(self, context):
1045
1055
:param context:
1046
1056
:return: An idp server
1047
1057
"""
1048
- co_name = self ._get_co_name (context )
1058
+ co_name = co_name or self ._get_co_name (context )
1049
1059
context .decorate (self .KEY_CO_NAME , co_name )
1050
1060
1051
1061
# Verify that we are configured for this CO. If the CO was not
@@ -1068,7 +1078,7 @@ def _create_co_virtual_idp(self, context):
1068
1078
idp_config = self ._add_endpoints_to_config (
1069
1079
idp_config , co_name , backend_name
1070
1080
)
1071
- idp_config = self ._add_entity_id (idp_config , co_name )
1081
+ idp_config = self ._add_entity_id (idp_config , co_name , backend_name )
1072
1082
context .decorate (self .KEY_CO_ENTITY_ID , idp_config ['entityid' ])
1073
1083
1074
1084
# Use the overwritten IdP config to generate a pysaml2 config object
@@ -1155,4 +1165,30 @@ def _register_endpoints(self, backend_names):
1155
1165
logline = "Adding mapping {}" .format (mapping )
1156
1166
logger .debug (logline )
1157
1167
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
+
1158
1179
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