File: overrides.py

package info (click to toggle)
python-djangosaml2 1.11.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 700 kB
  • sloc: python: 3,066; xml: 327; makefile: 18; sh: 9
file content (30 lines) | stat: -rw-r--r-- 1,047 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import logging

from django.conf import settings

import saml2.client

logger = logging.getLogger("djangosaml2")


class Saml2Client(saml2.client.Saml2Client):
    """
    Custom Saml2Client that adds a choice of preference for binding used with
    SAML Logout Requests. The preferred binding can be configured via
    SAML_LOGOUT_REQUEST_PREFERRED_BINDING settings variable.
    (Original Saml2Client always prefers SOAP, so it is always used if declared
    in remote metadata); but doesn't actually work and causes crashes.
    """

    def do_logout(self, *args, **kwargs):
        if not kwargs.get("expected_binding"):
            try:
                kwargs["expected_binding"] = (
                    settings.SAML_LOGOUT_REQUEST_PREFERRED_BINDING
                )
            except AttributeError:
                logger.warning(
                    "SAML_LOGOUT_REQUEST_PREFERRED_BINDING setting is"
                    " not defined. Default binding will be used."
                )
        return super().do_logout(*args, **kwargs)