obfuscation-commons-lang

Provides functionality for obfuscating objects using Apache Commons Lang

License

License

GroupId

GroupId

com.github.robtimus
ArtifactId

ArtifactId

obfuscation-commons-lang
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

obfuscation-commons-lang
Provides functionality for obfuscating objects using Apache Commons Lang
Project URL

Project URL

https://robtimus.github.io/obfuscation-commons-lang/
Source Code Management

Source Code Management

https://github.com/robtimus/obfuscation-commons-lang

Download obfuscation-commons-lang

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.robtimus/obfuscation-commons-lang/ -->
<dependency>
    <groupId>com.github.robtimus</groupId>
    <artifactId>obfuscation-commons-lang</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.robtimus/obfuscation-commons-lang/
implementation 'com.github.robtimus:obfuscation-commons-lang:1.0.1'
// https://jarcasting.com/artifacts/com.github.robtimus/obfuscation-commons-lang/
implementation ("com.github.robtimus:obfuscation-commons-lang:1.0.1")
'com.github.robtimus:obfuscation-commons-lang:jar:1.0.1'
<dependency org="com.github.robtimus" name="obfuscation-commons-lang" rev="1.0.1">
  <artifact name="obfuscation-commons-lang" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.robtimus', module='obfuscation-commons-lang', version='1.0.1')
)
libraryDependencies += "com.github.robtimus" % "obfuscation-commons-lang" % "1.0.1"
[com.github.robtimus/obfuscation-commons-lang "1.0.1"]

Dependencies

compile (2)

Group / Artifact Type Version
com.github.robtimus : obfuscation-core jar 1.3
org.apache.commons : commons-lang3 jar 3.11

test (3)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter jar 5.7.0
org.hamcrest : hamcrest jar 2.2
org.mockito : mockito-core jar 3.5.13

Project Modules

There are no modules declared in this project.

obfuscation-commons-lang

Provides extensions to Apache Commons Lang for obfuscating objects.

Currently it has one extension: an obfuscating ToStringStyle. This can obfuscate fields when used with ToStringBuilder or similar classes.

To create an obfuscating ToStringStyle, use one of the factory methods of class ObfuscatingToStringStyle to create a builder, add fields, and build the result. For instance, using the default style:

ToStringStyle style = ObfuscatingToStringStyle.defaultStyle()
        .withField("password", Obfuscator.fixedLength(3))
        .build();

Available styles

Most of the styles available in Apache Commons Lang 3 are available, including the recursive and multi-line recursive style. The only style that has been omitted is the JSON toString style.

Immutability

Most of the styles available in Apache Commons Lang 3 are all immutable. The same cannot be said for the obfuscating styles, they are not immutable and not thread-safe. Reusing the same instance should not be done concurrently (reusing it in the same thread should be possible).

However, it is possible to create immutable suppliers instead:

Supplier<? extends ToStringStyle> styleSupplier = ObfuscatingToStringStyle.defaultStyle()
        .withField("password", Obfuscator.fixedLength(3))
        .supplier();

The difference between using build() and using supplier() is that supplier() is more light-weight if you need to create multiple styles with the same settings. Such a supplier can be used directly or using ThreadLocal. For instance, in a class:

private static final Supplier<? extends ToStringStyle> TO_STRING_STYLE = ObfuscatingToStringStyle.defaultStyle()
        ...
        .supplier();

...

@Override
public String toString() {
    return ToStringBuilder.reflectionToString(this, TO_STRING_STYLE.get());
}

Serializability

Obfuscating ToStringStyle instances are serializable if the obfuscators they use are. This most often means that they are not serializable, even though most ToStringStyle implementations are.

Extending ObfuscatingToStringStyle

See examples for some examples. These include both an example that simply reuses ObfuscatingToStringStyle.Builder, and one that provides a builder with more properties.

Versions

Version
1.0.1
1.0