diff --git a/bindings/java/doxygen/blackboard.dox b/bindings/java/doxygen/blackboard.dox index 7c4288e91bf8495f96a96e76e466da2862542fe5..fc51e88b9699fcfbdcc4d6603340602e1f134876 100644 --- a/bindings/java/doxygen/blackboard.dox +++ b/bindings/java/doxygen/blackboard.dox @@ -36,9 +36,9 @@ Consult the \ref artifact_catalog_page "artifact catalog" for a list of built-in There are may ways to create artifacts, but we will focus on creating them through the Blackboard class or directly through a Content object. Regardless of how they are created, all artifacts must be associated with a Content object. <ul> -<li>org.sleuthkit.datamodel.AbstractContent.newDataArtifact(BlackboardArtifact.Type artifactType, Collection<BlackboardAttribute> attributesList, OsAccount osAccount) +<li>org.sleuthkit.datamodel.AbstractContent.newDataArtifact(BlackboardArtifact.Type artifactType, Collection<BlackboardAttribute> attributesList, Long osAccountId) <li>org.sleuthkit.datamodel.AbstractContent.newAnalysisResult(BlackboardArtifact.Type artifactType, Score score, String conclusion, String configuration, String justification, Collection<BlackboardAttribute> attributesList) -<li>org.sleuthkit.datamodel.Blackboard.newDataArtifact(BlackboardArtifact.Type artifactType, long sourceObjId, Long dataSourceObjId, Collection<BlackboardAttribute> attributes, OsAccount osAccount) +<li>org.sleuthkit.datamodel.Blackboard.newDataArtifact(BlackboardArtifact.Type artifactType, long sourceObjId, Long dataSourceObjId, Collection<BlackboardAttribute> attributes, Long osAccountId) <li>org.sleuthkit.datamodel.Blackboard.newAnalysisResult(BlackboardArtifact.Type artifactType, long objId, Long dataSourceObjId, Score score, String conclusion, String configuration, String justification, Collection<BlackboardAttribute> attributesList, CaseDbTransaction transaction) </ul> diff --git a/bindings/java/src/org/sleuthkit/datamodel/AbstractContent.java b/bindings/java/src/org/sleuthkit/datamodel/AbstractContent.java index c37a5463a5e17605367f89457dc3b661d714a4e4..026fa8aebb5b48e7094bd8e4219460262b1aa7ec 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/AbstractContent.java +++ b/bindings/java/src/org/sleuthkit/datamodel/AbstractContent.java @@ -18,6 +18,7 @@ */ package org.sleuthkit.datamodel; +import com.google.common.base.Optional; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -344,10 +345,12 @@ public AnalysisResultAdded newAnalysisResult(BlackboardArtifact.Type artifactTyp } @Override - public DataArtifact newDataArtifact(BlackboardArtifact.Type artifactType, Collection<BlackboardAttribute> attributesList, OsAccount osAccount) throws TskCoreException { + public DataArtifact newDataArtifact(BlackboardArtifact.Type artifactType, Collection<BlackboardAttribute> attributesList, Long osAccountId) throws TskCoreException { + // TODO + DataArtifact artifact = db.getBlackboard().newDataArtifact(artifactType, objId, this.getDataSource().getId(), attributesList, osAccountId); - DataArtifact artifact = db.getBlackboard().newDataArtifact(artifactType, objId, this.getDataSource().getId(), attributesList, osAccount); - if(osAccount != null) { + if(osAccountId != null) { + OsAccount osAccount = db.getOsAccountManager().getOsAccountByObjectId(osAccountId); db.getOsAccountManager().newOsAccountInstance(osAccount, (DataSource)getDataSource(), OsAccountInstance.OsAccountInstanceType.LAUNCHED); } return artifact; diff --git a/bindings/java/src/org/sleuthkit/datamodel/AbstractFile.java b/bindings/java/src/org/sleuthkit/datamodel/AbstractFile.java index dbeb39670e7300bf883a981e46c2fad79f0f186a..c4ffa584ecb35fea3f07991f7327042fc916b451 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/AbstractFile.java +++ b/bindings/java/src/org/sleuthkit/datamodel/AbstractFile.java @@ -1412,6 +1412,23 @@ public BlackboardArtifact newArtifact(int artifactTypeID) throws TskCoreExceptio return getSleuthkitCase().newBlackboardArtifact(artifactTypeID, getId(), dataSourceObjectId); } + /** + * Create and add a data artifact associated with this abstract file. This + * method creates the data artifact with the os account id associated with + * this abstract file if one exits. + * + * @param artifactType Type of data artifact to create. + * @param attributesList Additional attributes to attach to this data + * artifact. + * + * @return DataArtifact New data artifact. + * + * @throws TskCoreException If a critical error occurred within tsk core. + */ + public DataArtifact newDataArtifact(BlackboardArtifact.Type artifactType, Collection<BlackboardAttribute> attributesList) throws TskCoreException { + return super.newDataArtifact(artifactType, attributesList, osAccountObjId); + } + /** * Initializes common fields used by AbstactFile implementations (objects in * tsk_files table) diff --git a/bindings/java/src/org/sleuthkit/datamodel/Blackboard.java b/bindings/java/src/org/sleuthkit/datamodel/Blackboard.java index 05d76668299d0cdec80715e6a771cfbf543f7779..50b106a98cd0863e077b7fa0f9303e4619df8d89 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/Blackboard.java +++ b/bindings/java/src/org/sleuthkit/datamodel/Blackboard.java @@ -959,29 +959,24 @@ public static final class BlackboardException extends Exception { * belongs to, may be the same as the sourceObjId. * May be null. * @param attributes The attributes. May be empty or null. - * @param osAccount The OS account associated with the artifact. May - * be null. + * @param osAccountId The OS account id associated with the artifact. + * May be null. * * @return DataArtifact A new data artifact. * * @throws TskCoreException If a critical error occurs within tsk core. */ public DataArtifact newDataArtifact(BlackboardArtifact.Type artifactType, long sourceObjId, Long dataSourceObjId, - Collection<BlackboardAttribute> attributes, OsAccount osAccount) throws TskCoreException { + Collection<BlackboardAttribute> attributes, Long osAccountId) throws TskCoreException { if (artifactType.getCategory() != BlackboardArtifact.Category.DATA_ARTIFACT) { throw new TskCoreException(String.format("Artifact type (name = %s) is not of Data Artifact category. ", artifactType.getTypeName())); } - Long osAccountObjdId = null; - if (osAccount != null) { - osAccountObjdId = osAccount.getId(); - } - CaseDbTransaction transaction = caseDb.beginTransaction(); try { DataArtifact dataArtifact = newDataArtifact(artifactType, sourceObjId, dataSourceObjId, - attributes, osAccountObjdId, transaction); + attributes, osAccountId, transaction); transaction.commit(); return dataArtifact; } catch (TskCoreException ex) { diff --git a/bindings/java/src/org/sleuthkit/datamodel/BlackboardArtifact.java b/bindings/java/src/org/sleuthkit/datamodel/BlackboardArtifact.java index 6c240972f8fedf91c73ee73ab5569fc860676ada..4299b36b9ff0d47a2ecde378d5488b1dddd5b869 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/BlackboardArtifact.java +++ b/bindings/java/src/org/sleuthkit/datamodel/BlackboardArtifact.java @@ -697,7 +697,7 @@ public AnalysisResultAdded newAnalysisResult(BlackboardArtifact.Type artifactTyp } @Override - public DataArtifact newDataArtifact(BlackboardArtifact.Type artifactType, Collection<BlackboardAttribute> attributesList, OsAccount osAccount) throws TskCoreException { + public DataArtifact newDataArtifact(BlackboardArtifact.Type artifactType, Collection<BlackboardAttribute> attributesList, Long osAccountId) throws TskCoreException { throw new TskCoreException("Cannot create data artifact of an artifact. Not supported."); } diff --git a/bindings/java/src/org/sleuthkit/datamodel/Content.java b/bindings/java/src/org/sleuthkit/datamodel/Content.java index 2d27f2a7698a0aabab3c21f20ecb5915767bea52..ca10cd5711c663d41cdb162ece05525b5ca25b78 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/Content.java +++ b/bindings/java/src/org/sleuthkit/datamodel/Content.java @@ -1,15 +1,15 @@ /* * Sleuth Kit Data Model - * + * * Copyright 2011-2016 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. @@ -179,7 +179,7 @@ public interface Content extends SleuthkitVisitableItem { * Create and add an analysis result associated with this content. * * - * @param artifactType Type of analysis result artifact to create. + * @param artifactType Type of analysis result artifact to create. * @param score Score associated with this analysis. * @param conclusion Conclusion from the analysis, may be empty. * @param configuration Configuration element associated with this @@ -188,8 +188,8 @@ public interface Content extends SleuthkitVisitableItem { * @param attributesList Additional attributes to attach to this analysis * result artifact. * - * @return AnalysisResultAdded The analysis return added and the - current aggregate score of content. + * @return AnalysisResultAdded The analysis return added and the current + * aggregate score of content. * * @throws TskCoreException if critical error occurred within tsk core. */ @@ -201,24 +201,24 @@ public interface Content extends SleuthkitVisitableItem { * @param artifactType Type of analysis result artifact to create. * @param attributesList Additional attributes to attach to this data * artifact. - * @param osAccount The OS account associated with the artifact. May be - * null. + * @param osAccountId The OS account id associated with the artifact. May + * be null. * * @return DataArtifact New data artifact. * * @throws TskCoreException If a critical error occurred within tsk core. */ - public DataArtifact newDataArtifact(BlackboardArtifact.Type artifactType, Collection<BlackboardAttribute> attributesList, OsAccount osAccount) throws TskCoreException; - + public DataArtifact newDataArtifact(BlackboardArtifact.Type artifactType, Collection<BlackboardAttribute> attributesList, Long osAccountId) throws TskCoreException; + /** * Returns the final score for the content object. - * + * * @return Score. - * + * * @throws TskCoreException if critical error occurred within tsk core. */ public Score getAggregateScore() throws TskCoreException; - + /** * Get all artifacts associated with this content that have the given type * name @@ -232,16 +232,17 @@ public interface Content extends SleuthkitVisitableItem { public ArrayList<BlackboardArtifact> getArtifacts(String artifactTypeName) throws TskCoreException; /** - * Get all analysis results associated with this content, that have the given type. + * Get all analysis results associated with this content, that have the + * given type. * - * @param artifactType Type to look up. + * @param artifactType Type to look up. * * @return A list of analysis result artifacts matching the type. * * @throws TskCoreException If critical error occurred within tsk core. */ public List<AnalysisResult> getAnalysisResults(BlackboardArtifact.Type artifactType) throws TskCoreException; - + /** * Return the TSK_GEN_INFO artifact for the file so that individual * attributes can be added to it. Creates one if it does not already exist. @@ -317,7 +318,7 @@ public interface Content extends SleuthkitVisitableItem { * @throws TskCoreException If critical error occurred within tsk core. */ public List<AnalysisResult> getAllAnalysisResults() throws TskCoreException; - + /** * Get the names of all the hashsets that this content is in. * diff --git a/bindings/java/src/org/sleuthkit/datamodel/Report.java b/bindings/java/src/org/sleuthkit/datamodel/Report.java index d5894c6419ce603f07920ec40330d8111d3ee359..78eceef6c3ff152092c350a1f9d2f34aea89a70a 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/Report.java +++ b/bindings/java/src/org/sleuthkit/datamodel/Report.java @@ -256,13 +256,13 @@ public AnalysisResultAdded newAnalysisResult(BlackboardArtifact.Type artifactTyp } @Override - public DataArtifact newDataArtifact(BlackboardArtifact.Type artifactType, Collection<BlackboardAttribute> attributesList, OsAccount osAccount) throws TskCoreException { + public DataArtifact newDataArtifact(BlackboardArtifact.Type artifactType, Collection<BlackboardAttribute> attributesList, Long osAccountId) throws TskCoreException { if (artifactType.getTypeID() != BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID()) { throw new TskCoreException("Reports can only have keyword hit artifacts."); } - return db.getBlackboard().newDataArtifact(artifactType, objectId, this.getDataSource().getId(), attributesList, osAccount); + return db.getBlackboard().newDataArtifact(artifactType, objectId, this.getDataSource().getId(), attributesList, osAccountId); } @Override diff --git a/bindings/java/test/org/sleuthkit/datamodel/ArtifactTest.java b/bindings/java/test/org/sleuthkit/datamodel/ArtifactTest.java index 26c3fa00380b3f255f474781ad11a56c6d04e2cd..6b0d5174d2a06846f2de1286432d2bcbb7f89a5f 100644 --- a/bindings/java/test/org/sleuthkit/datamodel/ArtifactTest.java +++ b/bindings/java/test/org/sleuthkit/datamodel/ArtifactTest.java @@ -242,7 +242,7 @@ public void artifactTests() throws TskCoreException, Blackboard.BlackboardExcept // Test: add a new data artifact to the file - DataArtifact dataArtifact1 = abcTextFile.newDataArtifact(new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_SEARCH), Collections.emptyList(), osAccount1); + DataArtifact dataArtifact1 = abcTextFile.newDataArtifact(new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_SEARCH), Collections.emptyList(), osAccount1.getId()); OsAccountManager osAcctMgr = caseDB.getOsAccountManager(); @@ -251,14 +251,14 @@ public void artifactTests() throws TskCoreException, Blackboard.BlackboardExcept // Test: add a second data artifact to file - associate it with a different account - DataArtifact dataArtifact2 = abcTextFile.newDataArtifact(new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_CLIPBOARD_CONTENT), Collections.emptyList(), osAccount2); + DataArtifact dataArtifact2 = abcTextFile.newDataArtifact(new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_CLIPBOARD_CONTENT), Collections.emptyList(), osAccount2.getId()); assertTrue(dataArtifact2.getOsAccountObjectId().isPresent()); assertTrue(osAcctMgr.getOsAccountByObjectId(dataArtifact2.getOsAccountObjectId().get()).getAddr().orElse("").equalsIgnoreCase(ownerUid2)); // and two more - DataArtifact dataArtifact3 = abcTextFile.newDataArtifact(new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_AREA), Collections.emptyList(), osAccount2); - DataArtifact dataArtifact4 = abcTextFile.newDataArtifact(new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_AREA), Collections.emptyList(), osAccount2); + DataArtifact dataArtifact3 = abcTextFile.newDataArtifact(new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_AREA), Collections.emptyList(), osAccount2.getId()); + DataArtifact dataArtifact4 = abcTextFile.newDataArtifact(new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_AREA), Collections.emptyList(), osAccount2.getId()); // TEST: get all TSK_GPS_SEARCH data artifacts in the data source @@ -355,10 +355,10 @@ public void artifactTests() throws TskCoreException, Blackboard.BlackboardExcept // Create five data artifacts. Only three should create a row in tsk_data_artifacts. DataArtifact dataArt1 = defTextFile.newDataArtifact(dataArtType, java.util.Collections.emptyList(), null); - DataArtifact dataArt2 = defTextFile.newDataArtifact(dataArtType, java.util.Collections.emptyList(), osAccount2); + DataArtifact dataArt2 = defTextFile.newDataArtifact(dataArtType, java.util.Collections.emptyList(), osAccount2.getId()); BlackboardArtifact bbArt1 = defTextFile.newArtifact(dataArtType.getTypeID()); - DataArtifact dataArt3 = defTextFile.newDataArtifact(dataArtType, java.util.Collections.emptyList(), osAccount2); - DataArtifact dataArt4 = caseDB.getBlackboard().newDataArtifact(dataArtType, defTextFile.getId(), fs.getDataSource().getId(), java.util.Collections.emptyList(), osAccount2); + DataArtifact dataArt3 = defTextFile.newDataArtifact(dataArtType, java.util.Collections.emptyList(), osAccount2.getId()); + DataArtifact dataArt4 = caseDB.getBlackboard().newDataArtifact(dataArtType, defTextFile.getId(), fs.getDataSource().getId(), java.util.Collections.emptyList(), osAccount2.getId()); int dataArtifactCount = 5; // TEST: getDataArtifacts(artifact type id)