mirror of https://github.com/jumpserver/jumpserver
fix: 过期用户登录提示不明确
parent
c4bbeaaccc
commit
a9f814a515
|
@ -8,7 +8,7 @@ from django.core.cache import cache
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
from six import text_type
|
from six import text_type
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.contrib.auth.backends import ModelBackend as DJModelBackend
|
from django.contrib.auth.backends import ModelBackend
|
||||||
from rest_framework import HTTP_HEADER_ENCODING
|
from rest_framework import HTTP_HEADER_ENCODING
|
||||||
from rest_framework import authentication, exceptions
|
from rest_framework import authentication, exceptions
|
||||||
from common.auth import signature
|
from common.auth import signature
|
||||||
|
@ -17,6 +17,9 @@ from common.utils import get_object_or_none, make_signature, http_to_unixtime
|
||||||
from ..models import AccessKey, PrivateToken
|
from ..models import AccessKey, PrivateToken
|
||||||
|
|
||||||
|
|
||||||
|
UserModel = get_user_model()
|
||||||
|
|
||||||
|
|
||||||
def get_request_date_header(request):
|
def get_request_date_header(request):
|
||||||
date = request.META.get('HTTP_DATE', b'')
|
date = request.META.get('HTTP_DATE', b'')
|
||||||
if isinstance(date, text_type):
|
if isinstance(date, text_type):
|
||||||
|
@ -25,9 +28,16 @@ def get_request_date_header(request):
|
||||||
return date
|
return date
|
||||||
|
|
||||||
|
|
||||||
class ModelBackend(DJModelBackend):
|
class JMSModelBackend(ModelBackend):
|
||||||
def user_can_authenticate(self, user):
|
def user_can_authenticate(self, user):
|
||||||
return user.is_valid
|
return True
|
||||||
|
|
||||||
|
def get_user(self, user_id):
|
||||||
|
try:
|
||||||
|
user = UserModel._default_manager.get(pk=user_id)
|
||||||
|
except UserModel.DoesNotExist:
|
||||||
|
return None
|
||||||
|
return user if user.is_valid else None
|
||||||
|
|
||||||
|
|
||||||
class AccessKeyAuthentication(authentication.BaseAuthentication):
|
class AccessKeyAuthentication(authentication.BaseAuthentication):
|
||||||
|
@ -203,7 +213,7 @@ class SignatureAuthentication(signature.SignatureAuthentication):
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
|
|
||||||
class SSOAuthentication(ModelBackend):
|
class SSOAuthentication(JMSModelBackend):
|
||||||
"""
|
"""
|
||||||
什么也不做呀😺
|
什么也不做呀😺
|
||||||
"""
|
"""
|
||||||
|
@ -212,7 +222,7 @@ class SSOAuthentication(ModelBackend):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class WeComAuthentication(ModelBackend):
|
class WeComAuthentication(JMSModelBackend):
|
||||||
"""
|
"""
|
||||||
什么也不做呀😺
|
什么也不做呀😺
|
||||||
"""
|
"""
|
||||||
|
@ -221,7 +231,7 @@ class WeComAuthentication(ModelBackend):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class DingTalkAuthentication(ModelBackend):
|
class DingTalkAuthentication(JMSModelBackend):
|
||||||
"""
|
"""
|
||||||
什么也不做呀😺
|
什么也不做呀😺
|
||||||
"""
|
"""
|
||||||
|
@ -230,7 +240,7 @@ class DingTalkAuthentication(ModelBackend):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class AuthorizationTokenAuthentication(ModelBackend):
|
class AuthorizationTokenAuthentication(JMSModelBackend):
|
||||||
"""
|
"""
|
||||||
什么也不做呀😺
|
什么也不做呀😺
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -236,6 +236,11 @@ class AuthMixin:
|
||||||
ip = self.get_request_ip()
|
ip = self.get_request_ip()
|
||||||
request = self.request
|
request = self.request
|
||||||
|
|
||||||
|
if user.is_expired:
|
||||||
|
self.raise_credential_error(errors.reason_user_expired)
|
||||||
|
elif not user.is_active:
|
||||||
|
self.raise_credential_error(errors.reason_user_inactive)
|
||||||
|
|
||||||
self._set_partial_credential_error(user.username, ip, request)
|
self._set_partial_credential_error(user.username, ip, request)
|
||||||
self._check_is_local_user(user)
|
self._check_is_local_user(user)
|
||||||
self._check_is_block(user.username)
|
self._check_is_block(user.username)
|
||||||
|
|
|
@ -120,7 +120,7 @@ LOGIN_CONFIRM_ENABLE = CONFIG.LOGIN_CONFIRM_ENABLE
|
||||||
OTP_IN_RADIUS = CONFIG.OTP_IN_RADIUS
|
OTP_IN_RADIUS = CONFIG.OTP_IN_RADIUS
|
||||||
|
|
||||||
|
|
||||||
AUTH_BACKEND_MODEL = 'authentication.backends.api.ModelBackend'
|
AUTH_BACKEND_MODEL = 'authentication.backends.api.JMSModelBackend'
|
||||||
AUTH_BACKEND_PUBKEY = 'authentication.backends.pubkey.PublicKeyAuthBackend'
|
AUTH_BACKEND_PUBKEY = 'authentication.backends.pubkey.PublicKeyAuthBackend'
|
||||||
AUTH_BACKEND_LDAP = 'authentication.backends.ldap.LDAPAuthorizationBackend'
|
AUTH_BACKEND_LDAP = 'authentication.backends.ldap.LDAPAuthorizationBackend'
|
||||||
AUTH_BACKEND_OIDC_PASSWORD = 'jms_oidc_rp.backends.OIDCAuthPasswordBackend'
|
AUTH_BACKEND_OIDC_PASSWORD = 'jms_oidc_rp.backends.OIDCAuthPasswordBackend'
|
||||||
|
|
Loading…
Reference in New Issue