From d36e6379c0c24ed647a2680e5a04f593469b210b Mon Sep 17 00:00:00 2001 From: 05412 <2738076308@qq.com> Date: Thu, 25 Jul 2024 13:55:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AF=B7=E6=B1=82=E4=BD=93?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E9=80=BB=E8=BE=91=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../filter/UsernamePasswordAuthenticationCheckFilter.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/dev/surl/surl/filter/UsernamePasswordAuthenticationCheckFilter.kt b/src/main/java/dev/surl/surl/filter/UsernamePasswordAuthenticationCheckFilter.kt index f95e420..2fe0011 100644 --- a/src/main/java/dev/surl/surl/filter/UsernamePasswordAuthenticationCheckFilter.kt +++ b/src/main/java/dev/surl/surl/filter/UsernamePasswordAuthenticationCheckFilter.kt @@ -44,10 +44,12 @@ class UsernamePasswordAuthenticationCheckFilter( */ override fun attemptAuthentication(request: HttpServletRequest?, response: HttpServletResponse?): Authentication { request ?: throw IllegalArgumentException("request is null") - val userDto = request.run { - om.readValue(String(inputStream.readAllBytes(), StandardCharsets.UTF_8), UserDto::class.java) + val body = String(request.inputStream.readAllBytes(), StandardCharsets.UTF_8) + val userDto = try { + om.readValue(body, UserDto::class.java) + } catch (e: Exception) { + throw object : AuthenticationException("request body is invalid", e) {} } - // 尝试验证登录信息 try { validate(userDto, validator)