Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#26: Implement ToolCommandlet for Jasypt #243

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
7c4644a
add JasyptUrlUpdater to UpdateManager
mvomiero Feb 13, 2024
80e5c18
Merge branch 'main' of https://github.com/devonfw/IDEasy into fix/mis…
mvomiero Feb 13, 2024
db09dce
commandlet initialized
mvomiero Feb 14, 2024
92def9c
add function doJasypt() to handle encryption and decriptyon, run() fu…
mvomiero Feb 15, 2024
2cc0020
use Path instead of Paths
mvomiero Feb 19, 2024
cb315e0
Merge branch 'main' into jasypt/26-ImplementToolCommandletForJasypt
mvomiero Feb 19, 2024
ed1fb3d
initialize mvn command for artifact download
mvomiero Feb 20, 2024
f8bad9d
Merge remote-tracking branch 'upstream/main'
mvomiero Feb 20, 2024
9df8843
Merge branch 'main' into jasypt/26-ImplementToolCommandletForJasypt
mvomiero Feb 20, 2024
ec072ea
refactor code Jasypt
mvomiero Feb 20, 2024
b846dfb
Merge remote-tracking branch 'upstream/main' into jasypt/26-Implement…
mvomiero Feb 20, 2024
6ac0e73
postInstall() method added to install the jasypt artifact
mvomiero Feb 21, 2024
1ba57b1
debug print postinstall
mvomiero Feb 21, 2024
4efe32a
Different executable priority lists depending from os
mvomiero Feb 21, 2024
4f24b0b
formatting check
mvomiero Feb 21, 2024
760ecc8
Merge branch '#219/wrong-executable-extension-linux' into jasypt/26-I…
mvomiero Feb 21, 2024
570e0ef
Return statement in backup() functions in case of symlinks
mvomiero Feb 23, 2024
b41c4d3
adds documentation
mvomiero Feb 23, 2024
cae4aec
Merge remote-tracking branch 'upstream/main' into jasypt/26-Implement…
mvomiero Feb 27, 2024
e0a09b5
Merge branch 'jasypt/26-ImplementToolCommandletForJasypt' into TRY/3
mvomiero Mar 5, 2024
41821a3
test jasypt initialized
mvomiero Mar 5, 2024
df57163
Tests implemented and working
mvomiero Mar 5, 2024
8bc5f16
tests correctly implemented
mvomiero Mar 5, 2024
8b0e0d9
code cleanup jasypt
mvomiero Mar 5, 2024
e411d3e
updates access rights executables
mvomiero Mar 6, 2024
13e78b8
small error check and code refactoring
mvomiero Mar 6, 2024
8b872e3
removes jmc reference in testinfrastruktur
mvomiero Mar 6, 2024
6f10efd
Merge remote-tracking branch 'upstream/main' into feature/26-jasyptCo…
mvomiero Mar 11, 2024
0593e48
changes constants from public to private
mvomiero Mar 11, 2024
34f017c
Merge remote-tracking branch 'upstream/main' into feature/26-jasyptCo…
mvomiero Mar 13, 2024
b5f453d
Merge remote-tracking branch 'upstream/main' into feature/26-jasyptCo…
mvomiero Mar 15, 2024
b25c71e
refactors code after review
mvomiero Mar 15, 2024
80987d4
adds tag for encryption and class PasswordProperties
mvomiero Mar 15, 2024
d93fa4a
code cleanup
mvomiero Mar 15, 2024
e67dc2d
refactors tests
mvomiero Mar 18, 2024
160f050
test refactoring
mvomiero Mar 18, 2024
1629627
implements arguments commandlet
mvomiero Mar 18, 2024
32b305f
code refactoring tests
mvomiero Mar 18, 2024
ef6c4f3
code refactoring, documentation page deleted
mvomiero Mar 18, 2024
a9120e4
Merge remote-tracking branch 'upstream/main' into feature/26-jasyptCo…
mvomiero Mar 18, 2024
3190bd0
Merge remote-tracking branch 'upstream/main' into feature/26-jasyptCo…
mvomiero Mar 19, 2024
ef3301f
Merge remote-tracking branch 'upstream/main' into feature/26-jasyptCo…
mvomiero Mar 19, 2024
d9f6153
excludes .jar file from gitignore
mvomiero Mar 19, 2024
ce5b539
updates gitignore to exclude mocked jar test file
mvomiero Mar 19, 2024
ab80b96
code cleanup
mvomiero Mar 19, 2024
3b923ef
Merge branch 'main' into feature/26-jasyptCommandletWithUnitTests
hohwille Mar 21, 2024
5afc572
removes jar file
mvomiero Mar 21, 2024
f585e68
gitignore update
mvomiero Mar 21, 2024
efbbe57
adds jasypt.jar file
mvomiero Mar 21, 2024
f958fe1
renames masterPassword and secret
mvomiero Mar 21, 2024
0765118
Merge branch 'main' into feature/26-jasyptCommandletWithUnitTests
hohwille Mar 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.devonfw.tools.ide.tool.sonar.Sonar;
import com.devonfw.tools.ide.tool.terraform.Terraform;
import com.devonfw.tools.ide.tool.vscode.Vscode;
import com.devonfw.tools.ide.tool.jasypt.Jasypt;

