From 42a2772d1aa7493bcc4fac3e24ee8eda4eebc23d Mon Sep 17 00:00:00 2001 From: xubinbin <1323875150@qq.com> Date: Tue, 12 Dec 2023 17:09:04 +0800 Subject: [PATCH] =?UTF-8?q?bugfix=EF=BC=9A=E8=AF=B7=E6=B1=82=E5=A4=B4?= =?UTF-8?q?=E5=B8=A6token=EF=BC=8C=20SecurityUtils=20=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=94=A8=E6=88=B7id=20=E4=B8=80=E7=9B=B4=E4=B8=BA0=20#1195?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/vmp/conf/security/JwtAuthenticationFilter.java | 1 + .../com/genersoft/iot/vmp/conf/security/JwtUtils.java | 1 + .../com/genersoft/iot/vmp/conf/security/dto/JwtUser.java | 9 +++++++++ 3 files changed, 11 insertions(+) diff --git a/src/main/java/com/genersoft/iot/vmp/conf/security/JwtAuthenticationFilter.java b/src/main/java/com/genersoft/iot/vmp/conf/security/JwtAuthenticationFilter.java index f35b5bd8..f45f89a1 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/security/JwtAuthenticationFilter.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/security/JwtAuthenticationFilter.java @@ -78,6 +78,7 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter { // 构建UsernamePasswordAuthenticationToken,这里密码为null,是因为提供了正确的JWT,实现自动登录 User user = new User(); + user.setId(jwtUser.getUserId()); user.setUsername(jwtUser.getUserName()); user.setPassword(jwtUser.getPassword()); Role role = new Role(); diff --git a/src/main/java/com/genersoft/iot/vmp/conf/security/JwtUtils.java b/src/main/java/com/genersoft/iot/vmp/conf/security/JwtUtils.java index 65e9de37..3df75936 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/security/JwtUtils.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/security/JwtUtils.java @@ -144,6 +144,7 @@ public class JwtUtils implements InitializingBean { jwtUser.setUserName(username); jwtUser.setPassword(user.getPassword()); jwtUser.setRoleId(user.getRole().getId()); + jwtUser.setUserId(user.getId()); return jwtUser; } catch (InvalidJwtException e) { diff --git a/src/main/java/com/genersoft/iot/vmp/conf/security/dto/JwtUser.java b/src/main/java/com/genersoft/iot/vmp/conf/security/dto/JwtUser.java index 8921a308..df29c333 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/security/dto/JwtUser.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/security/dto/JwtUser.java @@ -21,6 +21,7 @@ public class JwtUser { EXCEPTION } + private int userId; private String userName; private String password; @@ -29,6 +30,14 @@ public class JwtUser { private TokenStatus status; + public int getUserId() { + return userId; + } + + public void setUserId(int userId) { + this.userId = userId; + } + public String getUserName() { return userName; }