Skip to content

Commit

Permalink
Jackson StixInstantModule refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenOTT committed May 3, 2019
1 parent f821f83 commit 27bbb20
Show file tree
Hide file tree
Showing 23 changed files with 3 additions and 129 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ class SomeClass {
Optional<IdentitySdo> getCreatedByRef();

@NotNull
@JsonSerialize(using = StixInstantSerializer.class) @JsonDeserialize(using = StixInstantDeserializer.class)
@JsonProperty("created")
@Value.Default
@Redactable(useMask = true)
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>io.digitalstate.stix</groupId>
<artifactId>stix</artifactId>
<version>v0.8.1</version>
<version>v0.8.2</version>
<packaging>jar</packaging>

<name>STIX 2</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.digitalstate.stix.bundle.BundleableObject;
import io.digitalstate.stix.datamarkings.GranularMarkingDm;
import io.digitalstate.stix.datamarkings.MarkingDefinitionDm;
import io.digitalstate.stix.json.StixInstantDeserializer;
import io.digitalstate.stix.json.StixInstantSerializer;
import io.digitalstate.stix.json.StixParsers;
import io.digitalstate.stix.json.converters.dehydrated.DomainObjectOptionalConverter;
import io.digitalstate.stix.json.converters.dehydrated.MarkingDefinitionSetConverter;
Expand Down Expand Up @@ -71,7 +68,6 @@ default boolean getHydrated(){
Optional<IdentitySdo> getCreatedByRef();

@NotNull
@JsonSerialize(using = StixInstantSerializer.class) @JsonDeserialize(using = StixInstantDeserializer.class)
@JsonProperty("created")
@JsonPropertyDescription("The created property represents the time at which the first version of this object was created. The timstamp value MUST be precise to the nearest millisecond.")
@Value.Default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public interface StixModified {
@NotNull
@JsonProperty("modified")
@JsonPropertyDescription("The modified property represents the time that this particular version of the object was created. The timstamp value MUST be precise to the nearest millisecond.")
@JsonSerialize(using = StixInstantSerializer.class) @JsonDeserialize(using = StixInstantDeserializer.class)
@Value.Default
@Redactable
default StixInstant getModified(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import io.digitalstate.stix.coo.objects.FileCoo;
import io.digitalstate.stix.coo.types.WindowsPeOptionalHeaderObj;
import io.digitalstate.stix.coo.types.WindowsPeSectionObj;
import io.digitalstate.stix.json.StixOptionalInstantDeserializer;
import io.digitalstate.stix.json.StixOptionalInstantSerializer;
import io.digitalstate.stix.validation.contraints.coo.allowedparents.AllowedParents;
import io.digitalstate.stix.validation.contraints.defaulttypevalue.DefaultTypeValue;
import io.digitalstate.stix.validation.contraints.hashingvocab.HashingVocab;
Expand Down Expand Up @@ -68,7 +66,6 @@ public interface WindowsPeBinaryFileExtensionExt extends CyberObservableExtensio

@JsonProperty("time_date_stamp")
@JsonPropertyDescription("Specifies the time when the PE binary was created. The timestamp value MUST BE precise to the second.")
@JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class)
Optional<StixInstant> getTimeDateStamp();

@JsonProperty("pointer_to_symbol_table_hex")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.digitalstate.stix.common.StixInstant;
import io.digitalstate.stix.coo.CyberObservableObject;
import io.digitalstate.stix.json.StixOptionalInstantDeserializer;
import io.digitalstate.stix.json.StixOptionalInstantSerializer;
import io.digitalstate.stix.validation.contraints.defaulttypevalue.DefaultTypeValue;
import io.digitalstate.stix.validation.groups.DefaultValuesProcessor;
import org.immutables.serial.Serial;
Expand Down Expand Up @@ -46,17 +44,14 @@ public interface DirectoryCoo extends CyberObservableObject {
Optional<@Pattern(regexp = "^[a-zA-Z0-9/\\.+_:-]{2,250}$")
String> getPathEnc();

@JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class)
@JsonProperty("created")
@JsonPropertyDescription("Specifies the date/time the directory was created.")
Optional<StixInstant> getCreated();

@JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class)
@JsonProperty("modified")
@JsonPropertyDescription("Specifies the date/time the directory was last written to/modified.")
Optional<StixInstant> getModified();

@JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class)
@JsonProperty("accessed")
@JsonPropertyDescription("Specifies the date/time the directory was last accessed.")
Optional<StixInstant> getAccessed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import io.digitalstate.stix.common.StixInstant;
import io.digitalstate.stix.coo.CyberObservableObject;
import io.digitalstate.stix.coo.types.MimePartTypeObj;
import io.digitalstate.stix.json.StixOptionalInstantDeserializer;
import io.digitalstate.stix.json.StixOptionalInstantSerializer;
import io.digitalstate.stix.validation.contraints.businessrule.BusinessRule;
import io.digitalstate.stix.validation.contraints.defaulttypevalue.DefaultTypeValue;
import io.digitalstate.stix.validation.groups.DefaultValuesProcessor;
Expand Down Expand Up @@ -43,7 +41,6 @@ public interface EmailMessageCoo extends CyberObservableObject {
@NotNull
boolean isMultipart();

@JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class)
@JsonProperty("date")
@JsonPropertyDescription("Specifies the date/time that the email message was sent.")
Optional<StixInstant> getDate();
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/io/digitalstate/stix/coo/objects/FileCoo.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.digitalstate.stix.common.StixInstant;
import io.digitalstate.stix.coo.CyberObservableObject;
import io.digitalstate.stix.json.StixOptionalInstantDeserializer;
import io.digitalstate.stix.json.StixOptionalInstantSerializer;
import io.digitalstate.stix.validation.contraints.businessrule.BusinessRule;
import io.digitalstate.stix.validation.contraints.defaulttypevalue.DefaultTypeValue;
import io.digitalstate.stix.validation.contraints.hashingvocab.HashingVocab;
Expand Down Expand Up @@ -75,17 +73,14 @@ public interface FileCoo extends CyberObservableObject {

@JsonProperty("created")
@JsonPropertyDescription("Specifies the date/time the file was created.")
@JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class)
Optional<StixInstant> getCreated();

@JsonProperty("modified")
@JsonPropertyDescription("Specifies the date/time the file was last written to/modified.")
@JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class)
Optional<StixInstant> getModified();

