mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 15:55:18 +08:00
针对企业双线接入的情况, 允许使用两个IP登录
This commit is contained in:
@@ -10,6 +10,7 @@ public class LoginDto {
|
||||
private String captchaId;
|
||||
private String captcha;
|
||||
private String ip;
|
||||
private String ip2;
|
||||
private String ua;
|
||||
private String userId;
|
||||
private String sessionId;
|
||||
|
||||
@@ -131,6 +131,7 @@ public class SessionService {
|
||||
.set(sessionId, objectMapper.writeValueAsString(dto), 1, TimeUnit.HOURS);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public void rebuildSession(String sessionId) {
|
||||
|
||||
if (StringUtils.isEmpty(sessionId)) {
|
||||
@@ -159,9 +160,28 @@ public class SessionService {
|
||||
String currentUa = RequestUtils.getUa(request);
|
||||
if (!StringUtils.equalsIgnoreCase(currentIp, loginDto.getIp())) {
|
||||
|
||||
log.warn("检测到IP变化: {} {}", loginDto, currentIp);
|
||||
logout(loginDto.getSessionId());
|
||||
throw new BizException("invalidToken", "检测到IP发生变化,请重新登录");
|
||||
// 针对企业双线接入的情况, 允许使用两个IP登录
|
||||
if (StringUtils.isEmpty(loginDto.getIp2())) {
|
||||
|
||||
loginDto.setIp2(currentIp);
|
||||
// 写入新的ip地址
|
||||
stringRedisTemplate
|
||||
.opsForValue()
|
||||
.set(
|
||||
sessionId,
|
||||
objectMapper.writeValueAsString(loginDto),
|
||||
1,
|
||||
TimeUnit.HOURS);
|
||||
} else {
|
||||
// 如果两个ip都不匹配, 则认为是异常登录
|
||||
if (!StringUtils.equalsIgnoreCase(currentIp, loginDto.getIp2())) {
|
||||
|
||||
log.warn("检测到IP变化: {} {}", loginDto, currentIp);
|
||||
|
||||
logout(loginDto.getSessionId());
|
||||
throw new BizException("invalidToken", "检测到IP发生变化,请重新登录");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!StringUtils.equalsIgnoreCase(currentUa, loginDto.getUa())) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user