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

[ELY-2343] Add a web option to the Elytron Tool #1715

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -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 @@ -87,6 +90,9 @@ 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";
Expand All @@ -108,6 +114,7 @@ class CredentialStoreCommand extends Command {
public static final String DEBUG_PARAM = "debug";
public static final String CUSTOM_CREDENTIAL_STORE_PROVIDER_PARAM = "credential-store-provider";
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 @@ -172,6 +179,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 @@ -343,6 +353,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 @@ -603,6 +603,12 @@ public interface ElytronToolMessages extends BasicLogger {
@Message(id = NONE, value = "No Credential Store location or Secret Key Alias specified.")
MissingOptionException missingCredentialStoreSecretKey();

@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,8 +17,11 @@
*/
package org.wildfly.security.tool;

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
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 @@ -63,6 +66,9 @@ class FileSystemEncryptRealmCommand extends Command {
static final String FILE_SYSTEM_ENCRYPT_COMMAND = "filesystem-realm-encrypt";
static final int SUMMARY_WIDTH = 100;

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";
Expand All @@ -82,6 +88,7 @@ class FileSystemEncryptRealmCommand extends Command {
private static final String DIRECTORY_ARG = "directory";
private static final String NAME_ARG = "name";
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()
};
Expand Down Expand Up @@ -145,6 +152,9 @@ class FileSystemEncryptRealmCommand extends Command {
option.setArgName(FILE_ARG);
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 @@ -289,6 +299,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 @@ -17,7 +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.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -64,6 +67,9 @@ class FileSystemRealmCommand extends Command {
static final String FILE_SYSTEM_REALM_COMMAND = "filesystem-realm";
static final int SUMMARY_WIDTH = 100;

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";
Expand All @@ -79,6 +85,7 @@ class FileSystemRealmCommand extends Command {
private static final String NAME_ARG = "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 @@ -119,6 +126,9 @@ class FileSystemRealmCommand extends Command {
option.setArgName(NAME_ARG);
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 @@ -220,6 +230,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
27 changes: 27 additions & 0 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 @@ -43,11 +47,15 @@ class MaskCommand extends Command {
*/
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 @@ -61,13 +69,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 @@ -84,6 +94,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
26 changes: 26 additions & 0 deletions tool/src/main/java/org/wildfly/security/tool/VaultCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
import static org.wildfly.security.credential.store.CredentialStore.CredentialSourceProtectionParameter;
import static org.wildfly.security.credential.store.CredentialStore.getInstance;

import java.awt.Desktop;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
Expand Down Expand Up @@ -70,6 +73,9 @@ public class VaultCommand extends Command {

public static final String VAULT_COMMAND = "vault";

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 PRINT_SUMMARY_PARAM = "summary";
public static final String FAIL_IF_EXIST_PARAM = "fail-if-exist";
Expand All @@ -86,6 +92,7 @@ public class VaultCommand extends Command {
public static final String ALIAS_PARAM = "alias";
public static final String HELP_PARAM = "help";
public static final String DEBUG_PARAM = "debug";
public static final String WEB_PARAM = "web";

private static final class Descriptor {
String keyStoreURL;
Expand Down Expand Up @@ -151,6 +158,8 @@ public VaultCommand() {
options.addOption(h);
options.addOption(d);

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

@Override
Expand All @@ -163,6 +172,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 + "#Migrating_Existing_Vaults"));
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();
}

boolean printSummary = cmdLine.hasOption(PRINT_SUMMARY_PARAM);

Expand Down