WL-1903 | Error handling for incorrect configuration of saml Auth.

This commit is contained in:
hasnain-naveed
2019-03-25 17:18:22 +05:00
parent 8e2b68e3f8
commit c554ef6dd9
2 changed files with 28 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
"""
Exceptions for SAML Authentication.
"""
from social_core.exceptions import AuthException
class IncorrectConfigurationException(AuthException):
"""
Error caused due to incorrect configuration.
"""
def __str__(self):
return 'There was an error in SAML authentication flow which might be caused by incorrect SAML configuration.'

View File

@@ -19,6 +19,7 @@ from enterprise.models import (
PendingEnterpriseCustomerUser
)
from third_party_auth.exceptions import IncorrectConfigurationException
from openedx.core.djangoapps.theming.helpers import get_current_request
STANDARD_SAML_PROVIDER_KEY = 'standard_saml_provider'
@@ -87,6 +88,21 @@ class SAMLAuthBackend(SAMLAuth): # pylint: disable=abstract-method
else:
return super(SAMLAuthBackend, self).generate_saml_config()
def get_user_id(self, details, response):
"""
Calling the parent function and handling the exception properly.
"""
try:
return super(SAMLAuthBackend, self).get_user_id(details, response)
except KeyError as ex:
log.warning(
u"Error in SAML authentication flow of IdP '{idp_name}': {message}".format(
message=ex.message,
idp_name=response.get('idp_name')
)
)
raise IncorrectConfigurationException(self)
def generate_metadata_xml(self, idp_name=None): # pylint: disable=arguments-differ
"""
Override of SAMLAuth.generate_metadata_xml to accept an optional idp parameter.