Skip to content

Commit

Permalink
Merge pull request #111 from c00kiemon5ter/feature-entityid-endpoint
Browse files Browse the repository at this point in the history
Expose metadata endpoint via configuration option
  • Loading branch information
johanlundberg authored Jul 12, 2017
2 parents 3c4e6e6 + 73dbc2f commit b15f5ca
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/satosa/backends/saml2.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from saml2.extension.ui import NAMESPACE as UI_NAMESPACE
from saml2.metadata import create_metadata_string

from satosa.base import SAMLBaseModule
from .base import BackendModule
from ..exception import SATOSAAuthenticationError
from ..internal_data import (InternalResponse,
Expand All @@ -29,7 +30,7 @@
logger = logging.getLogger(__name__)


class SAMLBackend(BackendModule):
class SAMLBackend(BackendModule, SAMLBaseModule):
"""
A saml2 backend module (acting as a SP).
"""
Expand All @@ -51,7 +52,6 @@ def __init__(self, outgoing, internal_attributes, config, base_url, name):
:param name: name of the plugin
"""
super().__init__(outgoing, internal_attributes, base_url, name)

sp_config = SPConfig().load(copy.deepcopy(config["sp_config"]), False)
self.sp = Base(sp_config)

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

if self.expose_entityid_endpoint():
parsed_entity_id = urlparse(self.sp.config.entityid)
url_map.append(("^{0}".format(parsed_entity_id.path[1:]),
self._metadata_endpoint))

return url_map

def get_metadata_desc(self):
Expand Down
8 changes: 8 additions & 0 deletions src/satosa/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,11 @@ def run(self, context):
exc_info=True)
raise SATOSAUnknownError("Unknown error") from err
return resp


class SAMLBaseModule(object):
KEY_ENTITYID_ENDPOINT = 'entityid_endpoint'

def expose_entityid_endpoint(self):
value = self.config.get(self.KEY_ENTITYID_ENDPOINT, False)
return bool(value)
8 changes: 7 additions & 1 deletion src/satosa/frontends/saml2.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from saml2.samlp import name_id_policy_from_string
from saml2.server import Server

from satosa.base import SAMLBaseModule
from .base import FrontendModule
from ..internal_data import InternalRequest, UserIdHashType
from ..logging_util import satosa_logging
Expand Down Expand Up @@ -57,7 +58,7 @@ def hash_type_to_saml_name_id_format(hash_type):
return NAMEID_FORMAT_PERSISTENT


class SAMLFrontend(FrontendModule):
class SAMLFrontend(FrontendModule, SAMLBaseModule):
"""
A pysaml2 frontend module
"""
Expand Down Expand Up @@ -411,6 +412,11 @@ def _register_endpoints(self, providers):
url_map.append(("(%s)/%s$" % (valid_providers, parsed_endp.path),
functools.partial(self.handle_authn_request, binding_in=binding)))

if self.expose_entityid_endpoint():
parsed_entity_id = urlparse(self.idp.config.entityid)
url_map.append(("^{0}".format(parsed_entity_id.path[1:]),
self._metadata_endpoint))

return url_map

def _build_idp_config_endpoints(self, config, providers):
Expand Down

0 comments on commit b15f5ca

Please sign in to comment.