WL-1903 | Error handling for incorrect configuration of saml Auth.
This commit is contained in:
12
common/djangoapps/third_party_auth/exceptions.py
Normal file
12
common/djangoapps/third_party_auth/exceptions.py
Normal 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.'
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user