Skip to content

Commit 87f4082

Browse files
vkadamc00kiemon5ter
authored andcommitted
Support for exposing co entity's metadata endpoint
1 parent 8a096d5 commit 87f4082

File tree

5 files changed

+49
-11
lines changed

5 files changed

+49
-11
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
**/.DS_Store
22
_build
33
.idea
4+
*.iml
45
*.pyc
56
*.log*
67

example/internal_attributes.yaml.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ attributes:
2727
orcid: [emails.str]
2828
github: [email]
2929
openid: [email]
30-
saml: [email, emailAdress, mail]
30+
saml: [email, emailAddress, mail]
3131
name:
3232
facebook: [name]
3333
orcid: [name.credit-name]

src/satosa/backends/saml2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ def _metadata_endpoint(self, context):
448448
:param context: The current context
449449
:return: response with metadata
450450
"""
451-
msg = "Sending metadata response"
451+
msg = "Sending metadata response for entityId = {}".format(self.sp.config.entityid)
452452
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
453453
logger.debug(logline)
454454

@@ -488,6 +488,7 @@ def register_endpoints(self):
488488
("^%s$" % parsed_endp.path[1:], self.disco_response))
489489

490490
if self.expose_entityid_endpoint():
491+
logger.debug("Exposing backend entity endpoint = {}".format(self.sp.config.entityid))
491492
parsed_entity_id = urlparse(self.sp.config.entityid)
492493
url_map.append(("^{0}".format(parsed_entity_id.path[1:]),
493494
self._metadata_endpoint))

src/satosa/frontends/saml2.py

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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+

src/satosa/metadata_creation/saml_metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def _create_frontend_metadata(frontend_modules, backend_modules):
8080
logger.info(logline)
8181
idp_config = copy.deepcopy(frontend.config["idp_config"])
8282
idp_config = frontend._add_endpoints_to_config(idp_config, co_name, backend.name)
83-
idp_config = frontend._add_entity_id(idp_config, co_name)
83+
idp_config = frontend._add_entity_id(idp_config, co_name, backend.name)
8484
idp_config = frontend._overlay_for_saml_metadata(idp_config, co_name)
8585
entity_desc = _create_entity_descriptor(idp_config)
8686
frontend_metadata[frontend.name].append(entity_desc)

0 commit comments

Comments
 (0)