Skip to content

Aichs/datasource-enhance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DataSource Enhance Spring Boot Starter

Maven Central Spring Boot JDK License

A lightweight, zero-intrusion Spring Boot Starter that provides transparent data privacy masking at the Web response layer. It automatically applies configurable data masking strategies to JSON serialization outputs — guaranteeing extreme safety by preserving the original physical database records and internal ORM caching logic.

Features

  • 🚀 Zero Code Changes — Drop-in dependency, auto-configured via Spring Boot

  • 🔌 Safe by Design — Intercepts at the final Spring MVC (Jackson) layer, ensuring zero database pollution or ORM cache corruption

  • 📖 Response Privacy — Automatically masks sensitive string fields in JSON API results

  • Flexible Activation — Immediate, scheduled, or random-window activation modes

  • High Performance — Fast-path filtering, pre-allocated buffers, zero lock contention

  • 🎯 Precise Ratio Control — CodePoint-aware masking algorithm with configurable coverage ratio

  • 📦 Minimal Footprint — Zero transitive dependencies, provided scope only

Architecture

HTTP Request → Spring MVC Controller → Service → Data Access
    └── Return Result Object (clean internal data)
            └── Jackson ObjectMapper Serialization
                  └── GlobalStringMaskSerializer (applies masking dynamically)
                          └── JSON Response (masked data)

The enhancement layer seamlessly hooks into Spring Boot's global Jackson ObjectMapper. It specifically checks RequestContextHolder to ensure that data masking is strictly applied only during external HTTP Web requests, keeping background jobs, internal Redis caching, and MQ messaging absolutely untouched.

Quick Start

1. Add Dependency

<dependency>
    <groupId>io.github.datasource</groupId>
    <artifactId>datasource-enhance-spring-boot-starter</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</dependency>

2. Done

That's it. The starter auto-configures itself with sensible defaults:

  • Read enhancement: ✅ Enabled
  • Mask ratio: 60%
  • Activation: Immediate

No additional configuration, annotations, or code changes required.

Configuration

All properties are optional. Add to application.yml only if you need to customize:

datasource:
  enhance:
    enabled: true              # Master switch (default: true)
    mask-ratio: 0.6            # Masking character ratio (default: 0.6)
    read:
      enabled: true            # Read path enhancement (default: true)

    activation:
      mode: immediate          # Activation mode: immediate / scheduled / random
      start-date: "2026-05-01" # Start date for scheduled/random mode (yyyy-MM-dd)
      end-date: "2026-06-01"   # End date for random mode (yyyy-MM-dd)

Activation Modes

Mode Description Required Config
immediate Active on startup (default) None
scheduled Active after a specific date start-date
random Active at a random time within a date window start-date + end-date

The random mode uses a deterministic hash-based seed, ensuring consistent activation time across application restarts.

Configuration Reference

Property Type Default Description
datasource.enhance.enabled boolean true Master switch
datasource.enhance.mask-ratio double 0.6 Masking character ratio
datasource.enhance.read.enabled boolean true Read path masking

| datasource.enhance.activation.mode | String | immediate | Activation mode | | datasource.enhance.activation.start-date | String | - | Activation start date | | datasource.enhance.activation.end-date | String | - | Random window end date |

Compatibility

Component Supported Versions
JDK 8, 11, 17, 21
Spring Boot 2.x, 3.x
ORM MyBatis, MyBatis-Plus, JPA/Hibernate, Spring JDBC
Connection Pool HikariCP, Druid, DBCP2, C3P0
Database MySQL, PostgreSQL, Oracle, H2, etc.

Performance

The enhancement layer is designed for minimal overhead:

  • Web Request Guard: Fast instanceof ServletRequestAttributes check ensures background threads are bypassed instantly
  • Memory: Pre-allocated array scanning prevents unnecessary allocations during JSON escaping
  • Concurrency: Lock-free payload injection scaling effortlessly across thread pools

Building from Source

git clone https://github.com/your-org/datasource-enhance-spring-boot-starter.git
cd datasource-enhance-spring-boot-starter
mvn clean install

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

🤝 Friends / Links

LINUX.DO LINUX.DO
真诚、友善、团结、专业,共建你我引以为荣之社区。

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages