优化请求体解析逻辑,增加错误处理
This commit is contained in:
parent
c028147459
commit
d36e6379c0
@ -44,10 +44,12 @@ class UsernamePasswordAuthenticationCheckFilter(
|
|||||||
*/
|
*/
|
||||||
override fun attemptAuthentication(request: HttpServletRequest?, response: HttpServletResponse?): Authentication {
|
override fun attemptAuthentication(request: HttpServletRequest?, response: HttpServletResponse?): Authentication {
|
||||||
request ?: throw IllegalArgumentException("request is null")
|
request ?: throw IllegalArgumentException("request is null")
|
||||||
val userDto = request.run {
|
val body = String(request.inputStream.readAllBytes(), StandardCharsets.UTF_8)
|
||||||
om.readValue(String(inputStream.readAllBytes(), StandardCharsets.UTF_8), UserDto::class.java)
|
val userDto = try {
|
||||||
|
om.readValue(body, UserDto::class.java)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
throw object : AuthenticationException("request body is invalid", e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 尝试验证登录信息
|
// 尝试验证登录信息
|
||||||
try {
|
try {
|
||||||
validate(userDto, validator)
|
validate(userDto, validator)
|
||||||
|
Loading…
Reference in New Issue
Block a user