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

Copyright © 2012-2016 Basis Technology. Generated on: Mon May 7 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.