-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(jackson): use mode name to match obfuscate processor
- Loading branch information
Showing
10 changed files
with
93 additions
and
40 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
42 changes: 42 additions & 0 deletions
42
...ckson/src/main/java/com/power4j/fist/jackson/support/obfuscation/NoopStringObfuscate.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,42 @@ | ||
/* | ||
* Copyright 2024. ChenJun ([email protected] & https://github.com/John-Chan) | ||
* | ||
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* http://www.gnu.org/licenses/lgpl.html | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.power4j.fist.jackson.support.obfuscation; | ||
|
||
/** | ||
* @author CJ ([email protected]) | ||
* @since 1.0 | ||
*/ | ||
public class NoopStringObfuscate implements StringObfuscate { | ||
|
||
public final static String MODEL_ID = "noop"; | ||
|
||
@Override | ||
public String modeId() { | ||
return MODEL_ID; | ||
} | ||
|
||
@Override | ||
public String obfuscate(String value) throws Exception { | ||
return value; | ||
} | ||
|
||
@Override | ||
public String deobfuscate(String value) throws Exception { | ||
return value; | ||
} | ||
|
||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,10 +18,9 @@ | |
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.Map; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.function.Supplier; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
|
||
/** | ||
* @author CJ ([email protected]) | ||
|
@@ -32,24 +31,25 @@ public class StringObfuscateRegistry implements ObfuscateProcessorProvider { | |
|
||
public final static StringObfuscateRegistry INSTANCE = new StringObfuscateRegistry(); | ||
|
||
private final static Map<Class<?>, Supplier<StringObfuscate>> OBFUSCATE_MAP = new ConcurrentHashMap<>(); | ||
private final static List<StringObfuscate> INSTANCES = new CopyOnWriteArrayList<>(); | ||
|
||
static { | ||
registerObfuscate(SimpleStringObfuscate.class, SimpleStringObfuscate::ofDefault); | ||
registerObfuscate(new NoopStringObfuscate()); | ||
registerObfuscate(SimpleStringObfuscate.ofDefault()); | ||
} | ||
|
||
public static Optional<StringObfuscate> getObfuscateInstance(Class<? extends StringObfuscate> obfuscate) { | ||
return Optional.ofNullable(OBFUSCATE_MAP.get(obfuscate)).map(Supplier::get); | ||
} | ||
|
||
public static void registerObfuscate(Class<? extends StringObfuscate> obfuscate, | ||
Supplier<StringObfuscate> supplier) { | ||
OBFUSCATE_MAP.put(obfuscate, supplier); | ||
public static void registerObfuscate(StringObfuscate instance) { | ||
INSTANCES.add(instance); | ||
} | ||
|
||
@Override | ||
public Optional<StringObfuscate> getInstance(Class<? extends StringObfuscate> obfuscateClass) { | ||
return getObfuscateInstance(obfuscateClass); | ||
public Optional<StringObfuscate> getInstance(String mode) { | ||
for (StringObfuscate obfuscate : INSTANCES) { | ||
if (mode.equals(obfuscate.modeId())) { | ||
return Optional.of(obfuscate); | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
} |
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