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

Copyright © 2012-2016 Basis Technology. Generated on: Fri Sep 29 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.