This class will manage all the authentication sources.
| 204 | |
| 205 | |
| 206 | class AuthSourceManager: |
| 207 | """This class will manage all the authentication sources. |
| 208 | """ |
| 209 | |
| 210 | def __init__(self, form, sources): |
| 211 | self.form = form |
| 212 | self.auth_sources = sources |
| 213 | self.source = None |
| 214 | self.source_friendly_name = INTERNAL |
| 215 | self.current_source = INTERNAL |
| 216 | self.update_auth_sources() |
| 217 | |
| 218 | def as_dict(self): |
| 219 | """ |
| 220 | Returns the dictionary object representing this object. |
| 221 | """ |
| 222 | |
| 223 | res = dict() |
| 224 | res['source_friendly_name'] = self.source_friendly_name |
| 225 | res['auth_sources'] = self.auth_sources |
| 226 | res['current_source'] = self.current_source |
| 227 | |
| 228 | return res |
| 229 | |
| 230 | def update_auth_sources(self): |
| 231 | # Only mutate the ordered list of auth sources when a user explicitly |
| 232 | # selected an auth method on the login form. |
| 233 | # |
| 234 | # Without this guard, a plain internal login POST (email/password) can |
| 235 | # incorrectly drop INTERNAL/LDAP and try OAUTH2 first, which then fails |
| 236 | # because no oauth2 provider button was provided. |
| 237 | if request.method != 'POST': |
| 238 | return |
| 239 | |
| 240 | if 'internal_button' in request.form: |
| 241 | for auth_src in [KERBEROS, OAUTH2]: |
| 242 | if auth_src in self.auth_sources: |
| 243 | self.auth_sources.remove(auth_src) |
| 244 | return |
| 245 | |
| 246 | if 'oauth2_button' in request.form: |
| 247 | if INTERNAL in self.auth_sources: |
| 248 | self.auth_sources.remove(INTERNAL) |
| 249 | if LDAP in self.auth_sources: |
| 250 | self.auth_sources.remove(LDAP) |
| 251 | return |
| 252 | |
| 253 | def set_current_source(self, source): |
| 254 | self.current_source = source |
| 255 | |
| 256 | @property |
| 257 | def get_current_source(self): |
| 258 | return self.current_source |
| 259 | |
| 260 | def set_source(self, source): |
| 261 | self.source = source |
| 262 | |
| 263 | @property |
no outgoing calls
no test coverage detected