Skip to content

Commit f7eb106

Browse files
skorandac00kiemon5ter
authored andcommitted
Add unsolicited query parameter to set disco policy
Add a query parameter to the unsolicted endpoint to allow setting the discovery service policy.
1 parent 548ac44 commit f7eb106

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/satosa/frontends/saml2.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,12 +1028,17 @@ class SAMLUnsolicitedFrontend(SAMLFrontend):
10281028
SAML standard.
10291029
"""
10301030
KEY_ENDPOINT = "endpoint"
1031-
KEY_DISCO_WHITE = "discovery_service_whitelist"
1031+
KEY_DISCO_URL_WHITE = "discovery_service_url_whitelist"
1032+
KEY_DISCO_POLICY_WHITE = "discovery_service_policy_whitelist"
10321033
KEY_QUERY_SP = "providerId"
10331034
KEY_QUERY_ACS = "shire"
10341035
KEY_QUERY_RELAY = "target"
1035-
KEY_QUERY_DISCO = "discoveryURL"
1036+
KEY_QUERY_DISCO_URL = "discoveryURL"
1037+
KEY_QUERY_DISCO_POLICY = "discoveryPolicy"
10361038
KEY_SAML_DISCOVERY_SERVICE_URL = SAMLBackend.KEY_SAML_DISCOVERY_SERVICE_URL
1039+
KEY_SAML_DISCOVERY_SERVICE_POLICY = (
1040+
SAMLBackend.KEY_SAML_DISCOVERY_SERVICE_POLICY
1041+
)
10371042
KEY_UNSOLICITED = "unsolicited"
10381043

10391044
def __init__(self, auth_req_callback_func, internal_attributes, config,
@@ -1082,14 +1087,17 @@ def unsolicited_endpoint(self, context):
10821087
target_sp_entity_id = request.get(self.KEY_QUERY_SP, None)
10831088
target_sp_acs_url = request.get(self.KEY_QUERY_ACS, None)
10841089
target_sp_relay_state_url = request.get(self.KEY_QUERY_RELAY, None)
1085-
requested_disco_url = request.get(self.KEY_QUERY_DISCO, None)
1090+
requested_disco_url = request.get(self.KEY_QUERY_DISCO_URL, None)
1091+
requested_disco_policy = request.get(self.KEY_QUERY_DISCO_POLICY, None)
10861092

10871093
logger.debug("Unsolicited target SP is {}".format(target_sp_entity_id))
10881094
logger.debug("Unsolicited ACS URL is {}".format(target_sp_acs_url))
10891095
logger.debug("Unsolicited relay state is {}".format(
10901096
target_sp_relay_state_url))
10911097
logger.debug("Unsolicted discovery URL is {}".format(
10921098
requested_disco_url))
1099+
logger.debug("Unsolicted discovery policy is {}".format(
1100+
requested_disco_policy))
10931101

10941102
# We only proceed with known federated SPs.
10951103
try:
@@ -1194,15 +1202,28 @@ def unsolicited_endpoint(self, context):
11941202
# If provided and is whitelisted set the discovery service to use.
11951203
if requested_disco_url:
11961204
allowed = (self.config[self.KEY_UNSOLICITED]
1197-
.get(self.KEY_DISCO_WHITE))
1205+
.get(self.KEY_DISCO_URL_WHITE))
11981206
if requested_disco_url not in allowed:
1199-
msg = "Discovery service {} not allowed"
1207+
msg = "Discovery service URL {} not allowed"
12001208
msg = msg.format(requested_disco_url)
12011209
satosa_logging(logger, logging.ERROR, msg, context.state)
12021210
raise SATOSAError(msg)
12031211

12041212
context.decorate(self.KEY_SAML_DISCOVERY_SERVICE_URL,
12051213
requested_disco_url)
12061214

1215+
# If provided and is whitelisted set the discovery policy to use.
1216+
if requested_disco_policy:
1217+
allowed = (self.config[self.KEY_UNSOLICITED]
1218+
.get(self.KEY_DISCO_POLICY_WHITE))
1219+
if requested_disco_policy not in allowed:
1220+
msg = "Discovery service policy {} not allowed"
1221+
msg = msg.format(requested_disco_policy)
1222+
satosa_logging(logger, logging.ERROR, msg, context.state)
1223+
raise SATOSAError(msg)
1224+
1225+
context.decorate(self.KEY_SAML_DISCOVERY_SERVICE_POLICY,
1226+
requested_disco_policy)
1227+
12071228
# Handle the authn request use the base class.
12081229
return self._handle_authn_request(context, BINDING_HTTP_POST, self.idp)

0 commit comments

Comments
 (0)