bugfix:请求头带token, SecurityUtils 获取用户id 一直为0 #1195
parent
360fe689b1
commit
42a2772d1a
|
@ -78,6 +78,7 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
|
||||||
|
|
||||||
// 构建UsernamePasswordAuthenticationToken,这里密码为null,是因为提供了正确的JWT,实现自动登录
|
// 构建UsernamePasswordAuthenticationToken,这里密码为null,是因为提供了正确的JWT,实现自动登录
|
||||||
User user = new User();
|
User user = new User();
|
||||||
|
user.setId(jwtUser.getUserId());
|
||||||
user.setUsername(jwtUser.getUserName());
|
user.setUsername(jwtUser.getUserName());
|
||||||
user.setPassword(jwtUser.getPassword());
|
user.setPassword(jwtUser.getPassword());
|
||||||
Role role = new Role();
|
Role role = new Role();
|
||||||
|
|
|
@ -144,6 +144,7 @@ public class JwtUtils implements InitializingBean {
|
||||||
jwtUser.setUserName(username);
|
jwtUser.setUserName(username);
|
||||||
jwtUser.setPassword(user.getPassword());
|
jwtUser.setPassword(user.getPassword());
|
||||||
jwtUser.setRoleId(user.getRole().getId());
|
jwtUser.setRoleId(user.getRole().getId());
|
||||||
|
jwtUser.setUserId(user.getId());
|
||||||
|
|
||||||
return jwtUser;
|
return jwtUser;
|
||||||
} catch (InvalidJwtException e) {
|
} catch (InvalidJwtException e) {
|
||||||
|
|
|
@ -21,6 +21,7 @@ public class JwtUser {
|
||||||
EXCEPTION
|
EXCEPTION
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int userId;
|
||||||
private String userName;
|
private String userName;
|
||||||
|
|
||||||
private String password;
|
private String password;
|
||||||
|
@ -29,6 +30,14 @@ public class JwtUser {
|
||||||
|
|
||||||
private TokenStatus status;
|
private TokenStatus status;
|
||||||
|
|
||||||
|
public int getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserId(int userId) {
|
||||||
|
this.userId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
public String getUserName() {
|
public String getUserName() {
|
||||||
return userName;
|
return userName;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue