当前位置: 首页 > wzjs >正文

网站域名注册流程百度seo公司电话

网站域名注册流程,百度seo公司电话,阿克苏网站建设服务,做公司中文网站需要注意什么防全表更新与删除插件 BlockAttackInnerInterceptor 是 MyBatis-Plus 框架提供的一个安全插件,专门用于防止恶意的全表更新和删除操作。该插件通过拦截 update 和 delete 语句,确保这些操作不会无意中影响到整个数据表,从而保护数据的完整性…

防全表更新与删除插件

BlockAttackInnerInterceptor 是 MyBatis-Plus 框架提供的一个安全插件,专门用于防止恶意的全表更新和删除操作。该插件通过拦截 update 和 delete 语句,确保这些操作不会无意中影响到整个数据表,从而保护数据的完整性和安全性。

功能特性

  • 阻止全表更新删除:插件能够识别并阻止没有指定条件的 update 和 delete 语句,这些语句可能会导致全表数据被修改或删除。
  • 保护数据安全:通过限制全表操作,减少因误操作或恶意攻击导致的数据丢失风险。

使用方法

  1. 注入插件:在 Spring Boot 配置类中,通过 @Bean 注解将 MybatisPlusInterceptor 注入到 Spring 容器中,并添加 BlockAttackInnerInterceptor 作为内部拦截器。
@Configuration
public class MybatisPlusConfig {@Beanpublic MybatisPlusInterceptor mybatisPlusInterceptor() {MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());return interceptor;}
}

  1. 配置拦截规则:插件默认拦截没有指定条件的 update 和 delete 语句。如果需要自定义拦截规则,可以参考 MyBatis-Plus 的文档进行配置。

测试示例

全表更新测试

以下测试示例展示了如何使用 BlockAttackInnerInterceptor 来防止全表更新操作。

@SpringBootTest
public class QueryWrapperTest {@Autowiredprivate UserService userService;/*** SQL:UPDATE user  SET name=?,email=?;*/@Testpublic void testFullUpdate() {User user = new User();user.setId(999L);user.setName("custom_name");user.setEmail("xxx@mail.com");// 由于没有指定更新条件,插件将抛出异常// com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Prohibition of table update operationAssertions.assertThrows(MybatisPlusException.class, () -> {userService.saveOrUpdate(user, null);});}
}

部分更新测试

以下测试示例展示了如何正确地执行部分更新操作,插件不会对此类操作进行拦截。

@SpringBootTest
public class QueryWrapperTest {@Autowiredprivate UserService userService;/*** SQL:UPDATE user  SET name=?, email=? WHERE id = ?;*/@Testpublic void testPartialUpdate() {LambdaUpdateWrapper<User> wrapper = new LambdaUpdateWrapper<>();wrapper.eq(User::getId, 1);User user = new User();user.setId(10L);user.setName("custom_name");user.setEmail("xxx@mail.com");// 由于指定了更新条件,插件不会拦截此操作userService.saveOrUpdate(user, wrapper);}
}

注意

