Disable fresh login check in auth engines that won't support it

This commit is contained in:
Joseph Schorr 2017-12-12 16:00:38 -05:00
parent 524d77f527
commit 2214a2c7ad
5 changed files with 20 additions and 2 deletions

View file

@ -187,6 +187,11 @@ class UserAuthentication(object):
""" Returns whether this auth system supports using encrypted credentials. """ """ Returns whether this auth system supports using encrypted credentials. """
return self.state.supports_encrypted_credentials return self.state.supports_encrypted_credentials
@property
def supports_fresh_login(self):
""" Returns whether this auth system supports the fresh login check. """
return self.state.supports_fresh_login
def query_users(self, query, limit=20): def query_users(self, query, limit=20):
""" Performs a lookup against the user system for the specified query. The returned tuple """ Performs a lookup against the user system for the specified query. The returned tuple
will be of the form (results, federated_login_id, err_msg). If the method is unsupported, will be of the form (results, federated_login_id, err_msg). If the method is unsupported,

View file

@ -12,6 +12,10 @@ class AppTokenInternalAuth(object):
""" Forces all internal credential login to go through an app token, by disabling all other """ Forces all internal credential login to go through an app token, by disabling all other
access. access.
""" """
@property
def supports_fresh_login(self):
# Since there is no password.
return False
@property @property
def federated_service(self): def federated_service(self):

View file

@ -5,6 +5,10 @@ class DatabaseUsers(object):
def federated_service(self): def federated_service(self):
return None return None
@property
def supports_fresh_login(self):
return True
def ping(self): def ping(self):
""" Always assumed to be working. If the DB is broken, other checks will handle it. """ """ Always assumed to be working. If the DB is broken, other checks will handle it. """
return (True, None) return (True, None)

View file

@ -24,6 +24,10 @@ class FederatedUsers(object):
def federated_service(self): def federated_service(self):
return self._federated_service return self._federated_service
@property
def supports_fresh_login(self):
return True
@property @property
def supports_encrypted_credentials(self): def supports_encrypted_credentials(self):
return True return True

View file

@ -10,7 +10,7 @@ from flask_restful import Resource, abort, Api, reqparse
from flask_restful.utils.cors import crossdomain from flask_restful.utils.cors import crossdomain
from jsonschema import validate, ValidationError from jsonschema import validate, ValidationError
from app import app, metric_queue from app import app, metric_queue, authentication
from auth.permissions import (ReadRepositoryPermission, ModifyRepositoryPermission, from auth.permissions import (ReadRepositoryPermission, ModifyRepositoryPermission,
AdministerRepositoryPermission, UserReadPermission, AdministerRepositoryPermission, UserReadPermission,
UserAdminPermission) UserAdminPermission)
@ -300,7 +300,8 @@ def require_fresh_login(func):
last_login = session.get('login_time', datetime.datetime.min) last_login = session.get('login_time', datetime.datetime.min)
valid_span = datetime.datetime.now() - datetime.timedelta(minutes=10) valid_span = datetime.datetime.now() - datetime.timedelta(minutes=10)
if not user.password_hash or last_login >= valid_span: if (not user.password_hash or last_login >= valid_span or
not authentication.supports_fresh_login):
return func(*args, **kwargs) return func(*args, **kwargs)
raise FreshLoginRequired() raise FreshLoginRequired()