0006-utils-allow-specifying-auth-level-when-getting-backe.patch
src/authentic2/utils.py | ||
---|---|---|
152 | 152 |
return cls() |
153 | 153 | |
154 | 154 | |
155 |
def get_backends(setting_name='IDP_BACKENDS'): |
|
156 |
'''Return the list of enabled cleaned backends.''' |
|
155 |
def get_backends(setting_name='IDP_BACKENDS', required_auth_level=1): |
|
156 |
'''Return the list of enabled cleaned backends. |
|
157 | ||
158 |
required_auth_level param allows to filter backends on the authentication |
|
159 |
levels they provide. When set to 0, filtering is disabled. |
|
160 |
''' |
|
157 | 161 |
backends = [] |
158 | 162 |
for backend_path in getattr(app_settings, setting_name): |
159 | 163 |
kwargs = {} |
... | ... | |
163 | 167 |
# If no enabled method is defined on the backend, backend enabled by default. |
164 | 168 |
if hasattr(backend, 'enabled') and not backend.enabled(): |
165 | 169 |
continue |
170 |
if required_auth_level and hasattr(backend, 'auth_level'): |
|
171 |
if backend.auth_level != required_auth_level: |
|
172 |
continue |
|
173 |
elif required_auth_level > 1: |
|
174 |
continue |
|
166 | 175 |
kwargs_settings = getattr(app_settings, setting_name + '_KWARGS', {}) |
167 | 176 |
if backend_path in kwargs_settings: |
168 | 177 |
kwargs.update(kwargs_settings[backend_path]) |
169 |
- |