Changed plumbing for adding content to hash db actions

This commit is contained in:
Richard Cordovano 2013-10-28 15:09:58 -04:00
parent 136f93d38c
commit c13f41f67c
12 changed files with 127 additions and 39 deletions

View File

@ -0,0 +1,37 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2011 - 2013 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.sleuthkit.autopsy.corecomponentinterfaces;
import java.util.List;
import javax.swing.Action;
/**
* Implementers of this interface provide Actions that will be added to context
* menus in Autopsy.
*/
public interface ContextMenuActionsProvider {
/**
* Gets context menu Actions appropriate to the org.sleuthkit.datamodel
* objects in the NetBeans Lookup for the active TopComponent.
* Implementers can discover the data model objects by calling
* org.openide.util.Utilities.actionsGlobalContext().lookupAll().
* @return A list, possibly empty, of Action objects.
*/
List<Action> getActions();
}

View File

@ -0,0 +1,45 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2011 - 2013 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.sleuthkit.autopsy.coreutils;
import org.openide.util.Lookup;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.swing.Action;
import org.sleuthkit.autopsy.corecomponentinterfaces.ContextMenuActionsProvider;
/**
* This class implements the ContextMenuActionsProvider extension point.
*/
public class ContextMenuExtensionPoint {
/**
* Gets all of the Actions provided by registered implementers of the
* ContextMenuActionsProvider interface.
* @return A list, possibly empty, of Action objects.
*/
static public List<Action> getActions() {
ArrayList<Action> actions = new ArrayList<>();
Collection<? extends ContextMenuActionsProvider> actionProviders = Lookup.getDefault().lookupAll(ContextMenuActionsProvider.class);
for (ContextMenuActionsProvider provider : actionProviders) {
actions.addAll(provider.getActions());
}
return actions;
}
}

View File

@ -21,7 +21,6 @@ package org.sleuthkit.autopsy.datamodel;
import java.util.ArrayList;
import java.util.List;
import javax.swing.Action;
import org.sleuthkit.autopsy.directorytree.AddContentToHashDbAction;
import org.sleuthkit.autopsy.directorytree.ExtractAction;
import org.sleuthkit.autopsy.directorytree.NewWindowViewAction;
import org.sleuthkit.autopsy.directorytree.TagAbstractFileAction;
@ -78,7 +77,6 @@ public class DirectoryNode extends AbstractFsContentNode<AbstractFile> {
actions.add(ExtractAction.getInstance());
actions.add(null); // creates a menu separator
actions.add(TagAbstractFileAction.getInstance());
actions.add(AddContentToHashDbAction.getInstance());
return actions.toArray(new Action[0]);
}

View File

@ -21,7 +21,6 @@ package org.sleuthkit.autopsy.datamodel;
import java.util.ArrayList;
import java.util.List;
import javax.swing.Action;
import org.sleuthkit.autopsy.directorytree.AddContentToHashDbAction;
import org.sleuthkit.autopsy.directorytree.ExternalViewerAction;
import org.sleuthkit.autopsy.directorytree.ExtractAction;
import org.sleuthkit.autopsy.directorytree.HashSearchAction;
@ -86,7 +85,6 @@ public class FileNode extends AbstractFsContentNode<AbstractFile> {
actionsList.add(new HashSearchAction("Search for files with the same MD5 hash", this));
actionsList.add(null); // creates a menu separator
actionsList.add(TagAbstractFileAction.getInstance());
actionsList.add(AddContentToHashDbAction.getInstance());
return actionsList.toArray(new Action[0]);
}

View File

@ -24,7 +24,6 @@ import java.util.List;
import java.util.Map;
import javax.swing.Action;
import org.openide.nodes.Sheet;
import org.sleuthkit.autopsy.directorytree.AddContentToHashDbAction;
import org.sleuthkit.autopsy.directorytree.ExternalViewerAction;
import org.sleuthkit.autopsy.directorytree.ExtractAction;
import org.sleuthkit.autopsy.directorytree.NewWindowViewAction;
@ -110,7 +109,6 @@ public class LayoutFileNode extends AbstractAbstractFileNode<LayoutFile> {
actionsList.add(ExtractAction.getInstance());
actionsList.add(null); // creates a menu separator
actionsList.add(TagAbstractFileAction.getInstance());
actionsList.add(AddContentToHashDbAction.getInstance());
return actionsList.toArray(new Action[0]);
}

View File

