Skip to content

Commit 73dbc2f

Browse files
author
ivan
committed
Expose metadata endpoint via configuration option
Check for configuration option 'entityid_endpoint'. When set to true the metadata will be served at the entityid URI.
1 parent e5868d7 commit 73dbc2f

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

src/satosa/backends/saml2.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from saml2.extension.ui import NAMESPACE as UI_NAMESPACE
1616
from saml2.metadata import create_metadata_string
1717

18+
from satosa.base import SAMLBaseModule
1819
from .base import BackendModule
1920
from ..exception import SATOSAAuthenticationError
2021
from ..internal_data import (InternalResponse,
@@ -29,7 +30,7 @@
2930
logger = logging.getLogger(__name__)
3031

3132

32-
class SAMLBackend(BackendModule):
33+
class SAMLBackend(BackendModule, SAMLBaseModule):
3334
"""
3435
A saml2 backend module (acting as a SP).
3536
"""
@@ -51,7 +52,6 @@ def __init__(self, outgoing, internal_attributes, config, base_url, name):
5152
:param name: name of the plugin
5253
"""
5354
super().__init__(outgoing, internal_attributes, base_url, name)
54-
5555
sp_config = SPConfig().load(copy.deepcopy(config["sp_config"]), False)
5656
self.sp = Base(sp_config)
5757

@@ -218,7 +218,7 @@ def _translate_response(self, response, state):
218218

219219
internal_resp.user_id = response.get_subject().text
220220
internal_resp.attributes = self.converter.to_internal(self.attribute_profile, response.ava)
221-
221+
222222
# The SAML response may not include a NameID
223223
try:
224224
internal_resp.name_id = response.assertion.subject.name_id
@@ -260,6 +260,11 @@ def register_endpoints(self):
260260
url_map.append(
261261
("^%s$" % parsed_endp.path[1:], self.disco_response))
262262

263+
if self.expose_entityid_endpoint():
264+
parsed_entity_id = urlparse(self.sp.config.entityid)
265+
url_map.append(("^{0}".format(parsed_entity_id.path[1:]),
266+
self._metadata_endpoint))
267+
263268
return url_map
264269

265270
def get_metadata_desc(self):
@@ -324,7 +329,7 @@ def get_metadata_desc(self):
324329

325330
class SAMLInternalResponse(InternalResponse):
326331
"""
327-
Like the parent InternalResponse, holds internal representation of
332+
Like the parent InternalResponse, holds internal representation of
328333
service related data, but includes additional details relevant to
329334
SAML interoperability.
330335

src/satosa/base.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,11 @@ def run(self, context):
266266
exc_info=True)
267267
raise SATOSAUnknownError("Unknown error") from err
268268
return resp
269+
270+
271+
class SAMLBaseModule(object):
272+
KEY_ENTITYID_ENDPOINT = 'entityid_endpoint'
273+
274+
def expose_entityid_endpoint(self):
275+
value = self.config.get(self.KEY_ENTITYID_ENDPOINT, False)
276+
return bool(value)

src/satosa/frontends/saml2.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from saml2.samlp import name_id_policy_from_string
1616
from saml2.server import Server
1717

18+
from satosa.base import SAMLBaseModule
1819
from .base import FrontendModule
1920
from ..internal_data import InternalRequest, UserIdHashType
2021
from ..logging_util import satosa_logging
@@ -57,7 +58,7 @@ def hash_type_to_saml_name_id_format(hash_type):
5758
return NAMEID_FORMAT_PERSISTENT
5859

5960

60-
class SAMLFrontend(FrontendModule):
61+
class SAMLFrontend(FrontendModule, SAMLBaseModule):
6162
"""
6263
A pysaml2 frontend module
6364
"""
@@ -411,6 +412,11 @@ def _register_endpoints(self, providers):
411412
url_map.append(("(%s)/%s$" % (valid_providers, parsed_endp.path),
412413
functools.partial(self.handle_authn_request, binding_in=binding)))
413414

415+
if self.expose_entityid_endpoint():
416+
parsed_entity_id = urlparse(self.idp.config.entityid)
417+
url_map.append(("^{0}".format(parsed_entity_id.path[1:]),
418+
self._metadata_endpoint))
419+
414420
return url_map
415421

416422
def _build_idp_config_endpoints(self, config, providers):

0 commit comments

Comments
 (0)