Autopsy  4.14.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
IngestPipelinesConfiguration.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2012-2014 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.ingest;
20 
21 import java.io.IOException;
22 import java.nio.file.Path;
23 import java.nio.file.Paths;
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.logging.Level;
30 import org.w3c.dom.Document;
31 import org.w3c.dom.Element;
32 import org.w3c.dom.NodeList;
33 
38 final class IngestPipelinesConfiguration {
39 
40  private static final Logger logger = Logger.getLogger(IngestPipelinesConfiguration.class.getName());
41  private static final String PIPELINES_CONFIG_FILE = "PipelineConfig.xml"; //NON-NLS
42  private static final String PIPELINE_ELEM = "PIPELINE"; //NON-NLS
43  private static final int NUMBER_OF_PIPELINE_DEFINITIONS = 3;
44  private static final String PIPELINE_TYPE_ATTR = "type"; //NON-NLS
45  private static final String STAGE_ONE_DATA_SOURCE_INGEST_PIPELINE_ELEM = "ImageAnalysisStageOne"; //NON-NLS
46  private static final String STAGE_TWO_DATA_SOURCE_INGEST_PIPELINE_ELEM = "ImageAnalysisStageTwo"; //NON-NLS
47  private static final String FILE_INGEST_PIPELINE_ELEM = "FileAnalysis"; //NON-NLS
48  private static final String INGEST_MODULE_ELEM = "MODULE"; //NON-NLS
49 
50  private static IngestPipelinesConfiguration instance;
51 
52  private final List<String> stageOneDataSourceIngestPipelineConfig = new ArrayList<>();
53  private final List<String> fileIngestPipelineConfig = new ArrayList<>();
54  private final List<String> stageTwoDataSourceIngestPipelineConfig = new ArrayList<>();
55 
61  synchronized static IngestPipelinesConfiguration getInstance() {
62  if (instance == null) {
63  Logger.getLogger(IngestPipelinesConfiguration.class.getName()).log(Level.INFO, "Creating ingest module loader instance"); //NON-NLS
64  instance = new IngestPipelinesConfiguration();
65  }
66  return instance;
67  }
68 
73  private IngestPipelinesConfiguration() {
74  this.readPipelinesConfigurationFile();
75  }
76 
83  List<String> getStageOneDataSourceIngestPipelineConfig() {
84  return new ArrayList<>(stageOneDataSourceIngestPipelineConfig);
85  }
86 
93  List<String> getFileIngestPipelineConfig() {
94  return new ArrayList<>(fileIngestPipelineConfig);
95  }
96 
103  List<String> getStageTwoDataSourceIngestPipelineConfig() {
104  return new ArrayList<>(stageTwoDataSourceIngestPipelineConfig);
105  }
106 
110  private void readPipelinesConfigurationFile() {
111  try {
112  PlatformUtil.extractResourceToUserConfigDir(IngestPipelinesConfiguration.class, PIPELINES_CONFIG_FILE, false);
113 
114  Path configFilePath = Paths.get(PlatformUtil.getUserConfigDirectory(), PIPELINES_CONFIG_FILE);
115  Document doc = XMLUtil.loadDoc(IngestPipelinesConfiguration.class, configFilePath.toAbsolutePath().toString());
116  if (doc == null) {
117  return;
118  }
119 
120  // Get the document root element.
121  Element rootElement = doc.getDocumentElement();
122  if (null == rootElement) {
123  logger.log(Level.SEVERE, "Invalid pipelines config file"); //NON-NLS
124  return;
125  }
126 
127  // Get the pipeline elements and confirm that the correct number is
128  // present.
129  NodeList pipelineElements = rootElement.getElementsByTagName(IngestPipelinesConfiguration.PIPELINE_ELEM);
130  int numPipelines = pipelineElements.getLength();
131  if (numPipelines != IngestPipelinesConfiguration.NUMBER_OF_PIPELINE_DEFINITIONS) {
132  logger.log(Level.SEVERE, "Invalid pipelines config file"); //NON-NLS
133  return;
134  }
135 
136  // Parse the pipeline elements to populate the pipeline
137  // configuration lists.
138  List<String> pipelineConfig = null;
139  for (int pipelineNum = 0; pipelineNum < numPipelines; ++pipelineNum) {
140  Element pipelineElement = (Element) pipelineElements.item(pipelineNum);
141  String pipelineTypeAttr = pipelineElement.getAttribute(PIPELINE_TYPE_ATTR);
142  if (null != pipelineTypeAttr) {
143  switch (pipelineTypeAttr) {
144  case STAGE_ONE_DATA_SOURCE_INGEST_PIPELINE_ELEM:
145  pipelineConfig = this.stageOneDataSourceIngestPipelineConfig;
146  break;
147  case FILE_INGEST_PIPELINE_ELEM:
148  pipelineConfig = this.fileIngestPipelineConfig;
149  break;
150  case STAGE_TWO_DATA_SOURCE_INGEST_PIPELINE_ELEM:
151  pipelineConfig = this.stageTwoDataSourceIngestPipelineConfig;
152  break;
153  default:
154  logger.log(Level.SEVERE, "Invalid pipelines config file"); //NON-NLS
155  return;
156  }
157  }
158 
159  // Create an ordered list of class names. The sequence of class
160  // names defines the sequence of modules in the pipeline.
161  if (pipelineConfig != null) {
162  NodeList modulesElems = pipelineElement.getElementsByTagName(INGEST_MODULE_ELEM);
163  int numModules = modulesElems.getLength();
164  for (int moduleNum = 0; moduleNum < numModules; ++moduleNum) {
165  Element moduleElement = (Element) modulesElems.item(moduleNum);
166  String className = moduleElement.getTextContent();
167  if (null != className && !className.isEmpty()) {
168  pipelineConfig.add(className);
169  }
170  }
171  }
172  }
173  } catch (IOException ex) {
174  logger.log(Level.SEVERE, "Error copying default pipeline configuration to user dir", ex); //NON-NLS
175  }
176  }
177 }

Copyright © 2012-2020 Basis Technology. Generated on: Wed Apr 8 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.