Giter VIP home page Giter VIP logo

mybatis-desensitize's Introduction

mybatis-desensitize

基于mybatis框架的数据脱敏方案,使用spring aop拦截mybatis的dao接口。功能包括:

  • 数据脱敏:数据脱敏后更新到数据库
  • 脱敏数据恢复:从数据库查询脱敏数据,恢复真实值
  • 数据回滚

Usage

maven依赖

<dependency>
	<groupId>com.wjy</groupId>
	<artifactId>mybatis-desensitize</artifactId>
	<version>1.0.0</version>
</dependency>

目标字段配置

配置文件*.properties配置,逗号,分割

## 脱敏目标字段例
de_sensitize_feilds = "mobile,idCardNo"
## 脱敏恢复字段例
re_sensitize_feilds = "mobile,bankNo"

目标字段匹配

  • 脱敏字段为基础类型:使用mybatis@param注解指定别名
  • 脱敏字段为pojo对象:反射获取pojo对象的属性
  • 脱敏数据恢复字段为基础类型:使用自定义的@ReturnFeild注解指定别名
  • 脱敏恢复数据字段为pojo对象:反射获取pojo对象的属性

数据处理实现

使用者需提供自己的数据脱敏和脱敏恢复方法,实现com.wjy.mybatis.desensitize.spi.ISensitize接口

拦截器注册

注册数据脱敏拦截器,配置要处理的脱敏字段

<bean id="customSpi" class="xxxxx">

<bean id="desensitizeInterceptor" class="com.wjy.mybatis.desensitize.aop.DesensitizeInterceptor">
      <property name="spi" ref="customSpi" />
      <property name="feildSet" value="${de_sensitize_feilds}" />
</bean>

注册数据脱敏恢复拦截器,配置要处理的脱敏恢复字段

<bean id="customSpi" class="xxxxx">

<bean id="resensitizeInterceptor" class="com.wjy.mybatis.desensitize.aop.ResensitizeInterceptor">
      <property name="spi" ref="customSpi" />
      <property name="feildSet" value="${re_sensitize_feilds}" />
</bean>

拦截器配置

数据脱敏后更新到数据库,参数为pojo类型

<aop:aspect ref="desensitizeInterceptor">
        <aop:pointcut id="beforeByEntity" expression="execution(public * com.xxx.dao.xxxDao.insert(..))" ></aop:pointcut>
        <aop:around pointcut-ref="beforeByEntity" method="beforeByEntity"></aop:around>
</aop:aspect>

数据脱敏后更新到数据库,参数为基础类型

<aop:aspect ref="desensitizeInterceptor">
        <aop:pointcut id="beforeByParam" expression="execution(public * com.xxx.dao.xxxDao.update(..))" ></aop:pointcut>
        <aop:around pointcut-ref="beforeByParam" method="beforeByParam"></aop:around>
</aop:aspect>

从数据库查询脱敏数据,恢复真实值。返回值为实体类型

<aop:aspect ref="resensitizeInterceptor">
        <aop:pointcut id="afterReturnByEntity" expression="execution(public * com.xxx.dao.xxxDao.select(..))" ></aop:pointcut>
        <aop:around pointcut-ref="afterReturnByEntity" method="afterReturnByEntity"></aop:around>
</aop:aspect>

从数据库查询脱敏数据,恢复真实值。返回值为基础类型

<aop:aspect ref="resensitizeInterceptor">
        <aop:pointcut id="afterReturnByParam" expression="execution(public * com.xxx.dao.xxxDao.selectXX(..))"></aop:pointcut>
        <aop:around pointcut-ref="afterReturnByParam" method="afterReturnByParam"></aop:around>
</aop:aspect>

mybatis-desensitize's People

Contributors

handsomestwei avatar weijiayu2018 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.