自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

三種常見(jiàn)的數(shù)據(jù)脫敏方案,你知道哪種?

數(shù)據(jù)庫(kù) 其他數(shù)據(jù)庫(kù)
數(shù)據(jù)脫敏插件,目前支持地址脫敏、銀行卡號(hào)脫敏、中文姓名脫敏、固話脫敏、身份證號(hào)脫敏、手機(jī)號(hào)脫敏、密碼脫敏 一個(gè)是正則脫敏、另外一個(gè)根據(jù)顯示長(zhǎng)度脫敏,默認(rèn)是正則脫敏,可以根據(jù)自己的需要配置自己的規(guī)則。

1、SQL數(shù)據(jù)脫敏實(shí)現(xiàn)

MYSQL(電話號(hào)碼,身份證)數(shù)據(jù)脫敏的實(shí)現(xiàn)

-- CONCAT()、LEFT()和RIGHT()字符串函數(shù)組合使用,請(qǐng)看下面具體實(shí)現(xiàn)
 
-- CONCAT(str1,str2,…):返回結(jié)果為連接參數(shù)產(chǎn)生的字符串
-- LEFT(str,len):返回從字符串str 開(kāi)始的len 最左字符
-- RIGHT(str,len):從字符串str 開(kāi)始,返回最右len 字符
 
-- 電話號(hào)碼脫敏sql:
 
SELECT mobilePhone AS 脫敏前電話號(hào)碼,CONCAT(LEFT(mobilePhone,3), '********' ) AS 脫敏后電話號(hào)碼 FROM t_s_user
 
-- 身份證號(hào)碼脫敏sql:
 
SELECT idcard AS 未脫敏身份證, CONCAT(LEFT(idcard,3), '****' ,RIGHT(idcard,4)) AS 脫敏后身份證號(hào) FROM t_s_user

2、JAVA數(shù)據(jù)脫敏實(shí)現(xiàn)

數(shù)據(jù)脫敏插件,目前支持地址脫敏、銀行卡號(hào)脫敏、中文姓名脫敏、固話脫敏、身份證號(hào)脫敏、手機(jī)號(hào)脫敏、密碼脫敏 一個(gè)是正則脫敏、另外一個(gè)根據(jù)顯示長(zhǎng)度脫敏,默認(rèn)是正則脫敏,可以根據(jù)自己的需要配置自己的規(guī)則。

3、mybatis-mate-sensitive-jackson

mybatisplus 的新作,可以測(cè)試使用,生產(chǎn)需要收費(fèi)。

根據(jù)定義的策略類(lèi)型,對(duì)數(shù)據(jù)進(jìn)行脫敏,當(dāng)然策略可以自定義。

# 目前已有
package mybatis.mate.strategy;
 
public interface SensitiveType {
    String chineseName = "chineseName";
    String idCard = "idCard";
    String phone = "phone";
    String mobile = "mobile";
    String address = "address";
    String email = "email";
    String bankCard = "bankCard";
    String password = "password";
    String carNumber = "carNumber";
}

Demo 代碼目錄

圖片圖片

1.pom.xml

<?xml versinotallow="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <groupId>com.baomidou</groupId>
        <artifactId>mybatis-mate-examples</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>mybatis-mate-sensitive-jackson</artifactId>
    <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
    </dependencies>
 
</project>

2.appliation.yml

# DataSource Config
spring:
  datasource:
#    driver-class-name: org.h2.Driver
#    schema: classpath:db/schema-h2.sql
#    data: classpath:db/data-h2.sql
#    url: jdbc:h2:mem:test
#    username: root
#    password: test
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/mybatis_mate?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimeznotallow=UTC
    username: root
    password: 123456
# Mybatis Mate 配置
mybatis-mate:
  cert:
    #  測(cè)試證書(shū)會(huì)失效,請(qǐng)勿正式環(huán)境使用
    grant: thisIsTestLicense
    license: as/bsBaSVrsA9FfjC/N77ruEt2/QZDrW+MHETNuEuZBra5mlaXZU+DE1ZvF8UjzlLCpH3TFVH3WPV+Ya7Ugiz1Rx4wSh/FK6Ug9lhos7rnsNaRB/+mR30aXqtlLt4dAmLAOCT56r9mikW+t1DDJY8TVhERWMjEipbqGO9oe1fqYCegCEX8tVCpToKr5J1g1V86mNsNnEGXujnLlEw9jBTrGxAyQroD7Ns1Dhwz1K4Y188mvmRQp9t7OYrpgsC7N9CXq1s1c2GtvfItHArkqHE4oDrhaPjpbMjFWLI5/XqZDtW3D+AVcH7pTcYZn6vzFfDZEmfDFV5fQlT3Rc+GENEg==
 
# Logger Config
logging:
  level:
    mybatis.mate: debug

3.Appliation啟動(dòng)類(lèi)

package mybatis.mate.sensitive.jackson;
 
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
 
@SpringBootApplication
public class SensitiveJacksonApplication {
 
    // 測(cè)試訪問(wèn) http://localhost:8080/info ,http://localhost:8080/list
    public static void main(String[] args) {
        SpringApplication.run(SensitiveJacksonApplication.class, args);
    }
}

4.配置類(lèi),自定義脫敏策略

package mybatis.mate.sensitive.jackson.config;
 
import mybatis.mate.databind.ISensitiveStrategy;
import mybatis.mate.strategy.SensitiveStrategy;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
 
@Configuration
public class SensitiveStrategyConfig {
 
