Autopsy  4.9.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
IngestModuleFactoryLoader.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2014-2018 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.util.ArrayList;
22 import java.util.HashMap;
23 import java.util.HashSet;
24 import java.util.List;
25 import java.util.TreeMap;
26 import java.util.logging.Level;
27 import org.openide.DialogDisplayer;
28 import org.openide.NotifyDescriptor;
29 import org.openide.util.Lookup;
30 import org.openide.util.NbBundle;
45 
49 final class IngestModuleFactoryLoader {
50 
51  private static final Logger logger = Logger.getLogger(IngestModuleFactoryLoader.class.getName());
52  private static final String SAMPLE_MODULE_FACTORY_CLASS_NAME = SampleIngestModuleFactory.class.getCanonicalName();
53  private static final ArrayList<String> coreModuleOrdering = new ArrayList<String>() {
54  {
55  // The ordering of the core ingest module factories implemented
56  // using Java is hard-coded.
57  add("org.sleuthkit.autopsy.recentactivity.RecentActivityExtracterModuleFactory"); //NON-NLS
58  add(HashLookupModuleFactory.class.getCanonicalName());
59  add(FileTypeIdModuleFactory.class.getCanonicalName());
60  add(FileExtMismatchDetectorModuleFactory.class.getCanonicalName());
61  add(EmbeddedFileExtractorModuleFactory.class.getCanonicalName());
62  add(ExifParserModuleFactory.class.getCanonicalName());
63  add("org.sleuthkit.autopsy.keywordsearch.KeywordSearchModuleFactory"); //NON-NLS
64  add("org.sleuthkit.autopsy.thunderbirdparser.EmailParserModuleFactory"); //NON-NLS
65  add(EncryptionDetectionModuleFactory.class.getCanonicalName());
66  add(InterestingItemsIngestModuleFactory.class.getCanonicalName());
67  add(CentralRepoIngestModuleFactory.class.getCanonicalName());
68  add(PhotoRecCarverIngestModuleFactory.class.getCanonicalName());
69  add(VMExtractorIngestModuleFactory.class.getCanonicalName());
70  add(DataSourceIntegrityModuleFactory.class.getCanonicalName());
71  }
72  };
73 
84  static List<IngestModuleFactory> getIngestModuleFactories() {
85  // A hash set of display names and a hash map of class names to
86  // discovered factories are used to de-duplicate and order the
87  // factories.
88  HashSet<String> moduleDisplayNames = new HashSet<>();
89  HashMap<String, IngestModuleFactory> javaFactoriesByClass = new HashMap<>();
90 
91  // Discover the ingest module factories implemented using Java with a
92  // service provider annotation for the IngestModuleFactory interface.
93  for (IngestModuleFactory factory : Lookup.getDefault().lookupAll(IngestModuleFactory.class)) {
94  IngestModuleFactoryLoader.addFactory(factory, moduleDisplayNames, javaFactoriesByClass);
95  }
96 
97  // Discover the ingest module factories implemented using Java with a
98  // service provider annotation for the IngestModuleFactoryAdapter
99  // abstract base class.
100  for (IngestModuleFactory factory : Lookup.getDefault().lookupAll(IngestModuleFactoryAdapter.class)) {
101  if (!javaFactoriesByClass.containsValue(factory)) {
102  IngestModuleFactoryLoader.addFactory(factory, moduleDisplayNames, javaFactoriesByClass);
103  }
104  }
105 
106  // Add the core ingest module factories in the desired order, removing
107  // the core factories from the map so that the map will only contain
108  // non-core modules after this loop.
109  List<IngestModuleFactory> factories = new ArrayList<>();
110  for (String className : coreModuleOrdering) {
111  IngestModuleFactory coreFactory = javaFactoriesByClass.remove(className);
112  if (coreFactory != null) {
113  factories.add(coreFactory);
114  } else {
115  logger.log(Level.SEVERE, "Core factory {0} not loaded", className); //NON-NLS
116  }
117  }
118 
119  // Add any remaining non-core factories discovered. Order with an
120  // alphabetical sort by module display name.
121  TreeMap<String, IngestModuleFactory> javaFactoriesSortedByName = new TreeMap<>();
122  for (IngestModuleFactory factory : javaFactoriesByClass.values()) {
123  javaFactoriesSortedByName.put(factory.getModuleDisplayName(), factory);
124  }
125  factories.addAll(javaFactoriesSortedByName.values());
126 
127  // Add any ingest module factories implemented using Jython. Order is
128  // not guaranteed!
129  for (IngestModuleFactory factory : JythonModuleLoader.getIngestModuleFactories()) {
130  if (!moduleDisplayNames.contains(factory.getModuleDisplayName())) {
131  moduleDisplayNames.add(factory.getModuleDisplayName());
132  factories.add(factory);
133  logger.log(Level.INFO, "Found ingest module factory: name = {0}, version = {1}", new Object[]{factory.getModuleDisplayName(), factory.getModuleVersionNumber()}); //NON-NLS
134  } else {
135  logger.log(Level.SEVERE, "Found duplicate ingest module display name (name = {0})", factory.getModuleDisplayName()); //NON-NLS
136  DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
137  NbBundle.getMessage(IngestModuleFactoryLoader.class, "IngestModuleFactoryLoader.errorMessages.duplicateDisplayName", factory.getModuleDisplayName()),
138  NotifyDescriptor.ERROR_MESSAGE));
139  }
140  }
141 
142  return factories;
143  }
144 
145  private static void addFactory(IngestModuleFactory factory, HashSet<String> moduleDisplayNames, HashMap<String, IngestModuleFactory> javaFactoriesByClass) {
146  // Ignore the sample ingest module factories implemented in Java.
147  String className = factory.getClass().getCanonicalName();
148  if (className.equals(IngestModuleFactoryLoader.SAMPLE_MODULE_FACTORY_CLASS_NAME)) {
149  return;
150  }
151 
152  if (!moduleDisplayNames.contains(factory.getModuleDisplayName())) {
153  moduleDisplayNames.add(factory.getModuleDisplayName());
154  javaFactoriesByClass.put(factory.getClass().getCanonicalName(), factory);
155  logger.log(Level.INFO, "Found ingest module factory: name = {0}, version = {1}", new Object[]{factory.getModuleDisplayName(), factory.getModuleVersionNumber()}); //NON-NLS
156  } else {
157  logger.log(Level.SEVERE, "Found duplicate ingest module display name (name = {0})", factory.getModuleDisplayName()); //NON-NLS
158  DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
159  NbBundle.getMessage(IngestModuleFactoryLoader.class, "IngestModuleFactoryLoader.errorMessages.duplicateDisplayName", factory.getModuleDisplayName()),
160  NotifyDescriptor.ERROR_MESSAGE));
161  }
162  }
163 
164 }

Copyright © 2012-2018 Basis Technology. Generated on: Tue Dec 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.