Refactor LDAP support and add LDAP caching

This commit is contained in:
2020-11-06 20:55:04 +01:00
parent 1fef1e2b7a
commit b0d0f99492
6 changed files with 98 additions and 95 deletions

View File

@@ -1,15 +1,11 @@
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from .. import app_settings
from rest_framework import exceptions
from rest_framework.authentication import TokenAuthentication as DRFTokenAuthentication
from .models import AuthToken, get_default_expiry
if app_settings.USE_LDAP:
from ..ldap import LDAPConnection
AUTO_REFRESH = True
MIN_REFRESH_INTERVAL = 60
@@ -26,10 +22,6 @@ class TokenAuthentication(DRFTokenAuthentication):
except model.DoesNotExist:
raise exceptions.AuthenticationFailed(msg)
if app_settings.USE_LDAP:
if not LDAPConnection.get_instance().has_user(token.user.username):
raise exceptions.AuthenticationFailed('User is not listed in the LDAP registry.')
if not token.user.is_active:
raise exceptions.AuthenticationFailed(_('User inactive or deleted.'))