summaryrefslogtreecommitdiffstats
path: root/mellon/app_settings.py
blob: 3dd5b5784a19c22dba3d4f5332f43edd2e23362d (plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import sys
from django.core.exceptions import ImproperlyConfigured

class AppSettings(object):
    __PREFIX = 'MELLON_'
    __DEFAULTS = {
            'PUBLIC_KEYS': (),
            'PRIVATE_KEY': None,
            'PRIVATE_KEYS': (),
            'PRIVATE_KEY_PASSWORD': None,
            'NAME_ID_FORMATS': (),
            'NAME_ID_POLICY_FORMAT': None,
            'NAME_ID_POLICY_ALLOW_CREATE': True,
            'FORCE_AUTHN': False,
            'ADAPTER': (
                'mellon.adapters.DefaultAdapter',
             ),
            'REALM': 'saml',
            'PROVISION': True,
            'USERNAME_TEMPLATE': '{attributes[name_id_content]}@{realm}',
            'ATTRIBUTE_MAPPING': {},
            'SUPERUSER_MAPPING': {},
            'AUTHN_CLASSREF': (),
            'GROUP_ATTRIBUTE': None,
            'CREATE_GROUP': True,
            'ERROR_URL': None,
            'ERROR_REDIRECT_AFTER_TIMEOUT': 120,
            'DEFAULT_ASSERTION_CONSUMER_BINDING': 'post', # or artifact
    }

    @property
    def IDENTITY_PROVIDERS(self):
        from django.conf import settings
        try:
            idps = settings.MELLON_IDENTITY_PROVIDERS
        except AttributeError:
            raise ImproperlyConfigured('The MELLON_IDENTITY_PROVIDERS setting is mandatory')
        if isinstance(idps, dict):
            idps = [idps]
        return idps

    def __getattr__(self, name):
        from django.conf import settings
        if name not in self.__DEFAULTS:
            raise AttributeError
        return getattr(settings, self.__PREFIX + name, self.__DEFAULTS[name])

app_settings = AppSettings()
app_settings.__name__ = __name__
sys.modules[__name__] = app_settings