-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
408 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
sensitive-api/src/main/java/com/github/houbb/sensitive/api/IDeepCopy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.github.houbb.sensitive.api; | ||
|
||
/** | ||
* 深度拷贝接口 | ||
* @author binbin.hou | ||
* @since 0.0.9 | ||
* @param <T> 泛型 | ||
*/ | ||
public interface IDeepCopy { | ||
|
||
/** | ||
* 深度拷贝 | ||
* @param object 原始对象 | ||
* @return 结果 | ||
* @since 0.0.9 | ||
*/ | ||
<T> T deepCopy(T object); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
sensitive-api/src/main/java/com/github/houbb/sensitive/api/ISensitiveConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.github.houbb.sensitive.api; | ||
|
||
/** | ||
* 脱敏配置接口 | ||
* @author binbin.hou | ||
* @since 0.0.9 | ||
*/ | ||
public interface ISensitiveConfig { | ||
|
||
/** | ||
* 深度拷贝 | ||
* @return 深度拷贝 | ||
* @since 0.0.9 | ||
*/ | ||
IDeepCopy deepCopy(); | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
sensitive-core/src/main/java/com/github/houbb/sensitive/core/bs/SensitiveBs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package com.github.houbb.sensitive.core.bs; | ||
|
||
import com.github.houbb.heaven.support.instance.impl.Instances; | ||
import com.github.houbb.heaven.util.common.ArgUtil; | ||
import com.github.houbb.sensitive.api.IDeepCopy; | ||
import com.github.houbb.sensitive.api.ISensitive; | ||
import com.github.houbb.sensitive.api.ISensitiveConfig; | ||
import com.github.houbb.sensitive.core.api.SensitiveService; | ||
import com.github.houbb.sensitive.core.support.config.DefaultSensitiveConfig; | ||
import com.github.houbb.sensitive.core.support.deepcopy.FastJsonDeepCopy; | ||
|
||
/** | ||
* 脱敏引导类 | ||
* @author binbin.hou | ||
* @since 0.0.9 | ||
*/ | ||
public final class SensitiveBs { | ||
|
||
private SensitiveBs(){} | ||
|
||
/** | ||
* 深度拷贝 | ||
* @since 0.0.9 | ||
*/ | ||
private IDeepCopy deepCopy = Instances.singleton(FastJsonDeepCopy.class); | ||
|
||
/** | ||
* 脱敏实现 | ||
* @since 0.0.9 | ||
*/ | ||
private ISensitive sensitive = Instances.singleton(SensitiveService.class); | ||
|
||
/** | ||
* 新建实例 | ||
* @since 0.0.9 | ||
* @return 引导类实例 | ||
*/ | ||
public static SensitiveBs newInstance() { | ||
return new SensitiveBs(); | ||
} | ||
|
||
/** | ||
* 设置深度拷贝实现 | ||
* @param deepCopy 深度拷贝实现类 | ||
* @return this | ||
* @since 0.0.9 | ||
*/ | ||
public SensitiveBs deepCopy(IDeepCopy deepCopy) { | ||
ArgUtil.notNull(deepCopy, "deepCopy"); | ||
|
||
this.deepCopy = deepCopy; | ||
return this; | ||
} | ||
|
||
/** | ||
* 脱敏对象 | ||
* | ||
* 每次都创建一个新的对象,避免线程问题 | ||
* 可以使用 {@link ThreadLocal} 简单优化。 | ||
* @param object 原始对象 | ||
* @param <T> 泛型 | ||
* @return 脱敏后的对象 | ||
* @since 0.0.4 以前用的是单例。建议使用 spring 等容器管理 ISensitive 实现。 | ||
*/ | ||
@SuppressWarnings({"unchecked", "rawtypes"}) | ||
public <T> T desCopy(T object) { | ||
ISensitiveConfig config = buildConfig(); | ||
return (T) sensitive.desCopy(object, config); | ||
} | ||
|
||
/** | ||
* 返回脱敏后的对象 json | ||
* null 对象,返回字符串 "null" | ||
* @param object 对象 | ||
* @return 结果 json | ||
* @since 0.0.9 | ||
*/ | ||
@SuppressWarnings({"unchecked", "rawtypes"}) | ||
public String desJson(Object object) { | ||
ISensitiveConfig config = buildConfig(); | ||
return sensitive.desJson(object, config); | ||
} | ||
|
||
/** | ||
* 构建上下文 | ||
* @return 配置 | ||
* @since 0.0.9 | ||
*/ | ||
private ISensitiveConfig buildConfig() { | ||
return DefaultSensitiveConfig.newInstance() | ||
.deepCopy(deepCopy); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
.../src/main/java/com/github/houbb/sensitive/core/support/config/DefaultSensitiveConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.github.houbb.sensitive.core.support.config; | ||
|
||
import com.github.houbb.sensitive.api.IDeepCopy; | ||
import com.github.houbb.sensitive.api.ISensitiveConfig; | ||
|
||
/** | ||
* 默认脱敏配置实现 | ||
* @author binbin.hou | ||
* @since 0.0.9 | ||
*/ | ||
public class DefaultSensitiveConfig implements ISensitiveConfig { | ||
|
||
/** | ||
* 深度拷贝实现 | ||
* @since 0.0.9 | ||
*/ | ||
private IDeepCopy deepCopy; | ||
|
||
/** | ||
* 新建对象实例 | ||
* @since 0.0.9 | ||
* @return 实例 | ||
*/ | ||
public static DefaultSensitiveConfig newInstance() { | ||
return new DefaultSensitiveConfig(); | ||
} | ||
|
||
public DefaultSensitiveConfig deepCopy(IDeepCopy deepCopy) { | ||
this.deepCopy = deepCopy; | ||
return this; | ||
} | ||
|
||
@Override | ||
public IDeepCopy deepCopy() { | ||
return deepCopy; | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
...itive-core/src/main/java/com/github/houbb/sensitive/core/support/deepcopy/DeepCopies.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.github.houbb.sensitive.core.support.deepcopy; | ||
|
||
import com.github.houbb.heaven.support.instance.impl.Instances; | ||
import com.github.houbb.sensitive.api.IDeepCopy; | ||
import com.github.houbb.sensitive.core.util.BeanUtil; | ||
|
||
/** | ||
* 深度拷贝工具类 | ||
* @author binbin.hou | ||
* @since 0.0.9 | ||
*/ | ||
public final class DeepCopies { | ||
|
||
/** | ||
* 基于 json 的深度拷贝 | ||
* @return 深度拷贝实现 | ||
* @since 0.0.9 | ||
*/ | ||
public static IDeepCopy json() { | ||
return Instances.singleton(FastJsonDeepCopy.class); | ||
} | ||
|
||
} |
Oops, something went wrong.