@ -26,7 +26,6 @@ import java.util.Map;
import javax.swing.Action;
import org.openide.nodes.Sheet;
import org.sleuthkit.autopsy.datamodel.DisplayableItemNode.TYPE;
import org.sleuthkit.autopsy.directorytree.AddContentToHashDbAction;
import org.sleuthkit.autopsy.directorytree.ExternalViewerAction;
import org.sleuthkit.autopsy.directorytree.ExtractAction;
import org.sleuthkit.autopsy.directorytree.HashSearchAction;
@ -94,7 +93,6 @@ public class LocalFileNode extends AbstractAbstractFileNode<AbstractFile> {
actionsList.add(new HashSearchAction("Search for files with the same MD5 hash", this));
actionsList.add(null); // creates a menu separator
actionsList.add(TagAbstractFileAction.getInstance());
actionsList.add(AddContentToHashDbAction.getInstance());
return actionsList.toArray(new Action[0]);
}

View File

@ -25,7 +25,6 @@ import java.util.Map;
import javax.swing.Action;
import org.openide.nodes.Sheet;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.directorytree.AddContentToHashDbAction;
import org.sleuthkit.autopsy.directorytree.ExtractAction;
import org.sleuthkit.autopsy.directorytree.NewWindowViewAction;
import org.sleuthkit.autopsy.directorytree.TagAbstractFileAction;
@ -83,7 +82,6 @@ public class VirtualDirectoryNode extends AbstractAbstractFileNode<VirtualDirect
actions.add(ExtractAction.getInstance());
actions.add(null); // creates a menu separator
actions.add(TagAbstractFileAction.getInstance());
actions.add(AddContentToHashDbAction.getInstance());
return actions.toArray(new Action[0]);
}

View File

@ -208,7 +208,6 @@ public class DataResultFilterNode extends FilterNode {
actions.add(null); // creates a menu separator
actions.add(TagAbstractFileAction.getInstance());
actions.add(TagBlackboardArtifactAction.getInstance());
actions.add(AddContentToHashDbAction.getInstance());
}
}
if ((d = ban.getLookup().lookup(Directory.class)) != null) {
@ -225,7 +224,6 @@ public class DataResultFilterNode extends FilterNode {
actions.add(null); // creates a menu separator
actions.add(TagAbstractFileAction.getInstance());
actions.add(TagBlackboardArtifactAction.getInstance());
actions.add(AddContentToHashDbAction.getInstance());
}
}
if ((vd = ban.getLookup().lookup(VirtualDirectory.class)) != null) {
@ -242,7 +240,6 @@ public class DataResultFilterNode extends FilterNode {
actions.add(null); // creates a menu separator
actions.add(TagAbstractFileAction.getInstance());
actions.add(TagBlackboardArtifactAction.getInstance());
actions.add(AddContentToHashDbAction.getInstance());
}
} else if ((lf = ban.getLookup().lookup(LayoutFile.class)) != null) {
LayoutFileNode lfn = new LayoutFileNode(lf);
@ -258,7 +255,6 @@ public class DataResultFilterNode extends FilterNode {
actions.add(null); // creates a menu separator
actions.add(TagAbstractFileAction.getInstance());
actions.add(TagBlackboardArtifactAction.getInstance());
actions.add(AddContentToHashDbAction.getInstance());
}
} else if ((locF = ban.getLookup().lookup(LocalFile.class)) != null
|| (locF = ban.getLookup().lookup(DerivedFile.class)) != null) {
@ -275,7 +271,6 @@ public class DataResultFilterNode extends FilterNode {
actions.add(null); // creates a menu separator
actions.add(TagAbstractFileAction.getInstance());
actions.add(TagBlackboardArtifactAction.getInstance());
actions.add(AddContentToHashDbAction.getInstance());
}
}

View File

