diff --git a/openbas-api/src/main/java/io/openbas/rest/payload/form/PayloadCreateInput.java b/openbas-api/src/main/java/io/openbas/rest/payload/form/PayloadCreateInput.java index 7083cad651..943b9dc9b4 100644 --- a/openbas-api/src/main/java/io/openbas/rest/payload/form/PayloadCreateInput.java +++ b/openbas-api/src/main/java/io/openbas/rest/payload/form/PayloadCreateInput.java @@ -2,6 +2,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import io.openbas.database.model.Endpoint.PLATFORM_TYPE; +import io.openbas.database.model.Payload.PAYLOAD_SOURCE; +import io.openbas.database.model.Payload.PAYLOAD_STATUS; import io.openbas.database.model.PayloadArgument; import io.openbas.database.model.PayloadPrerequisite; import jakarta.validation.constraints.NotBlank; @@ -28,11 +30,11 @@ public class PayloadCreateInput { @NotBlank(message = MANDATORY_MESSAGE) @JsonProperty("payload_source") - private String source; + private PAYLOAD_SOURCE source; @NotBlank(message = MANDATORY_MESSAGE) @JsonProperty("payload_status") - private String status; + private PAYLOAD_STATUS status; @NotEmpty(message = MANDATORY_MESSAGE) @JsonProperty("payload_platforms") diff --git a/openbas-api/src/test/java/io/openbas/utils/fixtures/PayloadFixture.java b/openbas-api/src/test/java/io/openbas/utils/fixtures/PayloadFixture.java index 491a1c2b1a..6f09002c28 100644 --- a/openbas-api/src/test/java/io/openbas/utils/fixtures/PayloadFixture.java +++ b/openbas-api/src/test/java/io/openbas/utils/fixtures/PayloadFixture.java @@ -6,6 +6,8 @@ import static io.openbas.database.model.Command.COMMAND_TYPE; import static io.openbas.database.model.DnsResolution.DNS_RESOLUTION_TYPE; +import static io.openbas.database.model.Payload.PAYLOAD_SOURCE.MANUAL; +import static io.openbas.database.model.Payload.PAYLOAD_STATUS.VERIFIED; public class PayloadFixture { @@ -14,8 +16,8 @@ public static Payload createDefaultCommand() { command.setContent("cd .."); command.setExecutor("PowerShell"); command.setPlatforms(new Endpoint.PLATFORM_TYPE[]{Endpoint.PLATFORM_TYPE.Windows}); - command.setSource("MANUAL"); - command.setStatus("VERIFIED"); + command.setSource(MANUAL); + command.setStatus(VERIFIED); command.setAttackPatterns(Collections.emptyList()); return command; } @@ -24,8 +26,8 @@ public static Payload createDefaultDnsResolution() { DnsResolution dnsResolution = new DnsResolution("dns-resolution-id", DNS_RESOLUTION_TYPE, "dns resolution payload"); dnsResolution.setHostname("localhost"); dnsResolution.setPlatforms(new Endpoint.PLATFORM_TYPE[]{Endpoint.PLATFORM_TYPE.Linux}); - dnsResolution.setSource("MANUAL"); - dnsResolution.setStatus("VERIFIED"); + dnsResolution.setSource(MANUAL); + dnsResolution.setStatus(VERIFIED); dnsResolution.setAttackPatterns(Collections.emptyList()); return dnsResolution; } diff --git a/openbas-model/src/main/java/io/openbas/database/model/Payload.java b/openbas-model/src/main/java/io/openbas/database/model/Payload.java index 8be88b0c90..18468b5454 100644 --- a/openbas-model/src/main/java/io/openbas/database/model/Payload.java +++ b/openbas-model/src/main/java/io/openbas/database/model/Payload.java @@ -117,12 +117,14 @@ public enum PAYLOAD_STATUS { @JsonProperty("payload_external_id") private String externalId; + @Setter @Queryable(filterable = true, sortable = true) @Column(name = "payload_source") @Enumerated(EnumType.STRING) @JsonProperty("payload_source") private PAYLOAD_SOURCE source; + @Setter @Queryable(filterable = true) @Column(name = "payload_status") @Enumerated(EnumType.STRING) @@ -166,14 +168,6 @@ private String getCollectorType() { return this.collector != null ? this.collector.getType() : null; } - public void setStatus(String status) { - this.status = PAYLOAD_STATUS.valueOf(status.toUpperCase()); - } - - public void setSource(String source) { - this.source = PAYLOAD_SOURCE.valueOf(source.toUpperCase()); - } - @Override public int hashCode() { return Objects.hash(id);