From 2e118665f5944d9355aaaa8b8077e46c840d5da8 Mon Sep 17 00:00:00 2001 From: xinwen Date: Mon, 17 May 2021 19:50:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=BF=87=E6=9C=9F=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E9=80=80=E5=87=BA=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/authentication/backends/api.py | 7 ++++++- apps/jumpserver/settings/auth.py | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/authentication/backends/api.py b/apps/authentication/backends/api.py index 63356eff6..9da3bbbc3 100644 --- a/apps/authentication/backends/api.py +++ b/apps/authentication/backends/api.py @@ -8,7 +8,7 @@ from django.core.cache import cache from django.utils.translation import ugettext as _ from six import text_type from django.contrib.auth import get_user_model -from django.contrib.auth.backends import ModelBackend +from django.contrib.auth.backends import ModelBackend as DJModelBackend from rest_framework import HTTP_HEADER_ENCODING from rest_framework import authentication, exceptions from common.auth import signature @@ -25,6 +25,11 @@ def get_request_date_header(request): return date +class ModelBackend(DJModelBackend): + def user_can_authenticate(self, user): + return user.is_valid + + class AccessKeyAuthentication(authentication.BaseAuthentication): """App使用Access key进行签名认证, 目前签名算法比较简单, app注册或者手动建立后,会生成 access_key_id 和 access_key_secret, diff --git a/apps/jumpserver/settings/auth.py b/apps/jumpserver/settings/auth.py index 9fe5886c0..502146f13 100644 --- a/apps/jumpserver/settings/auth.py +++ b/apps/jumpserver/settings/auth.py @@ -120,7 +120,7 @@ LOGIN_CONFIRM_ENABLE = CONFIG.LOGIN_CONFIRM_ENABLE OTP_IN_RADIUS = CONFIG.OTP_IN_RADIUS -AUTH_BACKEND_MODEL = 'django.contrib.auth.backends.ModelBackend' +AUTH_BACKEND_MODEL = 'authentication.backends.api.ModelBackend' AUTH_BACKEND_PUBKEY = 'authentication.backends.pubkey.PublicKeyAuthBackend' AUTH_BACKEND_LDAP = 'authentication.backends.ldap.LDAPAuthorizationBackend' AUTH_BACKEND_OIDC_PASSWORD = 'jms_oidc_rp.backends.OIDCAuthPasswordBackend'