Package org.wildfly.security.tool
Class FileSystemRealmCommand
- java.lang.Object
-
- org.wildfly.security.tool.Command
-
- org.wildfly.security.tool.FileSystemRealmCommand
-
class FileSystemRealmCommand extends Command
Elytron-Tool command to convert legacy properties file into a FileSystemRealm. Also, optionally provides a WildFly CLI script to register the FileSystemRealm and corresponding security-domain in WildFly.- Author:
- Justin Cook
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
FileSystemRealmCommand.Descriptor
-
Field Summary
Fields Modifier and Type Field Description private static String
BULK_CONVERT_PARAM
private org.apache.commons.cli.CommandLine
cmdLine
private static String
DEBUG_PARAM
private static String
DEFAULT_FILESYSTEM_REALM_NAME
private static String
DEFAULT_SECURITY_DOMAIN_NAME
private List<FileSystemRealmCommand.Descriptor>
descriptors
private static String
DIRECTORY_ARG
private static String
FILE_ARG
(package private) static String
FILE_SYSTEM_REALM_COMMAND
private static String
FILESYSTEM_REALM_NAME_PARAM
(package private) static int
GENERAL_CONFIGURATION_WARNING
private static String
HELP_PARAM
private static String
NAME_ARG
private org.apache.commons.cli.Options
options
private static String
OUTPUT_LOCATION_PARAM
private List<String>
PARAMS_LIST
private org.apache.commons.cli.CommandLineParser
parser
private static String
ROLES_FILE_PARAM
private static String
SECURITY_DOMAIN_NAME_PARAM
private static String
SILENT_PARAM
private boolean
silentMode
private static String
SUMMARY_PARAM
(package private) static int
SUMMARY_WIDTH
private boolean
summaryMode
private StringBuilder
summaryString
private static String
USERS_FILE_PARAM
private boolean
warningOccurred
-
Fields inherited from class org.wildfly.security.tool.Command
GENERAL_CONFIGURATION_ERROR, INPUT_DATA_NOT_CONFIRMED, WIDTH
-
-
Constructor Summary
Constructors Constructor Description FileSystemRealmCommand()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
copyAddResetDescriptor(FileSystemRealmCommand.Descriptor original)
Copies a Descriptor into a temporary one for it can be cloned into the list of descriptorsprivate void
createFileSystemRealm()
Handles creating the Elytron filesystem-realm from the input arraysprivate void
createWildFlyScript()
Creates the script/commands the user must run for Elytron to recognize and use the new filesystem-realmprivate void
errorHandler(Exception e)
Determines if a summary needs to be printed and prints summary after an error is thrownvoid
execute(String[] args)
private void
findMissingRequiredValuesAndSetValues(int count, FileSystemRealmCommand.Descriptor descriptor)
Determines if the current descriptor block is missing any required values and then if it is, prints out a warning message and sets that required value and the optional values to nullprivate String
getDescriptorParam(String param, FileSystemRealmCommand.Descriptor descriptor)
Returns the value for a given param in a Descriptor objectvoid
help()
Displays the help for the commandprivate void
parseDescriptorFile(String file)
Handles input being given as a descriptor fileprivate List<String>
parseInputFile(FileSystemRealmCommand.Descriptor descriptor, String param, int count)
Parses a uses or roles properties file to get the user mappings (users-password for users files and users-roles for roles files).private void
printDescriptorBlocks(int count)
Prints out information found in a descriptor file for summary modeprivate void
warningHandler(String warning)
Prints out a warning message if silentMode is not enabled and adds the warning to the summary if summaryMode is enabled-
Methods inherited from class org.wildfly.security.tool.Command
aliases, getProvidersSupplier, getStatus, getToolCommand, isAlias, isEnableDebug, isWindows, printDuplicatesWarning, printDuplicatesWarning, prompt, setEnableDebug, setStatus, setToolCommand
-
-
-
-
Field Detail
-
GENERAL_CONFIGURATION_WARNING
static final int GENERAL_CONFIGURATION_WARNING
- See Also:
- Constant Field Values
-
FILE_SYSTEM_REALM_COMMAND
static final String FILE_SYSTEM_REALM_COMMAND
- See Also:
- Constant Field Values
-
SUMMARY_WIDTH
static final int SUMMARY_WIDTH
- See Also:
- Constant Field Values
-
HELP_PARAM
private static final String HELP_PARAM
- See Also:
- Constant Field Values
-
DEBUG_PARAM
private static final String DEBUG_PARAM
- See Also:
- Constant Field Values
-
SILENT_PARAM
private static final String SILENT_PARAM
- See Also:
- Constant Field Values
-
SUMMARY_PARAM
private static final String SUMMARY_PARAM
- See Also:
- Constant Field Values
-
USERS_FILE_PARAM
private static final String USERS_FILE_PARAM
- See Also:
- Constant Field Values
-
ROLES_FILE_PARAM
private static final String ROLES_FILE_PARAM
- See Also:
- Constant Field Values
-
OUTPUT_LOCATION_PARAM
private static final String OUTPUT_LOCATION_PARAM
- See Also:
- Constant Field Values
-
FILESYSTEM_REALM_NAME_PARAM
private static final String FILESYSTEM_REALM_NAME_PARAM
- See Also:
- Constant Field Values
-
SECURITY_DOMAIN_NAME_PARAM
private static final String SECURITY_DOMAIN_NAME_PARAM
- See Also:
- Constant Field Values
-
BULK_CONVERT_PARAM
private static final String BULK_CONVERT_PARAM
- See Also:
- Constant Field Values
-
FILE_ARG
private static final String FILE_ARG
- See Also:
- Constant Field Values
-
DIRECTORY_ARG
private static final String DIRECTORY_ARG
- See Also:
- Constant Field Values
-
NAME_ARG
private static final String NAME_ARG
- See Also:
- Constant Field Values
-
DEFAULT_FILESYSTEM_REALM_NAME
private static final String DEFAULT_FILESYSTEM_REALM_NAME
- See Also:
- Constant Field Values
-
DEFAULT_SECURITY_DOMAIN_NAME
private static final String DEFAULT_SECURITY_DOMAIN_NAME
- See Also:
- Constant Field Values
-
descriptors
private List<FileSystemRealmCommand.Descriptor> descriptors
-
options
private org.apache.commons.cli.Options options
-
parser
private org.apache.commons.cli.CommandLineParser parser
-
cmdLine
private org.apache.commons.cli.CommandLine cmdLine
-
silentMode
private boolean silentMode
-
summaryMode
private boolean summaryMode
-
summaryString
private StringBuilder summaryString
-
warningOccurred
private boolean warningOccurred
-
-
Method Detail
-
warningHandler
private void warningHandler(String warning)
Prints out a warning message if silentMode is not enabled and adds the warning to the summary if summaryMode is enabled- Parameters:
warning
- The warning to be shown
-
errorHandler
private void errorHandler(Exception e) throws Exception
Determines if a summary needs to be printed and prints summary after an error is thrown- Parameters:
e
- The exception thrown during execution- Throws:
Exception
- The exception to be handled by Elytron Tool
-
printDescriptorBlocks
private void printDescriptorBlocks(int count)
Prints out information found in a descriptor file for summary mode- Parameters:
count
- The amount of descriptor blocks in the file
-
getDescriptorParam
private String getDescriptorParam(String param, FileSystemRealmCommand.Descriptor descriptor)
Returns the value for a given param in a Descriptor object- Parameters:
param
- The parameter to be obtained from the Descriptor objectdescriptor
- The Descriptor object to be used- Returns:
- The value of the given parameter
-
parseDescriptorFile
private void parseDescriptorFile(String file) throws Exception
Handles input being given as a descriptor file- Throws:
Exception
- Exception to be handled by Elytron Tool
-
copyAddResetDescriptor
private void copyAddResetDescriptor(FileSystemRealmCommand.Descriptor original)
Copies a Descriptor into a temporary one for it can be cloned into the list of descriptors- Parameters:
original
- The original descriptor that is continually modified
-
findMissingRequiredValuesAndSetValues
private void findMissingRequiredValuesAndSetValues(int count, FileSystemRealmCommand.Descriptor descriptor)
Determines if the current descriptor block is missing any required values and then if it is, prints out a warning message and sets that required value and the optional values to null- Parameters:
count
- The index of the current descriptor block
-
parseInputFile
private List<String> parseInputFile(FileSystemRealmCommand.Descriptor descriptor, String param, int count) throws Exception
Parses a uses or roles properties file to get the user mappings (users-password for users files and users-roles for roles files).- Parameters:
descriptor
- The descriptor class holding the information for this blockparam
- The type of input file (either users-file or roles-file)count
- The index of the current descriptor block- Returns:
- The String list of each user mapping in the file
- Throws:
Exception
- Exception to be handled by Elytron Tool
-
createFileSystemRealm
private void createFileSystemRealm() throws Exception
Handles creating the Elytron filesystem-realm from the input arrays- Throws:
Exception
- Exception to be handled by Elytron Tool
-
-