Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ protected AuthenticationToken createToken(ServletRequest servletRequest, Servlet
}

String username = JwtUtil.getUsername(token);
String salt = loginRedisService.getSalt(username);
String salt;
if (jwtProperties.isSaltCheck()){
salt = loginRedisService.getSalt(username);
}else{
salt = jwtProperties.getSecret();
}
return JwtToken.build(token, username, salt, jwtProperties.getExpireSecond());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,9 @@ public class JwtProperties {
*/
private boolean singleLogin;

/**
* 是否进行盐值校验
*/
private boolean saltCheck;

}
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,13 @@ public ApiResult login(LoginParam loginParam, HttpServletResponse response) {
log.error("登陆失败,loginParam:{}", loginParam);
return ApiResult.fail(ApiCode.LOGIN_EXCEPTION);
}
// 包装盐值
String newSalt = SaltUtil.getSalt(jwtProperties.getSecret(), loginSysUserVo.getSalt());
String newSalt;
if (jwtProperties.isSaltCheck()){
// 包装盐值
newSalt = SaltUtil.getSalt(jwtProperties.getSecret(), loginSysUserVo.getSalt());
}else{
newSalt = jwtProperties.getSecret();
}
// 删除登陆用户盐值,盐值保存到后台Redis缓存中
loginSysUserVo.setSalt(null);

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ spring-boot-plus:
redis-check: true
# true: 同一个账号只能是最后一次登陆token有效,false:同一个账号可多次登陆
single-login: false
# 盐值校验,如果不加自定义盐值,则使用secret校验
salt-check: true
############################ JWT end ###############################

############################### spring-boot-plus end ###############################
Expand Down