@ -102,7 +102,6 @@ public class ExplorerNodeActionVisitor extends ContentVisitor.Default<List<? ext
public List<? extends Action> visit(final Directory d) {
List<Action> actions = new ArrayList<>();
actions.add(TagAbstractFileAction.getInstance());
actions.add(AddContentToHashDbAction.getInstance());
return actions;
}
@ -111,7 +110,6 @@ public class ExplorerNodeActionVisitor extends ContentVisitor.Default<List<? ext
List<Action> actions = new ArrayList<>();
actions.add(ExtractAction.getInstance());
actions.add(TagAbstractFileAction.getInstance());
actions.add(AddContentToHashDbAction.getInstance());
return actions;
}
@ -120,7 +118,6 @@ public class ExplorerNodeActionVisitor extends ContentVisitor.Default<List<? ext
List<Action> actions = new ArrayList<>();
actions.add(ExtractAction.getInstance());
actions.add(TagAbstractFileAction.getInstance());
actions.add(AddContentToHashDbAction.getInstance());
return actions;
}
@ -129,7 +126,6 @@ public class ExplorerNodeActionVisitor extends ContentVisitor.Default<List<? ext
List<Action> actions = new ArrayList<>();
actions.add(ExtractAction.getInstance());
actions.add(TagAbstractFileAction.getInstance());
actions.add(AddContentToHashDbAction.getInstance());
return actions;
}
@ -138,7 +134,6 @@ public class ExplorerNodeActionVisitor extends ContentVisitor.Default<List<? ext
List<Action> actions = new ArrayList<>();
actions.add(ExtractAction.getInstance());
actions.add(TagAbstractFileAction.getInstance());
actions.add(AddContentToHashDbAction.getInstance());
return actions;
}

View File

@ -16,25 +16,29 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.sleuthkit.autopsy.directorytree;
package org.sleuthkit.autopsy.hashdatabase;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Collection;
import java.util.logging.Level;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import org.openide.util.Utilities;
import org.openide.util.Lookup;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.openide.util.actions.Presenter;
import org.sleuthkit.autopsy.ingest.IngestConfigurator;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.datamodel.AbstractFile;
import org.sleuthkit.datamodel.TskCoreException;
/**
* Instances of this Action allow users to content to a hash database.
*/
public class AddContentToHashDbAction extends AbstractAction {
public class AddContentToHashDbAction extends AbstractAction implements Presenter.Popup {
// This class is a singleton to support multi-selection of nodes, since
// org.openide.nodes.NodeOp.findActions(Node[] nodes) will only pick up an Action if every
// node in the array returns a reference to the same action object from Node.getActions(boolean).
@ -81,16 +85,33 @@ public class AddContentToHashDbAction extends AbstractAction {
super(SINGLE_SELECTION_NAME);
}
@Override
public JMenuItem getPopupPresenter() {
return new AddContentToHashDbMenu();
}
@Override
public void actionPerformed(ActionEvent event) {
}
private class AddContentToHashDbMenu extends JMenu {
AddContentToHashDbMenu() {
// RJCTODO: Need super call?
// Get the current set of updateable hash databases and add each
// one as a menu item.
for (final HashDb database : HashDbXML.getCurrent().getKnownBadSets()) {
if (database.isUpdateable()) {
JMenuItem databaseItem = add(database.getName());
databaseItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Collection<? extends AbstractFile> selectedFiles = Utilities.actionsGlobalContext().lookupAll(AbstractFile.class);
for (AbstractFile file : selectedFiles) {
try {
// RJCTODO: Complete this method.
String md5Hash = file.getMd5Hash();
if (null != md5Hash) {
throw new TskCoreException("RJCTODO");
}
try {
database.addContentHash(file);
}
catch (TskCoreException ex) {
Logger.getLogger(AddContentToHashDbAction.class.getName()).log(Level.SEVERE, "Error tagging result", ex);
@ -99,3 +120,9 @@ public class AddContentToHashDbAction extends AbstractAction {
}
}
}
});
}
}
}
}
}

View File

@ -32,7 +32,6 @@ import javax.xml.parsers.ParserConfigurationException;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.coreutils.PlatformUtil;
import org.sleuthkit.autopsy.coreutils.XMLUtil;
import org.sleuthkit.autopsy.directorytree.AddContentToHashDbAction;
import org.sleuthkit.autopsy.hashdatabase.HashDb.DBType;
import org.sleuthkit.datamodel.SleuthkitJNI;
import org.sleuthkit.datamodel.TskCoreException;

View File

@ -33,7 +33,7 @@ import org.sleuthkit.autopsy.directorytree.ExtractAction;
import org.sleuthkit.autopsy.directorytree.TagAbstractFileAction;
import org.sleuthkit.autopsy.directorytree.HashSearchAction;
import org.sleuthkit.autopsy.directorytree.NewWindowViewAction;
import org.sleuthkit.autopsy.directorytree.AddContentToHashDbAction;
import org.sleuthkit.autopsy.hashdatabase.AddContentToHashDbAction;
import org.sleuthkit.datamodel.Content;
import org.sleuthkit.datamodel.ContentVisitor;
import org.sleuthkit.datamodel.DerivedFile;