Merge pull request #7662 from eugene7646/invalid_report_profile_name_8409

CL processor returns error when invalid report config name is used (8409)
This commit is contained in:
eugene7646 2022-08-23 10:50:14 -04:00 committed by GitHub
commit ff244a93da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 118 additions and 50 deletions

View File

@ -75,9 +75,9 @@ public class CommandLineIngestManager extends CommandLineManager {
private Case caseForJob = null; private Case caseForJob = null;
private AutoIngestDataSource dataSource = null; private AutoIngestDataSource dataSource = null;
static int CL_SUCCESS = 0; static final int CL_SUCCESS = 0;
static int CL_RUN_FAILURE = -1; static final int CL_RUN_FAILURE = -1;
static int CL_PROCESS_FAILURE = 1; static final int CL_PROCESS_FAILURE = -2;
public CommandLineIngestManager() { public CommandLineIngestManager() {
} }

View File

@ -0,0 +1,47 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2022 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.sleuthkit.autopsy.report.infrastructure;
/**
* Instances of this exception class are thrown when there is an error while
* generating a report.
*/
public final class ReportGenerationException extends Exception {
private static final long serialVersionUID = 1L;
/**
* Constructs a new exception with the specified message.
*
* @param message The message.
*/
public ReportGenerationException(String message) {
super(message);
}
/**
* Constructs a new exception with the specified message and cause.
*
* @param message The message.
* @param cause The cause.
*/
public ReportGenerationException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@ -1,7 +1,7 @@
/* /*
* Autopsy Forensic Browser * Autopsy Forensic Browser
* *
* Copyright 2013-2020 Basis Technology Corp. * Copyright 2013-2022 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org * Contact: carrier <at> sleuthkit <dot> org
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -107,7 +107,7 @@ public class ReportGenerator {
this.reportGenerationPanel = null; this.reportGenerationPanel = null;
this.configName = configName; this.configName = configName;
} }
/** /**
* Constructs a report generator that generates one or more reports by * Constructs a report generator that generates one or more reports by
* running user-selected report modules and uses a report generation panel * running user-selected report modules and uses a report generation panel
@ -121,12 +121,15 @@ public class ReportGenerator {
this.progressIndicator = panel.getProgressPanel(); this.progressIndicator = panel.getProgressPanel();
this.configName = configName; this.configName = configName;
} }
/** /**
* Generates the reports specified by the reporting configuration passed * Generates the reports specified by the reporting configuration passed in
* in via the constructor. Does lookup of all existing report modules. * via the constructor. Does lookup of all existing report modules.
*
* @throws ReportGenerationException if an error occurred while generating
* the report.
*/ */
public void generateReports() { public void generateReports() throws ReportGenerationException {
// load all report modules // load all report modules
Map<String, ReportModule> modules = new HashMap<>(); Map<String, ReportModule> modules = new HashMap<>();
for (TableReportModule module : ReportModuleLoader.getTableReportModules()) { for (TableReportModule module : ReportModuleLoader.getTableReportModules()) {
@ -143,38 +146,51 @@ public class ReportGenerator {
// special case for PortableCaseReportModule // special case for PortableCaseReportModule
modules.put(FactoryClassNameNormalizer.normalize(PortableCaseReportModule.class.getCanonicalName()), new PortableCaseReportModule()); modules.put(FactoryClassNameNormalizer.normalize(PortableCaseReportModule.class.getCanonicalName()), new PortableCaseReportModule());
generateReports(modules); generateReports(modules);
} }
@NbBundle.Messages({
"ReportGenerator.error.noReportModules=No report modules found",
"# {0} - report configuration name", "ReportGenerator.error.unableToLoadConfig=Unable to load reporting configuration {0}.",
"# {0} - report module name", "ReportGenerator.error.moduleNotFound=Report module {0} not found",
"# {0} - report module name", "ReportGenerator.error.noTableReportSettings=No table report settings for report module {0}",
"# {0} - report module name", "ReportGenerator.error.noFileReportSettings=No file report settings for report module {0}",
"# {0} - report module name", "ReportGenerator.error.invalidSettings=Invalid settings for report module {0}",
"# {0} - report module name", "ReportGenerator.error.unsupportedType=Report module {0} has unsupported report module type",
"# {0} - report module name", "ReportGenerator.error.exception=Exception while running report module {0}"})
/** /**
* Generates the reports specified by the reporting configuration passed in * Generates the reports specified by the reporting configuration passed in
* via the constructor. * via the constructor.
* *
* @param modules Map of report module objects to use. This is useful when we want to * @param modules Map of report module objects to use. This is useful when
* re-use the module instances or limit which reports are generated. * we want to re-use the module instances or limit which
* reports are generated.
*
* @throws ReportGenerationException if an error occurred while generating
* the report.
*/ */
public void generateReports(Map<String, ReportModule> modules) { public void generateReports(Map<String, ReportModule> modules) throws ReportGenerationException {
if (modules == null || modules.isEmpty()) { if (modules == null || modules.isEmpty()) {
logger.log(Level.SEVERE, "No report modules found"); logger.log(Level.SEVERE, Bundle.ReportGenerator_error_noReportModules());
progressIndicator.updateStatusLabel("No report modules found. Exiting"); progressIndicator.updateStatusLabel(Bundle.ReportGenerator_error_noReportModules());
return; throw new ReportGenerationException(Bundle.ReportGenerator_error_noReportModules());
} }
ReportingConfig config = null; ReportingConfig config = null;
try { try {
config = ReportingConfigLoader.loadConfig(configName); config = ReportingConfigLoader.loadConfig(configName);
} catch (ReportConfigException ex) { } catch (ReportConfigException ex) {
logger.log(Level.SEVERE, "Unable to load reporting configuration " + configName + ". Exiting", ex); logger.log(Level.SEVERE, Bundle.ReportGenerator_error_unableToLoadConfig(configName), ex);
progressIndicator.updateStatusLabel("Unable to load reporting configuration " + configName + ". Exiting"); progressIndicator.updateStatusLabel(Bundle.ReportGenerator_error_unableToLoadConfig(configName));
return; throw new ReportGenerationException(Bundle.ReportGenerator_error_unableToLoadConfig(configName));
} }
if (config == null) { if (config == null) {
logger.log(Level.SEVERE, "Unable to load reporting configuration {0}. Exiting", configName); logger.log(Level.SEVERE, Bundle.ReportGenerator_error_unableToLoadConfig(configName));
progressIndicator.updateStatusLabel("Unable to load reporting configuration " + configName + ". Exiting"); progressIndicator.updateStatusLabel(Bundle.ReportGenerator_error_unableToLoadConfig(configName));
return; throw new ReportGenerationException(Bundle.ReportGenerator_error_unableToLoadConfig(configName));
} }
try { try {
@ -189,8 +205,8 @@ public class ReportGenerator {
String moduleName = entry.getKey(); String moduleName = entry.getKey();
ReportModule module = modules.get(moduleName); ReportModule module = modules.get(moduleName);
if (module == null) { if (module == null) {
logger.log(Level.SEVERE, "Report module {0} not found", moduleName); logger.log(Level.SEVERE, Bundle.ReportGenerator_error_moduleNotFound(moduleName));
progressIndicator.updateStatusLabel("Report module " + moduleName + " not found"); progressIndicator.updateStatusLabel(Bundle.ReportGenerator_error_moduleNotFound(moduleName));
continue; continue;
} }
@ -216,8 +232,8 @@ public class ReportGenerator {
// get table report settings // get table report settings
TableReportSettings tableSettings = config.getTableReportSettings(); TableReportSettings tableSettings = config.getTableReportSettings();
if (tableSettings == null) { if (tableSettings == null) {
logger.log(Level.SEVERE, "No table report settings for report module {0}", moduleName); logger.log(Level.SEVERE, Bundle.ReportGenerator_error_noTableReportSettings(moduleName));
progressIndicator.updateStatusLabel("No table report settings for report module " + moduleName); progressIndicator.updateStatusLabel(Bundle.ReportGenerator_error_noTableReportSettings(moduleName));
continue; continue;
} }
@ -228,8 +244,8 @@ public class ReportGenerator {
// get file report settings // get file report settings
FileReportSettings fileSettings = config.getFileReportSettings(); FileReportSettings fileSettings = config.getFileReportSettings();
if (fileSettings == null) { if (fileSettings == null) {
logger.log(Level.SEVERE, "No file report settings for report module {0}", moduleName); logger.log(Level.SEVERE, Bundle.ReportGenerator_error_noFileReportSettings(moduleName));
progressIndicator.updateStatusLabel("No file report settings for report module " + moduleName); progressIndicator.updateStatusLabel(Bundle.ReportGenerator_error_noFileReportSettings(moduleName));
continue; continue;
} }
@ -240,20 +256,20 @@ public class ReportGenerator {
if (settings instanceof NoReportModuleSettings) { if (settings instanceof NoReportModuleSettings) {
settings = new PortableCaseReportModuleSettings(); settings = new PortableCaseReportModuleSettings();
} else if (!(settings instanceof PortableCaseReportModuleSettings)) { } else if (!(settings instanceof PortableCaseReportModuleSettings)) {
logger.log(Level.SEVERE, "Invalid settings for report module {0}", moduleName); logger.log(Level.SEVERE, Bundle.ReportGenerator_error_invalidSettings(moduleName));
progressIndicator.updateStatusLabel("Invalid settings for report module " + moduleName); progressIndicator.updateStatusLabel(Bundle.ReportGenerator_error_invalidSettings(moduleName));
continue; continue;
} }
generatePortableCaseReport((PortableCaseReportModule) module, (PortableCaseReportModuleSettings) settings); generatePortableCaseReport((PortableCaseReportModule) module, (PortableCaseReportModuleSettings) settings);
} else { } else {
logger.log(Level.SEVERE, "Report module {0} has unsupported report module type", moduleName); logger.log(Level.SEVERE, Bundle.ReportGenerator_error_unsupportedType(moduleName));
progressIndicator.updateStatusLabel("Report module " + moduleName + " has unsupported report module type"); progressIndicator.updateStatusLabel(Bundle.ReportGenerator_error_unsupportedType(moduleName));
} }
} catch (IOException e) { } catch (IOException e) {
logger.log(Level.SEVERE, "Exception while running report module {0}: {1}", new Object[]{moduleName, e.getMessage()}); logger.log(Level.SEVERE, Bundle.ReportGenerator_error_exception(moduleName));
progressIndicator.updateStatusLabel("Exception while running report module " + moduleName); progressIndicator.updateStatusLabel(Bundle.ReportGenerator_error_exception(moduleName));
} }
} }
} finally { } finally {
@ -321,15 +337,15 @@ public class ReportGenerator {
TableReportGenerator generator = new TableReportGenerator(tableReportSettings, progressIndicator, tableReport); TableReportGenerator generator = new TableReportGenerator(tableReportSettings, progressIndicator, tableReport);
generator.execute(); generator.execute();
tableReport.endReport(); tableReport.endReport();
// finish progress, wrap up // finish progress, wrap up
errorList = generator.getErrorList(); errorList = generator.getErrorList();
// if error list is empty, the operation has completed successfully. If not there is an error // if error list is empty, the operation has completed successfully. If not there is an error
ReportProgressPanel.ReportStatus finalStatus = (errorList == null || errorList.isEmpty()) ? ReportProgressPanel.ReportStatus finalStatus = (errorList == null || errorList.isEmpty())
ReportProgressPanel.ReportStatus.COMPLETE : ? ReportProgressPanel.ReportStatus.COMPLETE
ReportProgressPanel.ReportStatus.ERROR; : ReportProgressPanel.ReportStatus.ERROR;
progressIndicator.complete(finalStatus); progressIndicator.complete(finalStatus);
} }
} }
@ -368,10 +384,10 @@ public class ReportGenerator {
int i = 0; int i = 0;
// Add files to report. // Add files to report.
for (AbstractFile file : files) { for (AbstractFile file : files) {
if(shouldFilterFromReport(file, fileReportSettings)) { if (shouldFilterFromReport(file, fileReportSettings)) {
continue; continue;
} }
// Check to see if any reports have been cancelled. // Check to see if any reports have been cancelled.
if (progressIndicator.getStatus() == ReportStatus.CANCELED) { if (progressIndicator.getStatus() == ReportStatus.CANCELED) {
return; return;
@ -393,9 +409,9 @@ public class ReportGenerator {
progressIndicator.complete(ReportStatus.COMPLETE); progressIndicator.complete(ReportStatus.COMPLETE);
} }
} }
private boolean shouldFilterFromReport(AbstractFile file, FileReportSettings fileReportSettings) { private boolean shouldFilterFromReport(AbstractFile file, FileReportSettings fileReportSettings) {
if(fileReportSettings.getSelectedDataSources() == null) { if (fileReportSettings.getSelectedDataSources() == null) {
return false; return false;
} }
// Filter if the data source id is not in the list to process // Filter if the data source id is not in the list to process

View File

@ -2,7 +2,7 @@
* *
* Autopsy Forensic Browser * Autopsy Forensic Browser
* *
* Copyright 2012-2020 Basis Technology Corp. * Copyright 2012-2022 Basis Technology Corp.
* *
* Copyright 2012 42six Solutions. * Copyright 2012 42six Solutions.
* Contact: aebadirad <at> 42six <dot> com * Contact: aebadirad <at> 42six <dot> com
@ -108,7 +108,12 @@ public final class ReportWizardAction extends CallableSystemAction implements Pr
Map<String, ReportModule> modules = (Map<String, ReportModule>) wiz.getProperty("modules"); Map<String, ReportModule> modules = (Map<String, ReportModule>) wiz.getProperty("modules");
ReportGenerator generator = new ReportGenerator(configName, panel); //NON-NLS ReportGenerator generator = new ReportGenerator(configName, panel); //NON-NLS
ReportWorker worker = new ReportWorker(() -> { ReportWorker worker = new ReportWorker(() -> {
generator.generateReports(modules); try {
generator.generateReports(modules);
} catch (ReportGenerationException ex) {
// do nothing. the error message will be logged and
// displayed by the progress panel.
}
}); });
worker.execute(); worker.execute();
generator.displayProgressPanel(); generator.displayProgressPanel();