    /**
     * 注入脫敏策略
     */
    @Bean
    public ISensitiveStrategy sensitiveStrategy() {
        // 自定義 testStrategy 類(lèi)型脫敏處理
        return new SensitiveStrategy().addStrategy("testStrategy", t -> t + "***test***");
    }
}

5.業(yè)務(wù)類(lèi)

User,注解標(biāo)識(shí)脫敏字段,及選用脫敏策略

package mybatis.mate.sensitive.jackson.entity;
 
import lombok.Getter;
import lombok.Setter;
import mybatis.mate.annotation.FieldSensitive;
import mybatis.mate.sensitive.jackson.config.SensitiveStrategyConfig;
import mybatis.mate.strategy.SensitiveType;
 
@Getter
@Setter
public class User {
    private Long id;
    /**
     * 這里是一個(gè)自定義的策略 {@link SensitiveStrategyConfig} 初始化注入
     */
    @FieldSensitive("testStrategy")
    private String username;
    /**
     * 默認(rèn)支持策略 {@link SensitiveType }
     */
    @FieldSensitive(SensitiveType.mobile)
    private String mobile;
    @FieldSensitive(SensitiveType.email)
    private String email;
 
}

UserController

package mybatis.mate.sensitive.jackson.controller;
 
import mybatis.mate.databind.ISensitiveStrategy;
import mybatis.mate.databind.RequestDataTransfer;
import mybatis.mate.sensitive.jackson.entity.User;
import mybatis.mate.sensitive.jackson.mapper.UserMapper;
import mybatis.mate.strategy.SensitiveType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@RestController
public class UserController {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private ISensitiveStrategy sensitiveStrategy;
 
    // 測(cè)試訪問(wèn) http://localhost:8080/info
    @GetMapping("/info")
    public User info() {
        return userMapper.selectById(1L);
    }
 
    // 測(cè)試返回 map 訪問(wèn) http://localhost:8080/map
    @GetMapping("/map")
    public Map<String, Object> map() {
        // 測(cè)試嵌套對(duì)象脫敏
        Map<String, Object> userMap = new HashMap<>();
        userMap.put("user", userMapper.selectById(1L));
        userMap.put("test", 123);
        userMap.put("userMap", new HashMap<String, Object>() {{
            put("user2", userMapper.selectById(2L));
            put("test2", "hi china");
        }});
        // 手動(dòng)調(diào)用策略脫敏
        userMap.put("mobile", sensitiveStrategy.getStrategyFunctionMap()
                .get(SensitiveType.mobile).apply("15315388888"));
        return userMap;
    }
 
    // 測(cè)試訪問(wèn) http://localhost:8080/list
    // 不脫敏 http://localhost:8080/list?skip=1
    @GetMapping("/list")
    public List<User> list(HttpServletRequest request) {
        if ("1".equals(request.getParameter("skip"))) {
            // 跳過(guò)脫密處理
            RequestDataTransfer.skipSensitive();
        }
        return userMapper.selectList(null);
    }
}

UserMapper

package mybatis.mate.sensitive.jackson.mapper;
 
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import mybatis.mate.sensitive.jackson.entity.User;
import org.apache.ibatis.annotations.Mapper;
 
@Mapper
public interface UserMapper extends BaseMapper<User> {
 
}

6.測(cè)試

[
  {
    "id": 1,
    "username": "Jone***test***",
    "mobile": "153******81",
    "email": "t****@baomidou.com"
  },
  {
    "id": 2,
    "username": "Jack***test***",
    "mobile": "153******82",
    "email": "t****@baomidou.com"
  },
  {
    "id": 3,
    "username": "Tom***test***",
    "mobile": "153******83",
    "email": "t****@baomidou.com"
  }
]

GET http://localhost:8080/list?skip=1

[
  {
    "id": 1,
    "username": "Jone",
    "mobile": "15315388881",
    "email": "test1@baomidou.com"
  },
  {
    "id": 2,
    "username": "Jack",
    "mobile": "15315388882",
    "email": "test2@baomidou.com"
  },
  {
    "id": 3,
    "username": "Tom",
    "mobile": "15315388883",
    "email": "test3@baomidou.com"
  }
]
責(zé)任編輯:武曉燕 來(lái)源: 一安未來(lái)
相關(guān)推薦

2021-10-10 12:29:27

機(jī)器人AI人工智能

2020-10-26 14:03:07

混合云云計(jì)算云遷移

2018-09-25 07:08:52

IAM身份及訪問(wèn)管理網(wǎng)絡(luò)安全

2019-09-05 09:15:50

數(shù)據(jù)容器Docker

2017-07-03 18:24:39

MySQL數(shù)據(jù)冗余庫(kù)

2022-03-22 10:24:48

Linux開(kāi)源Elasticsea

2025-04-01 00:18:55

2017-12-29 08:26:28

存儲(chǔ)引擎MySQL

2016-11-10 13:00:32

網(wǎng)絡(luò)傳輸協(xié)議pythonhttp

2021-08-10 10:14:14

存儲(chǔ)接口存儲(chǔ)設(shè)備存儲(chǔ)

2020-03-31 16:13:26

分布式事務(wù)方案TCC

2024-01-31 09:24:58

2010-09-25 15:07:08

SQL插入語(yǔ)句

2010-08-24 09:43:33

2009-08-04 09:09:56

Java常見(jiàn)異常

2023-02-02 14:24:08

物聯(lián)網(wǎng)數(shù)據(jù)分析云平臺(tái)

2009-11-10 13:19:09

動(dòng)態(tài)路由協(xié)議

2010-09-30 14:40:45

2011-09-15 15:08:27

2021-07-05 05:37:12

5G消息運(yùn)營(yíng)商
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)