Pārlūkot izejas kodu

1.添加登录异常处理

WoNiu 4 gadi atpakaļ
vecāks
revīzija
386a11e46b

+ 9 - 0
src/main/java/com/galaxis/manatee/controller/JwtAuthenticationFilter.java

@@ -4,6 +4,8 @@ import com.auth0.jwt.JWT;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.galaxis.manatee.constant.SecurityConstant;
 import com.galaxis.manatee.entity.User;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
 import org.springframework.security.authentication.AuthenticationManager;
 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
 import org.springframework.security.core.Authentication;
@@ -61,4 +63,11 @@ public class JwtAuthenticationFilter extends UsernamePasswordAuthenticationFilte
                 .sign(HMAC512(SecurityConstant.SECRET.getBytes()));
         res.addHeader(SecurityConstant.HEADER_STRING, SecurityConstant.TOKEN_PREFIX + token);
     }
+
+    @Override
+    protected void unsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, AuthenticationException failed) throws IOException {
+        response.setStatus(500);
+        response.getWriter().println("Login exception! Please check the username and password");
+    }
+
 }