Skip to content

Commit

Permalink
[ELY-2343] Add a web option to the Elytron Tool
Browse files Browse the repository at this point in the history
  • Loading branch information
petrberan authored and rsearls committed Sep 18, 2024
1 parent 564c6a7 commit ad4a854
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
*/
package org.wildfly.security.tool;

import java.awt.Desktop;
import java.io.IOException;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -104,6 +107,16 @@ class CredentialStoreCommand extends Command {

public static final String CREDENTIAL_STORE_COMMAND = "credential-store";


private static final String DOCS_VERSION = "27";
private static final String DOCS_URI = "https://docs.wildfly.org/" + DOCS_VERSION + "/WildFly_Elytron_Security.html";

public static final String STORE_LOCATION_PARAM = "location";
public static final String IMPLEMENTATION_PROPERTIES_PARAM = "properties";
public static final String CREDENTIAL_STORE_PASSWORD_PARAM = "password";
public static final String CREDENTIAL_STORE_TYPE_PARAM = "type";
public static final String SALT_PARAM = "salt";
public static final String ITERATION_PARAM = "iteration";
public static final String PASSWORD_CREDENTIAL_VALUE_PARAM = "secret";
public static final String ADD_ALIAS_PARAM = "add";
public static final String CHECK_ALIAS_PARAM = "exists";
Expand All @@ -112,6 +125,7 @@ class CredentialStoreCommand extends Command {
public static final String REMOVE_ALIAS_PARAM = "remove";
public static final String ENTRY_TYPE_PARAM = "entry-type";
public static final String SIZE_PARAM = "size";
public static final String WEB_PARAM = "web";

public static final String GENERATE_KEY_PAIR_PARAM = "generate-key-pair";
public static final String ALGORITHM_PARAM = "algorithm";
Expand Down Expand Up @@ -176,6 +190,9 @@ class CredentialStoreCommand extends Command {
options.addOption("k", ALGORITHM_PARAM, true, ElytronToolMessages.msg.cmdLineKeyAlgorithmDesc());
options.addOption("kp", KEY_PASSPHRASE_PARAM, true, ElytronToolMessages.msg.cmdLineKeyPassphraseDesc());

opt = Option.builder().longOpt(WEB_PARAM).desc(ElytronToolMessages.msg.cmdWebDesc()).build();
options.addOption(opt);

OptionGroup privateKP = new OptionGroup();
Option privateString = new Option("pvk", PRIVATE_KEY_STRING_PARAM, true, ElytronToolMessages.msg.cmdLinePrivateKeyStringDesc());
Option privateLocation = new Option("pvl", PRIVATE_KEY_LOCATION_PARAM, true, ElytronToolMessages.msg.cmdLinePrivateKeyLocationDesc());
Expand Down Expand Up @@ -347,6 +364,23 @@ public void execute(String[] args) throws Exception {
setStatus(ElytronTool.ElytronToolExitStatus_OK);
return;
}
if (cmdLine.hasOption(WEB_PARAM)) {
if (Desktop.isDesktopSupported()){
Desktop desktop = Desktop.getDesktop();
if (desktop.isSupported(Desktop.Action.BROWSE)){
try {
desktop.browse(new URI(DOCS_URI + "#CredentialStore"));
setStatus(ElytronTool.ElytronToolExitStatus_OK);
return;
} catch (IOException | URISyntaxException e) {
setStatus(GENERAL_CONFIGURATION_ERROR);
throw ElytronToolMessages.msg.unableToOpenBrowser();
}
}
}
setStatus(GENERAL_CONFIGURATION_ERROR);
throw ElytronToolMessages.msg.unableToOpenBrowser();
}

printDuplicatesWarning(cmdLine);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,12 @@ public interface ElytronToolMessages extends BasicLogger {
@Message(id = NONE, value = "A tool that assists with Elytron configuration")
String cmdElytronToolDescription();

@Message(id = NONE, value = "Open online documentation for the command (Action)")
String cmdWebDesc();

@Message(id = NONE, value = "Unable to open the browser.")
IOException unableToOpenBrowser();

// Numeric Errors
@Message(id = 35, value = "Only one of '%s' and '%s' can be specified at the same time")
IllegalArgumentException mutuallyExclusiveOptions(String first, String second);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,49 +17,45 @@
*/
package org.wildfly.security.tool;


import static org.wildfly.security.tool.Params.BULK_CONVERT_PARAM;
import static org.wildfly.security.tool.Params.CREATE_CREDENTIAL_STORE_PARAM;
import static org.wildfly.security.tool.Params.CREDENTIAL_STORE_LOCATION_PARAM;
import static org.wildfly.security.tool.Params.DEBUG_PARAM;
import static org.wildfly.security.tool.Params.DEFAULT_KEY_PAIR_ALIAS;
import static org.wildfly.security.tool.Params.DEFAULT_LEVELS;
import static org.wildfly.security.tool.Params.DEFAULT_SECRET_KEY_ALIAS;
import static org.wildfly.security.tool.Params.DIRECTORY_PARAM;
import static org.wildfly.security.tool.Params.ENCODED_PARAM;
import static org.wildfly.security.tool.Params.FILE_PARAM;
import static org.wildfly.security.tool.Params.HASH_CHARSET_PARAM;
import static org.wildfly.security.tool.Params.HASH_ENCODING_PARAM;
import static org.wildfly.security.tool.Params.HELP_PARAM;
import static org.wildfly.security.tool.Params.INPUT_LOCATION_PARAM;
import static org.wildfly.security.tool.Params.KEYSTORE_PARAM;
import static org.wildfly.security.tool.Params.KEYSTORE_TYPE_PARAM;
import static org.wildfly.security.tool.Params.KEY_PAIR_ALIAS_PARAM;
import static org.wildfly.security.tool.Params.LEVELS_PARAM;
import static org.wildfly.security.tool.Params.LINE_SEPARATOR;
import static org.wildfly.security.tool.Params.NAME_PARAM;
import static org.wildfly.security.tool.Params.OUTPUT_LOCATION_PARAM;
import static org.wildfly.security.tool.Params.PASSWORD_ENV_PARAM;
import static org.wildfly.security.tool.Params.PASSWORD_PARAM;
import static org.wildfly.security.tool.Params.REALM_NAME_PARAM;
import static org.wildfly.security.tool.Params.SECRET_KEY_ALIAS_PARAM;
import static org.wildfly.security.tool.Params.SILENT_PARAM;
import static org.wildfly.security.tool.Params.SUMMARY_DIVIDER;
import static org.wildfly.security.tool.Params.SUMMARY_PARAM;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

import java.awt.Desktop;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.security.KeyPair;
import java.security.Provider;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;
import java.util.stream.Stream;
import javax.crypto.SecretKey;
import org.apache.commons.cli.CommandLine;
Expand All @@ -72,6 +68,7 @@
import org.wildfly.security.auth.realm.FileSystemSecurityRealm;
import org.wildfly.security.auth.realm.FileSystemSecurityRealmBuilder;
import org.wildfly.security.password.spec.Encoding;
import org.wildfly.security.password.WildFlyElytronPasswordProvider;
import org.wildfly.security.tool.help.DescriptionSection;
import org.wildfly.security.tool.help.HelpCommand;
import org.wildfly.security.tool.help.OptionsSection;
Expand All @@ -89,9 +86,30 @@
class FileSystemEncryptRealmCommand extends Command {
static final String FILE_SYSTEM_ENCRYPT_COMMAND = "filesystem-realm-encrypt";

private static final String DOCS_VERSION = "27";
private static final String DOCS_URI = "https://docs.wildfly.org/" + DOCS_VERSION + "/WildFly_Elytron_Security.html";

private static final String HELP_PARAM = "help";
private static final String DEBUG_PARAM = "debug";
private static final String SILENT_PARAM = "silent";
private static final String SUMMARY_PARAM = "summary";
private static final String INPUT_REALM_LOCATION_PARAM = "input-location";
private static final String REALM_NAME_PARAM = "realm-name";
private static final String OUTPUT_REALM_LOCATION_PARAM = "output-location";
private static final String CREDENTIAL_STORE_LOCATION_PARAM = "credential-store";
private static final String CREATE_CREDENTIAL_STORE_PARAM = "create";
private static final String SECRET_KEY_ALIAS_PARAM = "secret-key";
private static final String HASH_ENCODING_PARAM = "hash-encoding";
private static final String ENCODED_PARAM = "encoded";
private static final String LEVELS_PARAM = "levels";
private static final String POPULATE_SECRET_KEY_PARAM = "populate";
private static final String DEFAULT_FILESYSTEM_REALM_NAME = "encrypted-filesystem-realm";

private static final String WEB_PARAM = "web";
public static Supplier<Provider[]> ELYTRON_PASSWORD_PROVIDERS = () -> new Provider[]{
WildFlyElytronPasswordProvider.getInstance()
};

private final List<Descriptor> descriptors = new ArrayList<>();
private final List<String> PARAMS_LIST = new ArrayList<>(Arrays.asList(INPUT_LOCATION_PARAM, OUTPUT_LOCATION_PARAM));

Expand Down Expand Up @@ -176,6 +194,9 @@ class FileSystemEncryptRealmCommand extends Command {
option.setArgName(FILE_PARAM);
options.addOption(option);

option = Option.builder().longOpt(WEB_PARAM).desc(ElytronToolMessages.msg.cmdWebDesc()).build();
options.addOption(option);

option = Option.builder().longOpt(HELP_PARAM).desc(ElytronToolMessages.msg.cmdLineHelp()).build();
options.addOption(option);

Expand Down Expand Up @@ -392,6 +413,24 @@ public void execute(String[] args) throws Exception {
setStatus(ElytronTool.ElytronToolExitStatus_OK);
return;
}
if (cmdLine.hasOption(WEB_PARAM)) {
if (Desktop.isDesktopSupported()){
Desktop desktop = Desktop.getDesktop();
if (desktop.isSupported(Desktop.Action.BROWSE)){
try {
desktop.browse(new URI(DOCS_URI +
"#converting-an-unencrypted-filesystem-realm-into-an-encrypted-filesystem-realm"));
setStatus(ElytronTool.ElytronToolExitStatus_OK);
return;
} catch (IOException | URISyntaxException e) {
setStatus(GENERAL_CONFIGURATION_ERROR);
throw ElytronToolMessages.msg.unableToOpenBrowser();
}
}
}
setStatus(GENERAL_CONFIGURATION_ERROR);
throw ElytronToolMessages.msg.unableToOpenBrowser();
}
if (cmdLine.hasOption(SILENT_PARAM)) {
silentMode = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@
package org.wildfly.security.tool;

import static org.wildfly.security.tool.Params.BULK_CONVERT_PARAM;
import static org.wildfly.security.tool.Params.DEBUG_PARAM;
import static org.wildfly.security.tool.Params.DIRECTORY_PARAM;
import static org.wildfly.security.tool.Params.FILE_PARAM;
import static org.wildfly.security.tool.Params.HELP_PARAM;
import static org.wildfly.security.tool.Params.LINE_SEPARATOR;
import static org.wildfly.security.tool.Params.NAME_PARAM;
import static org.wildfly.security.tool.Params.OUTPUT_LOCATION_PARAM;
import static org.wildfly.security.tool.Params.SILENT_PARAM;
import static org.wildfly.security.tool.Params.SUMMARY_DIVIDER;
import static org.wildfly.security.tool.Params.SUMMARY_PARAM;

import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -77,12 +76,20 @@ class FileSystemRealmCommand extends Command {

static final String FILE_SYSTEM_REALM_COMMAND = "filesystem-realm";

private static final String DOCS_VERSION = "27";
private static final String DOCS_URI = "https://docs.wildfly.org/" + DOCS_VERSION + "/WildFly_Elytron_Security.html";

private static final String HELP_PARAM = "help";
private static final String DEBUG_PARAM = "debug";
private static final String SILENT_PARAM = "silent";
private static final String SUMMARY_PARAM = "summary";
private static final String USERS_FILE_PARAM = "users-file";
private static final String ROLES_FILE_PARAM = "roles-file";
private static final String FILESYSTEM_REALM_NAME_PARAM = "filesystem-realm-name";
private static final String SECURITY_DOMAIN_NAME_PARAM = "security-domain-name";
private static final String DEFAULT_FILESYSTEM_REALM_NAME = "converted-properties-filesystem-realm";
private static final String DEFAULT_SECURITY_DOMAIN_NAME = "converted-properties-security-domain";
private static final String WEB_PARAM = "web";

private List<Descriptor> descriptors = new ArrayList<>();
private final List<String> PARAMS_LIST = new ArrayList<>(Arrays.asList(USERS_FILE_PARAM, ROLES_FILE_PARAM, OUTPUT_LOCATION_PARAM, FILESYSTEM_REALM_NAME_PARAM, SECURITY_DOMAIN_NAME_PARAM));
Expand Down Expand Up @@ -123,6 +130,9 @@ class FileSystemRealmCommand extends Command {
option.setArgName(NAME_PARAM);
options.addOption(option);

option = Option.builder().longOpt(WEB_PARAM).desc(ElytronToolMessages.msg.cmdWebDesc()).build();
options.addOption(option);

option = Option.builder().longOpt(HELP_PARAM).desc(ElytronToolMessages.msg.cmdLineHelp()).build();
options.addOption(option);

Expand Down Expand Up @@ -224,6 +234,23 @@ public void execute(String[] args) throws Exception {
setStatus(ElytronTool.ElytronToolExitStatus_OK);
return;
}
if (cmdLine.hasOption(WEB_PARAM)) {
if (Desktop.isDesktopSupported()){
Desktop desktop = Desktop.getDesktop();
if (desktop.isSupported(Desktop.Action.BROWSE)){
try {
desktop.browse(new URI(DOCS_URI + "#Properties_File_Based_Authentication_Migration"));
setStatus(ElytronTool.ElytronToolExitStatus_OK);
return;
} catch (IOException | URISyntaxException e) {
setStatus(GENERAL_CONFIGURATION_ERROR);
throw ElytronToolMessages.msg.unableToOpenBrowser();
}
}
}
setStatus(GENERAL_CONFIGURATION_ERROR);
throw ElytronToolMessages.msg.unableToOpenBrowser();
}
if (cmdLine.hasOption(SILENT_PARAM)) {
silentMode = true;
}
Expand Down
36 changes: 32 additions & 4 deletions tool/src/main/java/org/wildfly/security/tool/MaskCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
*/
package org.wildfly.security.tool;

import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.GeneralSecurityException;
import java.security.SecureRandom;

Expand All @@ -31,10 +35,6 @@
import org.wildfly.security.tool.help.UsageSection;
import org.wildfly.security.util.PasswordBasedEncryptionUtil;

import static org.wildfly.security.tool.Params.DEBUG_PARAM;
import static org.wildfly.security.tool.Params.HELP_PARAM;
import static org.wildfly.security.tool.Params.ITERATION_PARAM;
import static org.wildfly.security.tool.Params.SALT_PARAM;
import static org.wildfly.security.util.PasswordUtil.generateSecureRandomString;

/**
Expand All @@ -49,7 +49,16 @@ class MaskCommand extends Command {
* Command string
*/
public static final String MASK_COMMAND = "mask";

private static final String DOCS_VERSION = "27";
private static final String DOCS_URI = "https://docs.wildfly.org/" + DOCS_VERSION + "/";

static final String SALT_PARAM = "salt";
static final String ITERATION_PARAM = "iteration";
static final String SECRET_PARAM = "secret";
static final String HELP_PARAM = "help";
static final String DEBUG_PARAM = "debug";
static final String WEB_PARAM = "web";

private final int defaultIterationCount = 10000;

Expand All @@ -63,13 +72,15 @@ class MaskCommand extends Command {
Option h = new Option("h", HELP_PARAM, false, ElytronToolMessages.msg.cmdLineHelp());
Option x = new Option("x", SECRET_PARAM, true, ElytronToolMessages.msg.cmdMaskSecretDesc());
Option d = new Option("d", DEBUG_PARAM, false, ElytronToolMessages.msg.cmdLineDebug());
Option web = Option.builder().longOpt(WEB_PARAM).desc(ElytronToolMessages.msg.cmdWebDesc()).build();
x.setArgName("to encrypt");
options = new Options();
options.addOption(x);
options.addOption(h);
options.addOption(salt);
options.addOption(iteration);
options.addOption(d);
options.addOption(web);
}

@Override
Expand All @@ -86,6 +97,23 @@ public void execute(String[] args) throws Exception {
setStatus(ElytronTool.ElytronToolExitStatus_OK);
return;
}
if (cmdLine.hasOption(WEB_PARAM)) {
if (Desktop.isDesktopSupported()){
Desktop desktop = Desktop.getDesktop();
if (desktop.isSupported(Desktop.Action.BROWSE)){
try {
desktop.browse(new URI(DOCS_URI + "Migration_Guide.html#credential-store-creation"));
setStatus(ElytronTool.ElytronToolExitStatus_OK);
return;
} catch (IOException | URISyntaxException e) {
setStatus(GENERAL_CONFIGURATION_ERROR);
throw ElytronToolMessages.msg.unableToOpenBrowser();
}
}
}
setStatus(GENERAL_CONFIGURATION_ERROR);
throw ElytronToolMessages.msg.unableToOpenBrowser();
}

printDuplicatesWarning(cmdLine);

Expand Down
Loading

0 comments on commit ad4a854

Please sign in to comment.