From 233ebeef28a51ecc5c5e0b95c1f2f62cac5a2c32 Mon Sep 17 00:00:00 2001 From: "chen.ma" Date: Sun, 30 Oct 2022 23:47:28 +0800 Subject: [PATCH] Optimize code exception information --- .../auth/filter/JWTAuthenticationFilter.java | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/hippo4j-server/hippo4j-auth/src/main/java/cn/hippo4j/auth/filter/JWTAuthenticationFilter.java b/hippo4j-server/hippo4j-auth/src/main/java/cn/hippo4j/auth/filter/JWTAuthenticationFilter.java index bf96f27f..f77f579a 100644 --- a/hippo4j-server/hippo4j-auth/src/main/java/cn/hippo4j/auth/filter/JWTAuthenticationFilter.java +++ b/hippo4j-server/hippo4j-auth/src/main/java/cn/hippo4j/auth/filter/JWTAuthenticationFilter.java @@ -17,16 +17,6 @@ package cn.hippo4j.auth.filter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import javax.servlet.FilterChain; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - import cn.hippo4j.auth.model.biz.user.JwtUser; import cn.hippo4j.auth.model.biz.user.LoginUser; import cn.hippo4j.auth.toolkit.JwtTokenUtil; @@ -35,7 +25,6 @@ import cn.hippo4j.common.toolkit.JSONUtil; import cn.hippo4j.common.web.base.Results; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; - import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; @@ -44,6 +33,15 @@ import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; +import javax.servlet.FilterChain; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + import static cn.hippo4j.auth.constant.Constants.SPLIT_COMMA; import static cn.hippo4j.common.constant.Constants.BASE_PATH; import static cn.hippo4j.common.constant.Constants.MAP_INITIAL_CAPACITY; @@ -75,9 +73,9 @@ public class JWTAuthenticationFilter extends UsernamePasswordAuthenticationFilte authenticate = authenticationManager.authenticate( new UsernamePasswordAuthenticationToken(loginUser.getUsername(), loginUser.getPassword(), new ArrayList())); } catch (BadCredentialsException e) { - log.warn("BadCredentialsException:{}", e.getMessage()); + log.warn("Bad credentials exception: {}", e.getMessage()); } catch (Exception e) { - log.error("attemptAuthentication error:", e); + log.error("Attempt authentication error", e); } return authenticate; }