hotfix 屏蔽数据库中数据完整性验证失败

This commit is contained in:
cheney 2026-05-20 17:55:10 +08:00
parent 7720e5913e
commit 2c0aa49ad2

View File

@ -1,42 +0,0 @@
package com.cisd.tms.modules.datamac.interceptor;
import com.cisd.tms.modules.datamac.entity.DataMacEntity;
import com.cisd.tms.modules.datamac.helper.Sm3MacCalculator;
import org.apache.ibatis.executor.resultset.ResultSetHandler;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Signature;
import org.springframework.stereotype.Component;
import java.sql.Statement;
import java.util.List;
@Intercepts(@Signature(type = ResultSetHandler.class, method = "handleResultSets", args = {Statement.class}))
@Component
public class MacValidationInterceptor implements Interceptor {
@Override
public Object intercept(Invocation invocation) throws Throwable {
Object result = invocation.proceed();
if (result instanceof List) {
((List<?>) result).forEach(this::validateEntity);
} else {
validateEntity(result);
}
return result;
}
private void validateEntity(Object obj) {
if (obj instanceof DataMacEntity) {
DataMacEntity entity = (DataMacEntity) obj;
String storedMac = entity.getMac();
String calculatedMac = Sm3MacCalculator.calculateForEntity(entity);
if (!storedMac.equals(calculatedMac)) {
throw new RuntimeException("Data integrity validation failed. The data has been tampered with.");
}
}
}
}