@JsonProperty("accessed")
@JsonPropertyDescription("Specifies the date/time the file was last accessed.")
@JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class)
Optional<StixInstant> getAccessed();

@JsonProperty("parent_directory_ref")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.digitalstate.stix.common.StixInstant;
import io.digitalstate.stix.coo.CyberObservableObject;
import io.digitalstate.stix.json.StixOptionalInstantDeserializer;
import io.digitalstate.stix.json.StixOptionalInstantSerializer;
import io.digitalstate.stix.validation.contraints.defaulttypevalue.DefaultTypeValue;
import io.digitalstate.stix.validation.groups.DefaultValuesProcessor;
import org.hibernate.validator.constraints.Range;
Expand Down Expand Up @@ -42,12 +40,10 @@ public interface NetworkTrafficCoo extends CyberObservableObject {

@JsonProperty("start")
@JsonPropertyDescription("Specifies the date/time the network traffic was initiated, if known.")
@JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class)
Optional<StixInstant> getStart();

@JsonProperty("end")
@JsonPropertyDescription("Specifies the date/time the network traffic ended, if known.")
@JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class)
Optional<StixInstant> getEnd();

@JsonProperty("is_active")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.digitalstate.stix.common.StixInstant;
import io.digitalstate.stix.coo.CyberObservableObject;
import io.digitalstate.stix.json.StixOptionalInstantDeserializer;
import io.digitalstate.stix.json.StixOptionalInstantSerializer;
import io.digitalstate.stix.validation.contraints.businessrule.BusinessRule;
import io.digitalstate.stix.validation.contraints.defaulttypevalue.DefaultTypeValue;
import io.digitalstate.stix.validation.groups.DefaultValuesProcessor;
Expand Down Expand Up @@ -56,7 +54,6 @@ public interface ProcessCoo extends CyberObservableObject {

@JsonProperty("created")
@JsonPropertyDescription("Specifies the date/time at which the process was created.")
@JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class)
Optional<StixInstant> getCreated();

@JsonProperty("cwd")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.digitalstate.stix.common.StixInstant;
import io.digitalstate.stix.coo.CyberObservableObject;
import io.digitalstate.stix.json.StixOptionalInstantDeserializer;
import io.digitalstate.stix.json.StixOptionalInstantSerializer;
import io.digitalstate.stix.validation.contraints.defaulttypevalue.DefaultTypeValue;
import io.digitalstate.stix.validation.contraints.vocab.Vocab;
import io.digitalstate.stix.validation.groups.DefaultValuesProcessor;
Expand Down Expand Up @@ -78,27 +76,22 @@ public interface UserAccountCoo extends CyberObservableObject {

@JsonProperty("account_created")
@JsonPropertyDescription("Specifies when the account was created.")
@JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class)
Optional<StixInstant> getAccountCreated();

@JsonProperty("account_expires")
@JsonPropertyDescription("Specifies the expiration date of the account.")
@JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class)
Optional<StixInstant> getAccountExpires();

@JsonProperty("password_last_changed")
@JsonPropertyDescription("Specifies when the account password was last changed.")
@JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class)
Optional<StixInstant> getPasswordLastChanged();

@JsonProperty("account_first_login")
@JsonPropertyDescription("Specifies when the account was first accessed.")
@JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class)
Optional<StixInstant> getAccountFirstLogin();

