overrides.py 984 B

123456789101112131415161718192021222324
  1. import logging
  2. import saml2.client
  3. from django.conf import settings
  4. logger = logging.getLogger('djangosaml2')
  5. class Saml2Client(saml2.client.Saml2Client):
  6. """
  7. Custom Saml2Client that adds a choice of preference for binding used with
  8. SAML Logout Requests. The preferred binding can be configured via
  9. SAML_LOGOUT_REQUEST_PREFERRED_BINDING settings variable.
  10. (Original Saml2Client always prefers SOAP, so it is always used if declared
  11. in remote metadata); but doesn't actually work and causes crashes.
  12. """
  13. def do_logout(self, *args, **kwargs):
  14. if not kwargs.get('expected_binding'):
  15. try:
  16. kwargs['expected_binding'] = settings.SAML_LOGOUT_REQUEST_PREFERRED_BINDING
  17. except AttributeError:
  18. logger.warning('SAML_LOGOUT_REQUEST_PREFERRED_BINDING setting is'
  19. ' not defined. Default binding will be used.')
  20. return super(Saml2Client, self).do_logout(*args, **kwargs)