  • 合理配置:确保在配置插件时,考虑到项目的实际需求,避免过度限制导致正常操作受阻。
  • 测试验证:在生产环境部署前,应充分测试插件的功能,确保其按预期工作。

BlockAttackInnerInterceptor 插件是 MyBatis-Plus 提供的一个重要的安全工具,它能够有效地防止全表更新和删除操作,保护数据库免受意外或恶意的数据破坏。通过合理配置和使用该插件,可以显著提高应用程序的数据安全性。

源码阅读

public class BlockAttackInnerInterceptor extends JsqlParserSupport implements InnerInterceptor {@Overridepublic void beforePrepare(StatementHandler sh, Connection connection, Integer transactionTimeout) {PluginUtils.MPStatementHandler handler = PluginUtils.mpStatementHandler(sh);MappedStatement ms = handler.mappedStatement();SqlCommandType sct = ms.getSqlCommandType();if (sct == SqlCommandType.UPDATE || sct == SqlCommandType.DELETE) {if (InterceptorIgnoreHelper.willIgnoreBlockAttack(ms.getId())) return;BoundSql boundSql = handler.boundSql();parserMulti(boundSql.getSql(), null);}}@Overrideprotected void processDelete(Delete delete, int index, String sql, Object obj) {this.checkWhere(delete.getTable().getName(), delete.getWhere(), "Prohibition of full table deletion");}@Overrideprotected void processUpdate(Update update, int index, String sql, Object obj) {this.checkWhere(update.getTable().getName(), update.getWhere(), "Prohibition of table update operation");}protected void checkWhere(String tableName, Expression where, String ex) {Assert.isFalse(this.fullMatch(where, this.getTableLogicField(tableName)), ex);}private boolean fullMatch(Expression where, String logicField) {if (where == null) {return true;}if (StringUtils.isNotBlank(logicField) && (where instanceof BinaryExpression)) {BinaryExpression binaryExpression = (BinaryExpression) where;if (StringUtils.equals(binaryExpression.getLeftExpression().toString(), logicField) || StringUtils.equals(binaryExpression.getRightExpression().toString(), logicField)) {return true;}}if (where instanceof EqualsTo) {// example: 1=1EqualsTo equalsTo = (EqualsTo) where;return StringUtils.equals(equalsTo.getLeftExpression().toString(), equalsTo.getRightExpression().toString());} else if (where instanceof NotEqualsTo) {// example: 1 != 2NotEqualsTo notEqualsTo = (NotEqualsTo) where;return !StringUtils.equals(notEqualsTo.getLeftExpression().toString(), notEqualsTo.getRightExpression().toString());} else if (where instanceof OrExpression) {OrExpression orExpression = (OrExpression) where;return fullMatch(orExpression.getLeftExpression(), logicField) || fullMatch(orExpression.getRightExpression(), logicField);} else if (where instanceof AndExpression) {AndExpression andExpression = (AndExpression) where;return fullMatch(andExpression.getLeftExpression(), logicField) && fullMatch(andExpression.getRightExpression(), logicField);} else if (where instanceof Parenthesis) {// example: (1 = 1)Parenthesis parenthesis = (Parenthesis) where;return fullMatch(parenthesis.getExpression(), logicField);}return false;}/*** 获取表名中的逻辑删除字段** @param tableName 表名* @return 逻辑删除字段*/private String getTableLogicField(String tableName) {if (StringUtils.isBlank(tableName)) {return StringUtils.EMPTY;}TableInfo tableInfo = TableInfoHelper.getTableInfo(tableName);if (tableInfo == null || !tableInfo.isWithLogicDelete() || tableInfo.getLogicDeleteFieldInfo() == null) {return StringUtils.EMPTY;}return tableInfo.getLogicDeleteFieldInfo().getColumn();}
}

http://www.dtcms.com/wzjs/54978.html

相关文章:

  • 即将发布的新品手机seo文章代写平台
  • 传统文化网站设计苏州seo网站管理
  • 郑州高新区做网站的公司足球排行榜前十名
  • 北京网站排名公司北京搜索优化推广公司
  • 网站建设市区中国万网域名注册服务内容
  • 烟台市做网站网站优化 秦皇岛
  • 网站建设开发数据库十大搜索引擎排行榜
  • WordPress采集淘宝头条插件武汉本地seo
  • 外贸营销单页网站seo推广岗位职责
  • 外贸网站用什么字体百度网盘网页登录入口
  • 个人建网站教程长沙sem培训
  • 网站平台方案设计天津外贸seo推广
  • 021新手学做网站广告投放是做什么的
  • wordpress模板获取数据库seo投放
  • WordPress集成插件seo关键词优化的技巧
  • 简要描述创建商务站点的商务重庆seo黄智
  • 企业网络搭建案例重庆网站seo技术
  • 专业做熟女的网站网页设计大作业
  • 京东的网站是哪家公司做的收录网站有哪些
  • 泰安定制网站建设公司百度关键词的费用是多少
  • 做外贸用哪个网站好seo上海公司
  • 安徽seo百度seo排名工具
  • 网站建设cms系统简述企业网站如何推广
  • 武汉网站开发whaa官网seo怎么做
  • 手表网网站网络推广方法
  • 成都市自住房建设网站市场营销策划书
  • 网站icon图标怎么加个人博客网站
  • wordpress中文企业主题 下载地址武汉网站seo公司
  • 做网站的是什么工程师优化seo
  • 网站优化 代码5188关键词平台