public class ConfigurationController extends Object
The main method of this class relies on the fact that it has been executed and loaded from within a runnable jar archive containing a manifest file consisting of basic project information. By default, i.e. without providing any command line arguments, the main configuration will be looked up at the following locations:
If the file could not be located successfully an exception will be thrown. Alternatively, the main configuration file path may be provided as command line argument using the switch '-c' or '--configuration-file'.
During the initialization procedure the ANTLR configuration parser will be invoked. Any encountered syntax errors will be printed to the standard error stream, however, unless any critical errors during the setup process occurred the application will continue running.
After completing the initialization procedure the control over the program flow will be returned to the caller in the main method, who in turn is able to retrieve the parsed and validated @{RubanetraSystemConfiguration}. By default, invoking the start-method of this class will initialize a default @{DroolsKrakenProtocolHandler} which effectively passes all PCAP-entries to the Kraken protocol decoding pipeline and ultimately to the Drools rule engine.
Modifier and Type | Field and Description |
---|---|
static String |
defaultMainConfigEnvVar |
static String |
defaultMainConfigName |
static String |
defaultMainConfigPath |
Constructor and Description |
---|
ConfigurationController()
Creates a new instance of itself and a
RubanetraSystemConfigurationBuilder |
Modifier and Type | Method and Description |
---|---|
void |
addInputFiles(String... filePaths)
Adds files containing network captures to the configuration builder
RubanetraSystemConfigurationBuilder . |
boolean |
checkMainConfigFile(File file)
Performs a simple file metadata validation (is it readable, is it a file),
however, it does not verify the contents of the file itself.
|
static org.apache.commons.cli.Options |
createDefaultOptions() |
File |
createFileFromResourceString(String filePath)
Tries to create a file object by looking up filePath in the current classloader's classpath.
|
File |
getCanonicalFile(String mainConfigurationPath)
Tries to represent the path denoted by mainConfigurationPath canonically.
|
static Attributes |
getMainAttributes() |
RubanetraSystemConfiguration |
getRubanetraSystemConfiguration() |
boolean |
initialize()
This method initializes the system invoking a parser for the main configuration file
denoted by (in processing order):
"rubanetra.conf" in the classpath and working directory
"./conf/rubanetra.conf" in the classpath and working directory
path denoted by environment variable FNA_SYSTEM_CONF_FILE in the class path and working directory
It tries to canonicalize all encountered file paths and will fail if it is unable
to create a canonical representation.
|
boolean |
initialize(File mainConfigFile)
This method initializes the system invoking a parser for the main configuration file
denoted by mainConfigFile.
|
boolean |
initialize(String mainConfigurationPath)
Convenience method for
initialize(java.io.File) . |
boolean |
initializeFromEnvVar(String envVariableName)
Tries to look up the value of the environment variable denoted by envVariableName, and interprets it as
main configuration path (
initialize(java.io.File) will be called) |
static void |
main(String[] args)
Creates a
ConfigurationController using default options
createDefaultOptions() and a GnuParser to parse the command line
arguments. |
void |
setOutputFile(String outputFilePath)
Sets the default output file for the derived and parsed data using
RubanetraSystemConfiguration.OutputFormat |
void |
setOutputFormat(String outputFormat)
Sets the
RubanetraSystemConfiguration.OutputFormat to apply
as serialization variant. |
void |
start()
This method will do nothing, unless one of the
initialize(java.io.File) methods has been invoked
successfully. |
public static final String defaultMainConfigName
public static final String defaultMainConfigPath
public static final String defaultMainConfigEnvVar
public ConfigurationController()
RubanetraSystemConfigurationBuilder
public static org.apache.commons.cli.Options createDefaultOptions()
public static void main(String[] args)
ConfigurationController
using default options
createDefaultOptions()
and a GnuParser
to parse the command line
arguments.
After a successful parsing process, start()
will be invoked.args
- command line arguments as defined by createDefaultOptions()
public static Attributes getMainAttributes()
public boolean initialize(File mainConfigFile)
RubanetraSystemConfigurationParser
and
RubanetraSystemConfigurationBaseListenerImpl
for parsing
functionality and builds the final RubanetraSystemConfiguration
object which can be obtained iff this method returned true via getRubanetraSystemConfiguration()
.mainConfigFile
- the main configuration file, which may not be nullgetRubanetraSystemConfiguration()
.NullPointerException
- if the main config file is a null pointerIllegalArgumentException
- if the main config file is not validpublic boolean initialize(String mainConfigurationPath)
initialize(java.io.File)
.
It creates a file based on the given path.mainConfigurationPath
- the path of the main configuration filegetRubanetraSystemConfiguration()
.public boolean initialize()
RubanetraSystemConfigurationParser
and
RubanetraSystemConfigurationBaseListenerImpl
for parsing
functionality and builds the final RubanetraSystemConfiguration
object which can be obtained iff this method returned true via getRubanetraSystemConfiguration()
.getRubanetraSystemConfiguration()
.NullPointerException
- if the main config file is a null pointerIllegalArgumentException
- if the main config file is not validpublic boolean initializeFromEnvVar(String envVariableName)
initialize(java.io.File)
will be called)envVariableName
- the name of the environment variable to look up (the value should represent the main
configuration file path)getRubanetraSystemConfiguration()
afterwards.public File getCanonicalFile(String mainConfigurationPath)
mainConfigurationPath
- the file to canonicalize.public File createFileFromResourceString(String filePath)
filePath
- the path of the file in the current classpathpublic boolean checkMainConfigFile(File file)
file
- the file to checkpublic void addInputFiles(String... filePaths)
RubanetraSystemConfigurationBuilder
.
This method may not be invoked after the initialization step has been completed, i.e. this method must be
invoked before initialize(java.io.File)
.
filePaths
- a number of file paths containing network captures in the specified
RubanetraSystemConfiguration.InputFormat
public void setOutputFile(String outputFilePath)
RubanetraSystemConfiguration.OutputFormat
This method may not be invoked after the initialization step has been completed, i.e. this method must be
invoked before initialize(java.io.File)
.
outputFilePath
- the path of the default output filepublic void setOutputFormat(String outputFormat)
RubanetraSystemConfiguration.OutputFormat
to apply
as serialization variant.
This method may not be invoked after the initialization step has been completed, i.e. this method must be
invoked before initialize(java.io.File)
.
outputFormat
- the String representation of a RubanetraSystemConfiguration.OutputFormat
public RubanetraSystemConfiguration getRubanetraSystemConfiguration()
initialize(java.io.File)
methods was invoked
successfully, then it will return the constructed RubanetraSystemConfiguration
.public void start()
initialize(java.io.File)
methods has been invoked
successfully.
If a valid RubanetraSystemConfiguration
is encountered,
a DroolsKrakenProtocolHandler
will be constructed and
PcapHandler.readNextPcapEntry(at.jku.fim.rubanetra.pcap.PcapActivityListener)
will be called as long as it returns true (using an infinite loop), i.e. until all network packets have been read
from the input files. Afterwards, it will try to close all opened input and output streams, that is it will call
DroolsKrakenProtocolHandler.close()
and PcapHandler.close()
.
Ultimately the existing reference to the RubanetraSystemConfiguration
will be erased, therefore allowing for a subsequent initialization call while reusing the same object.
Copyright © 2013–2015 Institute of networks and security. All rights reserved.