Browse Source

feat(all): 修改工厂模拟登录的token失效问题

dist.1.3.0
zhaoqiaobo 10 months ago
parent
commit
05ab39cabd
  1. 19
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/interceptor/LocalServerLoginAccountsInterceptor.java
  2. 19
      blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/interceptor/LocalServerLoginAccountsInterceptor.java
  3. 19
      blade-service/logpm-factory-data/logpm-factory-data-mwh/src/main/java/com/logpm/factorydata/mwh/interceptor/LocalServerLoginAccountsInterceptor.java
  4. 17
      blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/interceptor/LocalServerLoginAccountsInterceptor.java
  5. 2
      blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/mq/NodeDataPushListener.java
  6. 19
      blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/interceptor/LocalServerLoginAccountsInterceptor.java
  7. 19
      blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/interceptor/LocalServerLoginAccountsInterceptor.java

19
blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/interceptor/LocalServerLoginAccountsInterceptor.java

@ -3,14 +3,16 @@ package com.logpm.factorydata.jinpai.interceptor;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject;
import com.logpm.factorydata.jinpai.wrapper.CustomHttpServletRequestWrapper;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springblade.common.cache.CacheNames;
import org.springblade.common.component.MockLoginService;
import org.springblade.common.constant.LauncherConstant;
import org.springblade.common.exception.CustomerException;
import org.springblade.common.wrapper.CustomHttpServletRequestWrapper;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.redis.lock.LockType;
import org.springblade.core.redis.lock.RedisLockClient;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.ThreadLocalUtil;
import org.springframework.core.env.Environment;
@ -26,6 +28,7 @@ import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
@Log4j2
@AllArgsConstructor
@ -33,18 +36,26 @@ public class LocalServerLoginAccountsInterceptor extends HandlerInterceptorAdapt
private final BladeRedis bladeRedis;
private final Environment environment;
private final RedisLockClient redisLockClient;
private final MockLoginService mockLoginService;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws CustomerException {
try {
CustomHttpServletRequestWrapper wrappedRequest = new CustomHttpServletRequestWrapper(request);
org.springblade.common.wrapper.CustomHttpServletRequestWrapper wrappedRequest = new CustomHttpServletRequestWrapper(request);
String account ="shujutongbu";
JSONObject data =bladeRedis.get(CacheNames.LOCAL_SERVER_USER+account);
if(Objects.isNull(data)){
data = mockLoginService.mockToken("627683",account);
bladeRedis.setEx(CacheNames.LOCAL_SERVER_USER+account,data,25919900L);
boolean flag = redisLockClient.tryLock("local_server_user", LockType.FAIR, 5000, 10000, TimeUnit.MILLISECONDS);
if(flag){
data =bladeRedis.get(CacheNames.LOCAL_SERVER_USER+account);
if(Objects.isNull(data)){
data = mockLoginService.mockToken("627683",account);
bladeRedis.setEx(CacheNames.LOCAL_SERVER_USER+account,data,25919900L);
redisLockClient.unLock("local_server_user", LockType.FAIR);
}
}
}
// 修改或添加header

19
blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/interceptor/LocalServerLoginAccountsInterceptor.java

@ -3,14 +3,16 @@ package com.logpm.factorydata.linsy.interceptor;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject;
import com.logpm.factorydata.linsy.wrapper.CustomHttpServletRequestWrapper;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springblade.common.cache.CacheNames;
import org.springblade.common.component.MockLoginService;
import org.springblade.common.constant.LauncherConstant;
import org.springblade.common.exception.CustomerException;
import org.springblade.common.wrapper.CustomHttpServletRequestWrapper;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.redis.lock.LockType;
import org.springblade.core.redis.lock.RedisLockClient;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.ThreadLocalUtil;
import org.springframework.core.env.Environment;
@ -26,6 +28,7 @@ import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
@Log4j2
@AllArgsConstructor
@ -33,18 +36,26 @@ public class LocalServerLoginAccountsInterceptor extends HandlerInterceptorAdapt
private final BladeRedis bladeRedis;
private final Environment environment;
private final RedisLockClient redisLockClient;
private final MockLoginService mockLoginService;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws CustomerException {
try {
CustomHttpServletRequestWrapper wrappedRequest = new CustomHttpServletRequestWrapper(request);
org.springblade.common.wrapper.CustomHttpServletRequestWrapper wrappedRequest = new CustomHttpServletRequestWrapper(request);
String account ="shujutongbu";
JSONObject data =bladeRedis.get(CacheNames.LOCAL_SERVER_USER+account);
if(Objects.isNull(data)){
data = mockLoginService.mockToken("627683",account);
bladeRedis.setEx(CacheNames.LOCAL_SERVER_USER+account,data,25919900L);
boolean flag = redisLockClient.tryLock("local_server_user", LockType.FAIR, 5000, 10000, TimeUnit.MILLISECONDS);
if(flag){
data =bladeRedis.get(CacheNames.LOCAL_SERVER_USER+account);
if(Objects.isNull(data)){
data = mockLoginService.mockToken("627683",account);
bladeRedis.setEx(CacheNames.LOCAL_SERVER_USER+account,data,25919900L);
redisLockClient.unLock("local_server_user", LockType.FAIR);
}
}
}
// 修改或添加header

19
blade-service/logpm-factory-data/logpm-factory-data-mwh/src/main/java/com/logpm/factorydata/mwh/interceptor/LocalServerLoginAccountsInterceptor.java

@ -3,14 +3,16 @@ package com.logpm.factorydata.mwh.interceptor;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject;
import com.logpm.factorydata.mwh.wrapper.CustomHttpServletRequestWrapper;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springblade.common.cache.CacheNames;
import org.springblade.common.component.MockLoginService;
import org.springblade.common.constant.LauncherConstant;
import org.springblade.common.exception.CustomerException;
import org.springblade.common.wrapper.CustomHttpServletRequestWrapper;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.redis.lock.LockType;
import org.springblade.core.redis.lock.RedisLockClient;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.ThreadLocalUtil;
import org.springframework.core.env.Environment;
@ -26,6 +28,7 @@ import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
@Log4j2
@AllArgsConstructor
@ -33,18 +36,26 @@ public class LocalServerLoginAccountsInterceptor extends HandlerInterceptorAdapt
private final BladeRedis bladeRedis;
private final Environment environment;
private final RedisLockClient redisLockClient;
private final MockLoginService mockLoginService;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws CustomerException {
try {
CustomHttpServletRequestWrapper wrappedRequest = new CustomHttpServletRequestWrapper(request);
org.springblade.common.wrapper.CustomHttpServletRequestWrapper wrappedRequest = new CustomHttpServletRequestWrapper(request);
String account ="shujutongbu";
JSONObject data =bladeRedis.get(CacheNames.LOCAL_SERVER_USER+account);
if(Objects.isNull(data)){
data = mockLoginService.mockToken("627683",account);
bladeRedis.setEx(CacheNames.LOCAL_SERVER_USER+account,data,25919900L);
boolean flag = redisLockClient.tryLock("local_server_user", LockType.FAIR, 5000, 10000, TimeUnit.MILLISECONDS);
if(flag){
data =bladeRedis.get(CacheNames.LOCAL_SERVER_USER+account);
if(Objects.isNull(data)){
data = mockLoginService.mockToken("627683",account);
bladeRedis.setEx(CacheNames.LOCAL_SERVER_USER+account,data,25919900L);
redisLockClient.unLock("local_server_user", LockType.FAIR);
}
}
}
// 修改或添加header

17
blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/interceptor/LocalServerLoginAccountsInterceptor.java

@ -3,14 +3,16 @@ package com.logpm.factorydata.olo.interceptor;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject;
import com.logpm.factorydata.olo.wrapper.CustomHttpServletRequestWrapper;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springblade.common.cache.CacheNames;
import org.springblade.common.component.MockLoginService;
import org.springblade.common.constant.LauncherConstant;
import org.springblade.common.exception.CustomerException;
import org.springblade.common.wrapper.CustomHttpServletRequestWrapper;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.redis.lock.LockType;
import org.springblade.core.redis.lock.RedisLockClient;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.ThreadLocalUtil;
import org.springframework.core.env.Environment;
@ -26,6 +28,7 @@ import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
@Log4j2
@AllArgsConstructor
@ -33,6 +36,7 @@ public class LocalServerLoginAccountsInterceptor extends HandlerInterceptorAdapt
private final BladeRedis bladeRedis;
private final Environment environment;
private final RedisLockClient redisLockClient;
private final MockLoginService mockLoginService;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws CustomerException {
@ -43,8 +47,15 @@ public class LocalServerLoginAccountsInterceptor extends HandlerInterceptorAdapt
String account ="shujutongbu";
JSONObject data =bladeRedis.get(CacheNames.LOCAL_SERVER_USER+account);
if(Objects.isNull(data)){
data = mockLoginService.mockToken("627683",account);
bladeRedis.setEx(CacheNames.LOCAL_SERVER_USER+account,data,25919900L);
boolean flag = redisLockClient.tryLock("local_server_user", LockType.FAIR, 5000, 10000, TimeUnit.MILLISECONDS);
if(flag){
data =bladeRedis.get(CacheNames.LOCAL_SERVER_USER+account);
if(Objects.isNull(data)){
data = mockLoginService.mockToken("627683",account);
bladeRedis.setEx(CacheNames.LOCAL_SERVER_USER+account,data,25919900L);
redisLockClient.unLock("local_server_user", LockType.FAIR);
}
}
}
// 修改或添加header

2
blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/mq/NodeDataPushListener.java

@ -25,6 +25,7 @@ import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
@ -49,6 +50,7 @@ public class NodeDataPushListener {
exchange = @Exchange(name = FactoryDataConstants.Mq.Exchanges.NODE_DATA_PUSH, type = ExchangeTypes.TOPIC),
key = FactoryDataConstants.Mq.RoutingKeys.OLO_NODE_DATA_PUSH
))
@Transactional(rollbackFor = Exception.class)
public void nodeDataPush(String msg) {
log.info("接收到节点数据推送:{}", msg);
if (checkData(msg)) {

19
blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/interceptor/LocalServerLoginAccountsInterceptor.java

@ -3,14 +3,16 @@ package com.logpm.factorydata.suofeiya.interceptor;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject;
import com.logpm.factorydata.suofeiya.wrapper.CustomHttpServletRequestWrapper;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springblade.common.cache.CacheNames;
import org.springblade.common.component.MockLoginService;
import org.springblade.common.constant.LauncherConstant;
import org.springblade.common.exception.CustomerException;
import org.springblade.common.wrapper.CustomHttpServletRequestWrapper;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.redis.lock.LockType;
import org.springblade.core.redis.lock.RedisLockClient;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.ThreadLocalUtil;
import org.springframework.core.env.Environment;
@ -26,6 +28,7 @@ import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
@Log4j2
@AllArgsConstructor
@ -33,18 +36,26 @@ public class LocalServerLoginAccountsInterceptor extends HandlerInterceptorAdapt
private final BladeRedis bladeRedis;
private final Environment environment;
private final RedisLockClient redisLockClient;
private final MockLoginService mockLoginService;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws CustomerException {
try {
CustomHttpServletRequestWrapper wrappedRequest = new CustomHttpServletRequestWrapper(request);
org.springblade.common.wrapper.CustomHttpServletRequestWrapper wrappedRequest = new CustomHttpServletRequestWrapper(request);
String account ="shujutongbu";
JSONObject data =bladeRedis.get(CacheNames.LOCAL_SERVER_USER+account);
if(Objects.isNull(data)){
data = mockLoginService.mockToken("627683",account);
bladeRedis.setEx(CacheNames.LOCAL_SERVER_USER+account,data,25919900L);
boolean flag = redisLockClient.tryLock("local_server_user", LockType.FAIR, 5000, 10000, TimeUnit.MILLISECONDS);
if(flag){
data =bladeRedis.get(CacheNames.LOCAL_SERVER_USER+account);
if(Objects.isNull(data)){
data = mockLoginService.mockToken("627683",account);
bladeRedis.setEx(CacheNames.LOCAL_SERVER_USER+account,data,25919900L);
redisLockClient.unLock("local_server_user", LockType.FAIR);
}
}
}
// 修改或添加header

19
blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/interceptor/LocalServerLoginAccountsInterceptor.java

@ -3,14 +3,16 @@ package com.logpm.factorydata.zbom.interceptor;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject;
import com.logpm.factorydata.zbom.wrapper.CustomHttpServletRequestWrapper;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springblade.common.cache.CacheNames;
import org.springblade.common.component.MockLoginService;
import org.springblade.common.constant.LauncherConstant;
import org.springblade.common.exception.CustomerException;
import org.springblade.common.wrapper.CustomHttpServletRequestWrapper;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.redis.lock.LockType;
import org.springblade.core.redis.lock.RedisLockClient;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.ThreadLocalUtil;
import org.springframework.core.env.Environment;
@ -26,6 +28,7 @@ import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
@Log4j2
@AllArgsConstructor
@ -33,18 +36,26 @@ public class LocalServerLoginAccountsInterceptor extends HandlerInterceptorAdapt
private final BladeRedis bladeRedis;
private final Environment environment;
private final RedisLockClient redisLockClient;
private final MockLoginService mockLoginService;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws CustomerException {
try {
CustomHttpServletRequestWrapper wrappedRequest = new CustomHttpServletRequestWrapper(request);
org.springblade.common.wrapper.CustomHttpServletRequestWrapper wrappedRequest = new CustomHttpServletRequestWrapper(request);
String account ="shujutongbu";
JSONObject data =bladeRedis.get(CacheNames.LOCAL_SERVER_USER+account);
if(Objects.isNull(data)){
data = mockLoginService.mockToken("627683",account);
bladeRedis.setEx(CacheNames.LOCAL_SERVER_USER+account,data,25919900L);
boolean flag = redisLockClient.tryLock("local_server_user", LockType.FAIR, 5000, 10000, TimeUnit.MILLISECONDS);
if(flag){
data =bladeRedis.get(CacheNames.LOCAL_SERVER_USER+account);
if(Objects.isNull(data)){
data = mockLoginService.mockToken("627683",account);
bladeRedis.setEx(CacheNames.LOCAL_SERVER_USER+account,data,25919900L);
redisLockClient.unLock("local_server_user", LockType.FAIR);
}
}
}
// 修改或添加header

Loading…
Cancel
Save