@JsonProperty("account_last_login")
@JsonPropertyDescription("Specifies when the account was last accessed.")
@JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class)
Optional<StixInstant> getAccountLastLogin();

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import io.digitalstate.stix.common.StixInstant;
import io.digitalstate.stix.coo.CyberObservableObject;
import io.digitalstate.stix.coo.types.WindowsRegistryValueObj;
import io.digitalstate.stix.json.StixOptionalInstantDeserializer;
import io.digitalstate.stix.json.StixOptionalInstantSerializer;
import io.digitalstate.stix.validation.contraints.defaulttypevalue.DefaultTypeValue;
import io.digitalstate.stix.validation.groups.DefaultValuesProcessor;
import org.immutables.serial.Serial;
Expand Down Expand Up @@ -48,7 +46,6 @@ public interface WindowsRegistryKeyCoo extends CyberObservableObject {

@JsonProperty("modified")
@JsonPropertyDescription("Specifies the last date/time that the registry key was modified.")
@JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class)
Optional<StixInstant> getModified();

//@TODO Must be of type user-account
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import io.digitalstate.stix.common.StixInstant;
import io.digitalstate.stix.coo.CyberObservableObject;
import io.digitalstate.stix.coo.types.X509v3ExtensionsObj;
import io.digitalstate.stix.json.StixOptionalInstantDeserializer;
import io.digitalstate.stix.json.StixOptionalInstantSerializer;
import io.digitalstate.stix.validation.contraints.businessrule.BusinessRule;
import io.digitalstate.stix.validation.contraints.defaulttypevalue.DefaultTypeValue;
import io.digitalstate.stix.validation.contraints.hashingvocab.HashingVocab;
Expand Down Expand Up @@ -70,12 +68,10 @@ public interface X509CertificateCoo extends CyberObservableObject {

@JsonProperty("validity_not_before")
@JsonPropertyDescription("Specifies the date on which the certificate validity period begins.")
@JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class)
Optional<StixInstant> getValidityNotBefore();

@JsonProperty("validity_not_after")
@JsonPropertyDescription("Specifies the date on which the certificate validity period ends.")
@JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class)
Optional<StixInstant> getValidityNotAfter();

@JsonProperty("subject")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.digitalstate.stix.common.StixCustomProperties;
import io.digitalstate.stix.common.StixInstant;
import io.digitalstate.stix.json.StixOptionalInstantDeserializer;
import io.digitalstate.stix.json.StixOptionalInstantSerializer;
import io.digitalstate.stix.validation.GenericValidation;
import io.digitalstate.stix.validation.contraints.businessrule.BusinessRule;
import org.immutables.serial.Serial;
Expand Down Expand Up @@ -90,12 +88,10 @@ public interface X509v3ExtensionsObj extends GenericValidation, StixCustomProper

@JsonProperty("private_key_usage_period_not_before")
@JsonPropertyDescription("Specifies the date on which the validity period begins for the key, if it is different from the validity period of the certificate.")
@JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class)
Optional<StixInstant> getPrivateKeyUsagePeriodNotBefore();

@JsonProperty("private_key_usage_period_not_after")
@JsonPropertyDescription("Specifies the date on which the validity period ends for the key, if it is different from the validity period of the certificate.")
@JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class)
Optional<StixInstant> getPrivateKeyUsagePeriodNotAfter();

@JsonProperty("certificate_policies")
Expand Down

This file was deleted.

This file was deleted.

2 changes: 2 additions & 0 deletions src/main/java/io/digitalstate/stix/json/StixParsers.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import javax.validation.ValidationException;
import java.io.IOException;
import java.util.Optional;

public class StixParsers {

Expand All @@ -43,6 +44,7 @@ public static ObjectMapper generateJsonMapperBase() {
public static ObjectMapper getJsonMapper(boolean withSubTypeMappings, NamedType... additionalNamedTypes) {
//@TODO Add config to only serialize/deserialize that have @JsonProperty() annotation
if (withSubTypeMappings) {
jsonMapper.registerModule(generateStixInstantModule());
return registerBundleMapperSubTypes(jsonMapper, additionalNamedTypes);
} else {
return jsonMapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.digitalstate.stix.common.StixInstant;
import io.digitalstate.stix.json.StixOptionalInstantDeserializer;
import io.digitalstate.stix.json.StixOptionalInstantSerializer;
import io.digitalstate.stix.redaction.Redactable;
import io.digitalstate.stix.sdo.DomainObject;
import io.digitalstate.stix.validation.contraints.defaulttypevalue.DefaultTypeValue;
Expand Down Expand Up @@ -58,15 +56,13 @@ public interface CampaignSdo extends DomainObject {
@Redactable
Set<String> getAliases();

@JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class)
@JsonProperty("first_seen")
@JsonInclude(value = NON_EMPTY, content= NON_EMPTY)
@JsonPropertyDescription("The time that this Campaign was first seen.")
@Redactable
Optional<StixInstant> getFirstSeen();

//@TODO add support to ensure that Last Seen is AFTER the First Seen value
@JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class)
@JsonProperty("last_seen") @JsonInclude(value = NON_EMPTY, content= NON_EMPTY)
@JsonPropertyDescription("The time that this Campaign was last seen.")
@Redactable
Expand Down
Loading

0 comments on commit 27bbb20

Please sign in to comment.