Skip to content

Commit b15f5ca

Browse files
Merge pull request #111 from c00kiemon5ter/feature-entityid-endpoint
Expose metadata endpoint via configuration option
2 parents 3c4e6e6 + 73dbc2f commit b15f5ca

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

src/satosa/backends/saml2.py

Lines changed: 7 additions & 2 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

@@ -278,6 +278,11 @@ def register_endpoints(self):
278278
url_map.append(
279279
("^%s$" % parsed_endp.path[1:], self.disco_response))
280280

281+
if self.expose_entityid_endpoint():
282+
parsed_entity_id = urlparse(self.sp.config.entityid)
283+
url_map.append(("^{0}".format(parsed_entity_id.path[1:]),
284+
self._metadata_endpoint))
285+
281286
return url_map
282287

283288
def get_metadata_desc(self):

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)