Skip to content

Commit

Permalink
Raise an error when there are no SAML credentials in SAMLWAYFlessAcqu…
Browse files Browse the repository at this point in the history
…isitionLinkProcessor.fulfill
  • Loading branch information
vbessonov committed Feb 9, 2022
1 parent ba9d9df commit 50f1373
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions api/saml/wayfless.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,31 +149,35 @@ def fulfill(

self._logger.debug(f"SAML credentials: {saml_credential}")

if saml_credential:
saml_subject = self._saml_credential_manager.extract_saml_token(
saml_credential
if not saml_credential:
raise SAMLWAYFlessFulfillmentError(
f"There are no existing SAML credentials for patron {patron}"
)

self._logger.debug(f"SAML subject: {saml_subject}")
saml_subject = self._saml_credential_manager.extract_saml_token(
saml_credential
)

if not saml_subject.idp:
raise SAMLWAYFlessFulfillmentError(
f"SAML subject {saml_subject} does not contain an IdP's entityID"
)
self._logger.debug(f"SAML subject: {saml_subject}")

acquisition_link = acquisition_link_template.replace(
SAMLWAYFlessConfiguration.IDP_PLACEHOLDER,
urllib.parse.quote(saml_subject.idp, safe=""),
)
acquisition_link = acquisition_link.replace(
SAMLWAYFlessConfiguration.ACQUISITION_LINK_PLACEHOLDER,
urllib.parse.quote(fulfillment.content_link, safe=""),
if not saml_subject.idp:
raise SAMLWAYFlessFulfillmentError(
f"SAML subject {saml_subject} does not contain an IdP's entityID"
)

self._logger.debug(
f"Old acquisition link {fulfillment.content_link} has been transformed to {acquisition_link}"
)
acquisition_link = acquisition_link_template.replace(
SAMLWAYFlessConfiguration.IDP_PLACEHOLDER,
urllib.parse.quote(saml_subject.idp, safe=""),
)
acquisition_link = acquisition_link.replace(
SAMLWAYFlessConfiguration.ACQUISITION_LINK_PLACEHOLDER,
urllib.parse.quote(fulfillment.content_link, safe=""),
)

self._logger.debug(
f"Old acquisition link {fulfillment.content_link} has been transformed to {acquisition_link}"
)

fulfillment.content_link = acquisition_link
fulfillment.content_link = acquisition_link

return fulfillment

0 comments on commit 50f1373

Please sign in to comment.