diff --git a/cli/src/main/java/com/devonfw/tools/ide/tool/jasypt/Jasypt.java b/cli/src/main/java/com/devonfw/tools/ide/tool/jasypt/Jasypt.java
index a6f7aff99..c23272fd4 100644
--- a/cli/src/main/java/com/devonfw/tools/ide/tool/jasypt/Jasypt.java
+++ b/cli/src/main/java/com/devonfw/tools/ide/tool/jasypt/Jasypt.java
@@ -9,18 +9,24 @@
import com.devonfw.tools.ide.tool.java.Java;
import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import java.util.Set;
/**
- * {@link ToolCommandlet} for Jasypt, The java library which allows to add basic
- * encryption capabilities with minimum effort.
+ * {@link ToolCommandlet} for Jasypt, The java library which allows to add basic encryption capabilities with minimum
+ * effort.
*/
public class Jasypt extends LocalToolCommandlet {
+ /** {@link EnumProperty} for the command (encrypt or decrypt) */
public final EnumProperty command;
+ /** {@link PasswordProperty} for the master password */
public final PasswordProperty masterPassword;
+ /** {@link PasswordProperty} for the secret to be encrypted or decrypted */
public final PasswordProperty secret;
private static final String CLASS_NAME_ENCRYPTION = "org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI";
@@ -84,14 +90,18 @@ public void run() {
private void runJasypt(String className) {
- Java java = getCommandlet(Java.class);
+ List arguments = new ArrayList<>(
+ Arrays.asList("-cp", resolveJasyptJarPath().toString(), className, "password=" + this.masterPassword.getValue(), "input=" + this.secret.getValue()));
+
+ String jasyptOpts = this.context.getVariables().get("JASYPT_OPTS");
+ if (jasyptOpts != null && !jasyptOpts.trim().isEmpty()) {
+ String[] jasyptOptions = jasyptOpts.split("\\s+");
- String[] jasyptOptions = this.context.getVariables().get("JASYPT_OPTS").split(" ");
- String algorithm = jasyptOptions[0];
- String generatorClassName = jasyptOptions[1];
+ arguments.addAll(Arrays.asList(jasyptOptions));
+ }
- java.runTool(null, "-cp", resolveJasyptJarPath().toString(), className, algorithm, generatorClassName,
- "password=" + this.masterPassword.getValue(), "input=" + this.secret.getValue());
+ Java java = getCommandlet(Java.class);
+ java.runTool(null, arguments.toArray(new String[0]));
}
private Path resolveJasyptJarPath() {
diff --git a/cli/src/main/resources/nls/Help.properties b/cli/src/main/resources/nls/Help.properties
index 960769a67..ad2198069 100644
--- a/cli/src/main/resources/nls/Help.properties
+++ b/cli/src/main/resources/nls/Help.properties
@@ -20,8 +20,8 @@ cmd.helm=Tool commandlet for Helm (Kubernetes Package Manager).
cmd.help=Prints this help.
cmd.install=Install the selected tool.
cmd.intellij=Tool commandlet for IntelliJ (IDE)
-cmd.jasypt=Tool commandlet for Jasypt (encryption/decryption).
-cmd.jasypt.val.command=Modues (encrypt | decrypt)
+cmd.jasypt=Tool commandlet for Jasypt, allows to install Jasypt and encrypt or decrypt secrets using strong encryption with a master password. It is possible to input custom arguments by setting the JASYPT_OPTS variable, which defaults to JASYPT_OPTS="algorithm=PBEWITHHMACSHA512ANDAES_256 ivGeneratorClassName=org.jasypt.iv.RandomIvGenerator".
+cmd.jasypt.val.command=Action (encrypt | decrypt)
cmd.jasypt.val.masterPassword=master password.
cmd.jasypt.val.secret=The secret to be encrypted or decrypted.
cmd.java=Tool commandlet for Java (OpenJDK).
diff --git a/cli/src/main/resources/nls/Help_de.properties b/cli/src/main/resources/nls/Help_de.properties
index 196dcde24..c6d2fef3e 100644
--- a/cli/src/main/resources/nls/Help_de.properties
+++ b/cli/src/main/resources/nls/Help_de.properties
@@ -20,7 +20,7 @@ cmd.helm=Werkzeug Kommando für Helm (Kubernetes Package Manager).
cmd.help=Zeigt diese Hilfe an.
cmd.install=Installiert das selektierte Werkzeug.
cmd.intellij=Werkzeug Kommando für Intellij (IDE)
-cmd.jasypt=Werkzeug Kommando für Jasypt.
+cmd.jasypt=Werkzeug Kommando für Jasypt, ermöglicht die Installation von Jasypt und die Verschlüsselung oder Entschlüsselung von Geheimnissen mit starker Verschlüsselung durch einen Master-Passwort. Es ist möglich, benutzerdefinierte Argumente durch Setzen der JASYPT_OPTS-Variable einzugeben, die standardmäßig auf JASYPT_OPTS="algorithm=PBEWITHHMACSHA512ANDAES_256 ivGeneratorClassName=org.jasypt.iv.RandomIvGenerator" gesetzt ist.
cmd.jasypt.val.command=Mode (encrypt | decrypt)
cmd.jasypt.val.masterPassword=master Passwort.
cmd.jasypt.val.secret=Das zu verschlüsselnde oder zu entschlüsselnde Geheimnis.
diff --git a/cli/src/test/java/com/devonfw/tools/ide/tool/jasypt/JasyptTest.java b/cli/src/test/java/com/devonfw/tools/ide/tool/jasypt/JasyptTest.java
index 32eb612af..3d6603e91 100644
--- a/cli/src/test/java/com/devonfw/tools/ide/tool/jasypt/JasyptTest.java
+++ b/cli/src/test/java/com/devonfw/tools/ide/tool/jasypt/JasyptTest.java
@@ -5,14 +5,24 @@
import com.devonfw.tools.ide.context.IdeTestContext;
import com.devonfw.tools.ide.log.IdeLogLevel;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import uk.org.webcompere.systemstubs.environment.EnvironmentVariables;
+import uk.org.webcompere.systemstubs.jupiter.SystemStub;
+import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension;
/**
* Integration test of {@link Jasypt}.
*/
+@ExtendWith(SystemStubsExtension.class)
public class JasyptTest extends AbstractIdeContextTest {
- private static final String PROJECT_JASYPT = "jasypt";
+ private static final String JASYPT_OPTS = "custom_argument";
+ private static final String PROJECT_JASYPT = "jasypt";
+
+ /**
+ * Tests if {@link Jasypt} is properly installed by the {@link InstallCommandlet}
+ */
@Test
public void testJasyptInstallCommandlet() {
@@ -27,6 +37,9 @@ public void testJasyptInstallCommandlet() {
checkInstallation(context);
}
+ /**
+ * Tests if {@link Jasypt} Commandlet installation is properly working
+ */
@Test
public void testJasyptInstall() {
@@ -42,6 +55,9 @@ public void testJasyptInstall() {
checkInstallation(context);
}
+ /**
+ * Tests if {@link Jasypt} Commandlet is properly running
+ */
@Test
public void testJasyptRun() {
@@ -57,8 +73,35 @@ public void testJasyptRun() {
commandlet.run();
// assert
- assertLogMessage(context, IdeLogLevel.INFO, "executing java:");
- assertLogMessage(context, IdeLogLevel.INFO, "This is a jar file.");
+ assertLogMessage(context, IdeLogLevel.INFO, context.getVariables().get("JASYPT_OPTS"));
+ checkInstallation(context);
+ }
+
+ @SystemStub
+ private final EnvironmentVariables environment = new EnvironmentVariables();
+
+ /**
+ * Tests if {@link Jasypt} Commandlet is properly running with a user-defined JASYPT_OPTS env variable
+ */
+ @Test
+ public void testJasyptRunWithCustomVariable() {
+
+ // arrange
+ environment.set("JASYPT_OPTS", JASYPT_OPTS);
+
+ IdeTestContext context = newContext(PROJECT_JASYPT);
+ Jasypt commandlet = new Jasypt(context);
+
+ commandlet.command.setValue(JasyptCommand.ENCRYPT);
+ commandlet.masterPassword.setValue("password");
+ commandlet.secret.setValue("input");
+
+ // act
+ commandlet.run();
+
+ // assert
+ assertLogMessage(context, IdeLogLevel.INFO, context.getVariables().get("JASYPT_OPTS"));
+
checkInstallation(context);
}
diff --git a/cli/src/test/resources/ide-projects/jasypt/repository/java/java/default/bin/java b/cli/src/test/resources/ide-projects/jasypt/repository/java/java/default/bin/java
index 655040e33..11fa988f3 100644
--- a/cli/src/test/resources/ide-projects/jasypt/repository/java/java/default/bin/java
+++ b/cli/src/test/resources/ide-projects/jasypt/repository/java/java/default/bin/java
@@ -1,3 +1,2 @@
#!/bin/bash
-echo "executing java:"
-cat $2 # .jar file
\ No newline at end of file
+echo "${@:6}" # optional arguments
\ No newline at end of file