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

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.