/**
* Implementation of {@link CommandletManager}.
Expand Down Expand Up @@ -88,6 +89,7 @@ public CommandletManagerImpl(IdeContext context) {
add(new Aws(context));
add(new Cobigen(context));
add(new Jmc(context));
add(new Jasypt(context));
add(new Docker(context));
add(new Sonar(context));
}
Expand Down
7 changes: 7 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/common/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ public final class Tag {
/** {@link #Tag} for github. */
public static final Tag GITHUB = create("github", GIT);


/** {@link #Tag} for diff (tools that compare files and determine the difference). */
public static final Tag DIFF = create("diff", CONFIG_MANAGEMENT, false, "patch");

Expand All @@ -311,6 +312,12 @@ public final class Tag {
/** {@link #Tag} for Linux. */
public static final Tag LINUX = create("linux", OS, false);

/** {@link #getParent() Parent} for cryptography. */
public static final Tag CRYPTO = create("cryptography", ROOT, false, "crypto");

/** {@link #Tag} for encryption. */
public static final Tag ENCRYPTION = create("encryption", CRYPTO);

private final String id;

private final Tag parent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ protected String getValue(String name) {
if (!name.equals(key)) {
value = this.parent.get(key);
}
if (value != null) {
if (value == null) {
value = var.getDefaultValueAsString(this.context);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.devonfw.tools.ide.property;

/**
* {@link Property} with {@link #getValueType() value type} {@link String} representing a password.
*/
public class PasswordProperty extends StringProperty {

/**
* The constructor.
*
* @param name the {@link #getName() property name}.
* @param required the {@link #isRequired() required flag}.
* @param alias the {@link #getAlias() property alias}.
*/
public PasswordProperty(String name, boolean required, String alias) {

super(name, required, alias);
}

}
103 changes: 103 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/tool/jasypt/Jasypt.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package com.devonfw.tools.ide.tool.jasypt;

import com.devonfw.tools.ide.common.Tag;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.property.EnumProperty;
import com.devonfw.tools.ide.property.PasswordProperty;
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
import com.devonfw.tools.ide.tool.ToolCommandlet;
import com.devonfw.tools.ide.tool.java.Java;

import java.nio.file.Path;
import java.util.Set;

/**
* {@link ToolCommandlet} for <a href="http://www.jasypt.org/">Jasypt</a>, The java library which allows to add basic
* encryption capabilities with minimum effort.
*/
public class Jasypt extends LocalToolCommandlet {

public final EnumProperty<JasyptCommand> command;

public final PasswordProperty masterPassword;

public final PasswordProperty secret;

private static final String CLASS_NAME_ENCRYPTION = "org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI";

private static final String CLASS_NAME_DECRYPTION = "org.jasypt.intf.cli.JasyptPBEStringDecryptionCLI";

/**
* The constructor.
*
* @param context the {@link IdeContext}.
*/
public Jasypt(IdeContext context) {

super(context, "jasypt", Set.of(Tag.JAVA, Tag.ENCRYPTION));

this.command = add(new EnumProperty<>("", true, "command", JasyptCommand.class));
this.masterPassword = add(new PasswordProperty("", true, "masterPassword"));
this.secret = add(new PasswordProperty("", true, "secret"));
}

@Override
protected void initProperties() {

// Empty on purpose
}

@Override
public boolean doInstall(boolean silent) {

getCommandlet(Java.class).install();

return super.doInstall(silent);
}

@Override
protected boolean isExtract() {

return false;
}

@Override
public void run() {

Path toolPath = getToolPath();
if (!toolPath.toFile().exists()) {
super.install(true);
}

JasyptCommand command = this.command.getValue();
switch (command) {
case ENCRYPT:
runJasypt(CLASS_NAME_ENCRYPTION);
break;
case DECRYPT:
runJasypt(CLASS_NAME_DECRYPTION);
break;

default:
}
}

private void runJasypt(String className) {

Java java = getCommandlet(Java.class);

String[] jasyptOptions = this.context.getVariables().get("JASYPT_OPTS").split(" ");
String algorithm = jasyptOptions[0];
String generatorClassName = jasyptOptions[1];

java.runTool(null, "-cp", resolveJasyptJarPath().toString(), className, algorithm, generatorClassName,
"password=" + this.masterPassword.getValue(), "input=" + this.secret.getValue());
}

private Path resolveJasyptJarPath() {

Path toolPath = this.getToolPath();
String installedVersion = getInstalledVersion().toString();
return toolPath.resolve("jasypt-" + installedVersion + ".jar");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.devonfw.tools.ide.tool.jasypt;

/**
* Represents commands for controlling a jasypt operation in The{@link Jasypt} Tool.
*/
public enum JasyptCommand {
ENCRYPT, DECRYPT
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ public interface IdeVariables {
/** {@link VariableDefinition} for {@link com.devonfw.tools.ide.context.IdeContext#getWorkspaceName() WORKSPACE}. */
VariableDefinitionString GRAALVM_EDITION = new VariableDefinitionString("GRAALVM_EDITION", null, c -> "community");

/** {@link VariableDefinition} for options of jasypt */
VariableDefinitionString JASYPT_OPTS = new VariableDefinitionString("JASYPT_OPTS", null,
c -> "algorithm=PBEWITHHMACSHA512ANDAES_256 ivGeneratorClassName=org.jasypt.iv.RandomIvGenerator");

/** A {@link Collection} with all pre-defined {@link VariableDefinition}s. */
Collection<VariableDefinition<?>> VARIABLES = List.of(PATH, HOME, WORKSPACE_PATH, IDE_HOME, IDE_ROOT, WORKSPACE,
IDE_TOOLS, CREATE_START_SCRIPTS, IDE_MIN_VERSION, MVN_VERSION, DOCKER_EDITION, GRAALVM_EDITION);
IDE_TOOLS, CREATE_START_SCRIPTS, IDE_MIN_VERSION, MVN_VERSION, DOCKER_EDITION, GRAALVM_EDITION, JASYPT_OPTS);

/**
* @param name the name of the requested {@link VariableDefinition}.
Expand Down
4 changes: 4 additions & 0 deletions cli/src/main/resources/nls/Ide.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ cmd-shell=Commandlet to start built-in shell with advanced auto-completion.
cmd-terraform=Tool commandlet for Terraform
cmd-vscode=Tool commandlet for Visual Studio Code (IDE)
cmd-cobigen=Tool commandlet for Cobigen
cmd-jasypt=Tool commandlet for Jasypt
cmd-sonar=Tool commandlet for SonarQube
val-args=The commandline arguments to pass to the tool.
val-edition=The tool edition.
val-sonar-command=START|STOP|ANALYZE
val-jasypt-command=encrypt | decrypt
val-jasypt-masterPassword=master password
val-jasypt-secret=The secret to be encrypted or decrypted
val-tool=The tool commandlet to select.
val-version=The tool version
val-set-version-version=The tool version to set.
Expand Down
1 change: 1 addition & 0 deletions cli/src/main/resources/nls/Ide_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ cmd-set-version=Setzt die Version des selektierten Werkzeugs.
cmd-terraform=Werkzeug Kommando für Terraform.
cmd-vscode=Werkzeug Kommando für Visual Studio Code (IDE)
cmd-cobigen=Werkzeug Kommando für Cobigen.
cmd-jasypt=Werkzeug Kommando für Jasypt
cmd-sonar=Werkzeug Kommando für SonarQube.
val-args=Die Kommandozeilen-Argumente zur Übergabe an das Werkzeug.
val-edition=Die Werkzeug Edition.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.devonfw.tools.ide.tool.jasypt;

import com.devonfw.tools.ide.commandlet.InstallCommandlet;
import com.devonfw.tools.ide.context.AbstractIdeContextTest;
import com.devonfw.tools.ide.context.IdeTestContext;
import com.devonfw.tools.ide.log.IdeLogLevel;
import org.junit.jupiter.api.Test;

/**
* Integration test of {@link Jasypt}.
*/
public class JasyptTest extends AbstractIdeContextTest {

private static final String PROJECT_JASYPT = "jasypt";

@Test
public void testJasyptInstallCommandlet() {

// arrange
IdeTestContext context = newContext(PROJECT_JASYPT);
InstallCommandlet install = context.getCommandletManager().getCommandlet(InstallCommandlet.class);
install.tool.setValueAsString("jasypt", context);
// act
install.run();

// assert
checkInstallation(context);
}

@Test
public void testJasyptInstall() {

// arrange
IdeTestContext context = newContext(PROJECT_JASYPT);

Jasypt commandlet = new Jasypt(context);

// act
commandlet.install();

// assert
checkInstallation(context);
}

@Test
public void testJasyptRun() {

// arrange
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, "executing java:");
assertLogMessage(context, IdeLogLevel.INFO, "This is a jar file.");
checkInstallation(context);
}

private void checkInstallation(IdeTestContext context) {

// install - java
assertThat(context.getSoftwarePath().resolve("java/bin/java")).exists();

// commandlet - jasypt
assertThat(context.getSoftwarePath().resolve("jasypt/jasypt-1.9.3.jar")).hasContent("This is a jar file.");
assertThat(context.getSoftwarePath().resolve("jasypt/.ide.software.version")).exists().hasContent("1.9.3");
assertLogMessage(context, IdeLogLevel.SUCCESS, "Successfully installed jasypt in version 1.9.3");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is the download metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is the users HOME directory
1 change: 1 addition & 0 deletions cli/src/test/resources/ide-projects/jasypt/project/readme
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is the IDE_HOME directory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
JAVA_VERSION=17.0.10_7
JASYPT_VERSION=1.9.3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is the main workspace of jmc test case
1 change: 1 addition & 0 deletions cli/src/test/resources/ide-projects/jasypt/readme
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is the IDE_ROOT directory
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a jar file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
echo "executing java:"
cat $2 # .jar file
Loading