Merge remote-tracking branch 'origin/V1.00' into V1.00
This commit is contained in:
commit
d3793e393c
@ -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.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user