Refactor LDAP support and add LDAP caching
This commit is contained in:
@@ -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.'))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user