From 8ee7230eadd3f651fe45b55debd5a436b6f26ac5 Mon Sep 17 00:00:00 2001 From: ibuler Date: Fri, 31 Jul 2020 19:40:27 +0800 Subject: [PATCH] =?UTF-8?q?fix(auth):=20=E4=BF=AE=E5=A4=8Dradius=20decode?= =?UTF-8?q?=20error=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/authentication/backends/radius.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/apps/authentication/backends/radius.py b/apps/authentication/backends/radius.py index e45fd8033..8edd2124c 100644 --- a/apps/authentication/backends/radius.py +++ b/apps/authentication/backends/radius.py @@ -1,11 +1,11 @@ # -*- coding: utf-8 -*- # +import traceback from django.contrib.auth import get_user_model from radiusauth.backends import RADIUSBackend, RADIUSRealmBackend from django.conf import settings -from pyrad.packet import AccessRequest User = get_user_model() @@ -27,6 +27,17 @@ class CreateUserMixin: user.save() return user + def _perform_radius_auth(self, client, packet): + # TODO: 等待官方库修复这个BUG + try: + return super()._perform_radius_auth(client, packet) + except UnicodeError as e: + import sys + tb = ''.join(traceback.format_exception(*sys.exc_info(), limit=2, chain=False)) + if tb.find("cl.decode") != -1: + return [], False, False + return None + def authenticate(self, *args, **kwargs): # 校验用户时,会传入public_key参数,父类authentication中不接受public_key参数,所以要pop掉 # TODO:需要优化各backend的authenticate方法,django进行调用前会检测各authenticate的参数