Project

General

Profile

0002-utils-allow-specifying-auth-level-when-getting-backe.patch

Valentin Deniaud, 29 May 2019 03:01 PM

Download (1.61 KB)

View differences:

Subject: [PATCH 2/4] utils: allow specifying auth level when getting backends
 (#33550)

 src/authentic2/utils.py | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
src/authentic2/utils.py
166 166
    return cls()
167 167

  
168 168

  
169
def get_backends(setting_name='IDP_BACKENDS'):
170
    '''Return the list of enabled cleaned backends.'''
169
def get_backends(setting_name='IDP_BACKENDS', required_auth_level=1):
170
    '''Return the list of enabled cleaned backends.
171

  
172
    required_auth_level param can be specified in order to filter backends on
173
    the authentication levels they provide. When set to 0, filtering is
174
    disabled.
175
    '''
171 176
    backends = []
172 177
    for backend_path in getattr(app_settings, setting_name):
173 178
        kwargs = {}
......
177 182
        # If no enabled method is defined on the backend, backend enabled by default.
178 183
        if hasattr(backend, 'enabled') and not backend.enabled():
179 184
            continue
185
        if required_auth_level:
186
            if not required_auth_level == getattr(backend, 'auth_level', 1):
187
                continue
180 188
        kwargs_settings = getattr(app_settings, setting_name + '_KWARGS', {})
181 189
        if backend_path in kwargs_settings:
182 190
            kwargs.update(kwargs_settings[backend_path])
183
-