-
Notifications
You must be signed in to change notification settings - Fork 124
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
5 changed files
with
98 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<artifactId>smallrye-config-parent</artifactId> | ||
<groupId>io.smallrye.config</groupId> | ||
<version>2.12.2-SNAPSHOT</version> | ||
<relativePath>../../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>smallrye-config-jasypt</artifactId> | ||
|
||
<name>SmallRye Config: Jasypt</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.smallrye.config</groupId> | ||
<artifactId>smallrye-config</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jasypt</groupId> | ||
<artifactId>jasypt</artifactId> | ||
<version>1.9.3</version> | ||
</dependency> | ||
|
||
<!-- Test --> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.smallrye.testing</groupId> | ||
<artifactId>smallrye-testing-utilities</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>jakarta.annotation</groupId> | ||
<artifactId>jakarta.annotation-api</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
26 changes: 26 additions & 0 deletions
26
utils/jasypt/src/main/java/io/smallrye/config/jasypt/JasyptSecretKeysHandler.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,26 @@ | ||
package io.smallrye.config.jasypt; | ||
|
||
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor; | ||
import org.jasypt.iv.RandomIvGenerator; | ||
import org.jasypt.properties.PropertyValueEncryptionUtils; | ||
|
||
import io.smallrye.config.SecretKeysHandler; | ||
|
||
public class JasyptSecretKeysHandler implements SecretKeysHandler { | ||
@Override | ||
public String handleSecret(final String secret) { | ||
// TODO - We need to be able to configure this in the Handler. | ||
// Option to configure it in the constructor or retrieve config on the fly? | ||
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor(); | ||
encryptor.setPassword("jasypt"); | ||
encryptor.setAlgorithm("PBEWithHMACSHA512AndAES_256"); | ||
encryptor.setIvGenerator(new RandomIvGenerator()); | ||
encryptor.initialize(); | ||
return PropertyValueEncryptionUtils.decrypt(secret, encryptor); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "jasypt"; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
utils/jasypt/src/main/resources/META-INF/services/io.smallrye.config.SecretKeysHandler
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 @@ | ||
io.smallrye.config.jasypt.JasyptSecretKeysHandler |
28 changes: 28 additions & 0 deletions
28
utils/jasypt/src/test/java/io/smallrye/config/jasypt/JasyptSecretKeysHandlerTest.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,28 @@ | ||
package io.smallrye.config.jasypt; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.smallrye.config.PropertiesConfigSource; | ||
import io.smallrye.config.SmallRyeConfig; | ||
import io.smallrye.config.SmallRyeConfigBuilder; | ||
|
||
class JasyptSecretKeysHandlerTest { | ||
@Test | ||
void jasypt() { | ||
Map<String, String> properties = new HashMap<>(); | ||
properties.put("my.secret", "${jasypt::ENC(wqp8zDeiCQ5JaFvwDtoAcr2WMLdlD0rjwvo8Rh0thG5qyTQVGxwJjBIiW26y0dtU)}"); | ||
|
||
SmallRyeConfig config = new SmallRyeConfigBuilder() | ||
.addDefaultInterceptors() | ||
.addDiscoveredSources() | ||
.withSources(new PropertiesConfigSource(properties, "", 0)) | ||
.build(); | ||
|
||
assertEquals("12345678", config.getRawValue("my.secret")); | ||
} | ||
} |