Provides Spring and Spring Boot obfuscation support.
Add obfuscation-spring-boot-starter as a dependency to your project to get the following:
-
Autowire support for Obfuscator.
Instances ofObfuscator
can be autowired in two ways:- Annotate an autowired field, constructor argument or method argument with any of the obfuscator annotations of obfuscation-annotations, and an instance of the matching obfuscator will be autowired.
- With no obfuscator annotation present, a default obfuscator is used.
-
Autowire support for Obfuscated.
Declaring an autowired field, constructor argument or method argument asObfuscated
will automatically wrap the autowired field or argument. This supports both autowired values and beans.
The obfuscator to use is determined in one of two ways:- Annotate the field or argument with any of the obfuscator annotations of obfuscation-annotations to use the matching obfuscation rules.
- With no obfuscator annotation present, a default obfuscator is used.
The character representation can be specified using @RepresentedBy. If this annotation is not present, the default character representation is used.
Examples:
@Autowired
@ObfuscateFixedLength(8)
private Obfuscator obfuscator;
@Autowired
private Obfuscator defaultObfuscator;
@Value("${property}")
@ObfuscateFixedLength(8)
private Obfuscated<String> obfuscatedValue;
@Autowired
@ObfuscateFixedLength(8)
@RepresentedBy(MyCharacterRepresentation.class)
private Obfuscated<MyBean> obfuscatedBean;
Out-of-the-box, the default obfuscator is Obfuscator.fixedLength(3). This can be overridden in two ways:
- Provide a custom bean of type Obfuscator.
- Define the default obfuscator in the application properties. See Properties for more information.
If an ObfuscatorProvider type is already available as a bean, this bean will be used. Otherwise, the type is instantiated using Spring's own bean factory. This allows implementations to use autowired fields.
The automatic support for autowiring Obfuscator
and Obfuscated
only works when using obfuscation-spring-boot-starter
. To add obfuscation support to vanilla Spring:
- Add obfuscation-spring-beans as a dependency to your project instead of
obfuscation-spring-boot-starter
. - Provide a bean of type ObfuscatorSupportBeanFactoryPostProcessor to allow
Obfuscator
to be autowired as above. - Provide a bean of type ObfuscatedSupportBeanFactoryPostProcessor to allow
Obfuscated
to be autowired as above. - Optionally provide a custom bean of type Obfuscator to override the default
Obfuscator
.