Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

METRON-1691: REST should limit the number of Pcap jobs a user can submit #1129

Expand Up @@ -22,6 +22,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class Field {

Expand Down Expand Up @@ -132,33 +133,22 @@ public void setProtos(List<Proto> protos) {
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Field field = (Field) o;

return (getName() != null ? getName().equals(field.getName()) : field.getName() != null) &&
(getPos() != null ? getPos().equals(field.getPos()) : field.getPos() == null) &&
(getShowname() != null ? getShowname().equals(field.getShowname()) : field.getShowname() == null) &&
(getSize() != null ? getSize().equals(field.getSize()) : field.getSize() == null) &&
(getValue() != null ? getValue().equals(field.getValue()) : field.getValue() == null) &&
(getShow() != null ? getShow().equals(field.getShow()) : field.getShow() == null) &&
(getUnmaskedvalue() != null ? getUnmaskedvalue().equals(field.getUnmaskedvalue()) : field.getUnmaskedvalue() == null) &&
(getHide() != null ? getHide().equals(field.getHide()) : field.getHide() == null) &&
(getFields() != null ? getFields().equals(field.getFields()) : field.getFields() == null) &&
(getProtos() != null ? getProtos().equals(field.getProtos()) : field.getProtos() == null);
return Objects.equals(name, field.name) &&
Objects.equals(pos, field.pos) &&
Objects.equals(showname, field.showname) &&
Objects.equals(size, field.size) &&
Objects.equals(value, field.value) &&
Objects.equals(show, field.show) &&
Objects.equals(unmaskedvalue, field.unmaskedvalue) &&
Objects.equals(hide, field.hide) &&
Objects.equals(fields, field.fields) &&
Objects.equals(protos, field.protos);
}

@Override
public int hashCode() {
int result = getName() != null ? getName().hashCode() : 0;
result = 31 * result + (getPos() != null ? getPos().hashCode() : 0);
result = 31 * result + (getShowname() != null ? getShowname().hashCode() : 0);
result = 31 * result + (getSize() != null ? getSize().hashCode() : 0);
result = 31 * result + (getValue() != null ? getValue().hashCode() : 0);
result = 31 * result + (getShow() != null ? getShow().hashCode() : 0);
result = 31 * result + (getUnmaskedvalue() != null ? getUnmaskedvalue().hashCode() : 0);
result = 31 * result + (getHide() != null ? getHide().hashCode() : 0);
result = 31 * result + (getFields() != null ? getFields().hashCode() : 0);
result = 31 * result + (getProtos() != null ? getProtos().hashCode() : 0);
return result;

return Objects.hash(name, pos, showname, size, value, show, unmaskedvalue, hide, fields, protos);
}
}
Expand Up @@ -113,34 +113,4 @@ public void setFields() {
}
PcapOptions.FIELDS.put(this, fields);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

FixedPcapRequest fixedPcapRequest = (FixedPcapRequest) o;

return (super.equals(o)) &&
(getIpSrcAddr() != null ? getIpSrcAddr().equals(fixedPcapRequest.getIpSrcAddr()) : fixedPcapRequest.getIpSrcAddr() != null) &&
(getIpDstAddr() != null ? getIpDstAddr().equals(fixedPcapRequest.getIpDstAddr()) : fixedPcapRequest.getIpDstAddr() != null) &&
(getIpSrcPort() != null ? getIpSrcPort().equals(fixedPcapRequest.getIpSrcPort()) : fixedPcapRequest.getIpSrcPort() != null) &&
(getIpDstPort() != null ? getIpDstPort().equals(fixedPcapRequest.getIpDstPort()) : fixedPcapRequest.getIpDstPort() != null) &&
(getProtocol() != null ? getProtocol().equals(fixedPcapRequest.getProtocol()) : fixedPcapRequest.getProtocol() != null) &&
(getPacketFilter() != null ? getPacketFilter().equals(fixedPcapRequest.getPacketFilter()) : fixedPcapRequest.getPacketFilter() != null) &&
(getIncludeReverse() != null ? getIncludeReverse().equals(fixedPcapRequest.getIncludeReverse()) : fixedPcapRequest.getIncludeReverse() != null);
}

@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (getIpSrcAddr() != null ? getIpSrcAddr().hashCode() : 0);
result = 31 * result + (getIpDstAddr() != null ? getIpDstAddr().hashCode() : 0);
result = 31 * result + (getIpSrcPort() != null ? getIpSrcPort().hashCode() : 0);
result = 31 * result + (getIpDstPort() != null ? getIpDstPort().hashCode() : 0);
result = 31 * result + (getProtocol() != null ? getProtocol().hashCode() : 0);
result = 31 * result + (getPacketFilter() != null ? getPacketFilter().hashCode() : 0);
result = 31 * result + (getIncludeReverse() != null ? getIncludeReverse().hashCode() : 0);
return result;
}
}
Expand Up @@ -21,6 +21,7 @@
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;

import java.util.List;
import java.util.Objects;

public class Packet {

Expand All @@ -40,14 +41,13 @@ public void setProtos(List<Proto> protos) {
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Packet packet = (Packet) o;

return (getProtos() != null ? getProtos().equals(packet.getProtos()) : packet.getProtos() == null);
return Objects.equals(protos, packet.protos);
}

@Override
public int hashCode() {
return getProtos() != null ? getProtos().hashCode() : 0;

return Objects.hash(protos);
}
}
Expand Up @@ -17,6 +17,8 @@
*/
package org.apache.metron.rest.model.pcap;

import java.util.Objects;

public class PcapStatus {

private String jobId;
Expand Down Expand Up @@ -69,23 +71,17 @@ public void setPageTotal(Integer size) {
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

PcapStatus pcapStatus = (PcapStatus) o;

return (getJobId() != null ? getJobId().equals(pcapStatus.getJobId()) : pcapStatus.getJobId() != null) &&
(getJobStatus() != null ? getJobStatus().equals(pcapStatus.getJobStatus()) : pcapStatus.getJobStatus() != null) &&
(getDescription() != null ? getDescription().equals(pcapStatus.getDescription()) : pcapStatus.getDescription() != null) &&
(getPercentComplete() != null ? getPercentComplete().equals(pcapStatus.getPercentComplete()) : pcapStatus.getPercentComplete() != null) &&
(getPageTotal() != null ? getPageTotal().equals(pcapStatus.getPageTotal()) : pcapStatus.getPageTotal() != null);
PcapStatus that = (PcapStatus) o;
return Objects.equals(jobId, that.jobId) &&
Objects.equals(jobStatus, that.jobStatus) &&
Objects.equals(description, that.description) &&
Objects.equals(percentComplete, that.percentComplete) &&
Objects.equals(pageTotal, that.pageTotal);
}

@Override
public int hashCode() {
int result = (getJobId() != null ? getJobId().hashCode() : 0);
result = 31 * result + (getJobStatus() != null ? getJobStatus().hashCode() : 0);
result = 31 * result + (getDescription() != null ? getDescription().hashCode() : 0);
result = 31 * result + (getPercentComplete() != null ? getPercentComplete().hashCode() : 0);
result = 31 * result + (getPageTotal() != null ? getPageTotal().hashCode() : 0);
return result;

return Objects.hash(jobId, jobStatus, description, percentComplete, pageTotal);
}
}
Expand Up @@ -22,6 +22,7 @@
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;

import java.util.List;
import java.util.Objects;

public class Pdml {

Expand Down Expand Up @@ -81,23 +82,17 @@ public void setPackets(List<Packet> packets) {
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Pdml pdml = (Pdml) o;

return (getVersion() != null ? getVersion().equals(pdml.getVersion()) : pdml.getVersion() != null) &&
(getCreator() != null ? getCreator().equals(pdml.getCreator()) : pdml.getCreator() == null) &&
(getTime() != null ? getTime().equals(pdml.getTime()) : pdml.getTime() == null) &&
(getCaptureFile() != null ? getCaptureFile().equals(pdml.getCaptureFile()) : pdml.getCaptureFile() == null) &&
(getPackets() != null ? getPackets().equals(pdml.getPackets()) : pdml.getPackets() == null);
return Objects.equals(version, pdml.version) &&
Objects.equals(creator, pdml.creator) &&
Objects.equals(time, pdml.time) &&
Objects.equals(captureFile, pdml.captureFile) &&
Objects.equals(packets, pdml.packets);
}

@Override
public int hashCode() {
int result = getVersion() != null ? getVersion().hashCode() : 0;
result = 31 * result + (getCreator() != null ? getCreator().hashCode() : 0);
result = 31 * result + (getTime() != null ? getTime().hashCode() : 0);
result = 31 * result + (getCaptureFile() != null ? getCaptureFile().hashCode() : 0);
result = 31 * result + (getPackets() != null ? getPackets().hashCode() : 0);
return result;

return Objects.hash(version, creator, time, captureFile, packets);
}
}
Expand Up @@ -21,6 +21,7 @@
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;

import java.util.List;
import java.util.Objects;

public class Proto {

Expand Down Expand Up @@ -90,25 +91,18 @@ public void setFields(List<Field> fields) {
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Proto proto = (Proto) o;

return (getName() != null ? getName().equals(proto.getName()) : proto.getName() != null) &&
(getPos() != null ? getPos().equals(proto.getPos()) : proto.getPos() == null) &&
(getShowname() != null ? getShowname().equals(proto.getShowname()) : proto.getShowname() == null) &&
(getSize() != null ? getSize().equals(proto.getSize()) : proto.getSize() == null) &&
(getHide() != null ? getHide().equals(proto.getHide()) : proto.getHide() == null) &&
(getFields() != null ? getFields().equals(proto.getFields()) : proto.getFields() == null);
return Objects.equals(name, proto.name) &&
Objects.equals(pos, proto.pos) &&
Objects.equals(showname, proto.showname) &&
Objects.equals(size, proto.size) &&
Objects.equals(hide, proto.hide) &&
Objects.equals(fields, proto.fields);
}

@Override
public int hashCode() {
int result = getName() != null ? getName().hashCode() : 0;
result = 31 * result + (getPos() != null ? getPos().hashCode() : 0);
result = 31 * result + (getShowname() != null ? getShowname().hashCode() : 0);
result = 31 * result + (getSize() != null ? getSize().hashCode() : 0);
result = 31 * result + (getHide() != null ? getHide().hashCode() : 0);
result = 31 * result + (getFields() != null ? getFields().hashCode() : 0);
return result;

return Objects.hash(name, pos, showname, size, hide, fields);
}
}
Expand Up @@ -38,22 +38,4 @@ public void setQuery(String query) {
public void setFields() {
PcapOptions.FIELDS.put(this, getQuery());
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

QueryPcapRequest queryPcapRequest = (QueryPcapRequest) o;

return (super.equals(o)) &&
(getQuery() != null ? getQuery().equals(queryPcapRequest.getQuery()) : queryPcapRequest.getQuery() != null);
}

@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (getQuery() != null ? getQuery().hashCode() : 0);
return result;
}
}
27 changes: 21 additions & 6 deletions metron-interface/metron-rest/README.md
Expand Up @@ -212,7 +212,7 @@ METRON_SPRING_PROFILES_ACTIVE="vagrant,dev"

## Pcap Query

The REST application exposes endpoints for querying Pcap data. For more information about filtering options see [Query Filter Utility](/metron-platform/metron-pcap-backend#query-filter-utility).
The REST application exposes endpoints for querying Pcap data. For more information about filtering options see [Query Filter Utility](../../metron-platform/metron-pcap-backend#query-filter-utility).

There is an endpoint available that will return Pcap data in [PDML](https://wiki.wireshark.org/PDML) format. [Wireshark](https://www.wireshark.org/) must be installed for this feature to work.
Installing wireshark in CentOS can be done with `yum -y install wireshark`.
Expand Down Expand Up @@ -253,8 +253,9 @@ Request and Response objects are JSON formatted. The JSON schemas are available
| [ `GET /api/v1/metaalert/add/alert`](#get-apiv1metaalertaddalert)|
| [ `GET /api/v1/metaalert/remove/alert`](#get-apiv1metaalertremovealert)|
| [ `GET /api/v1/metaalert/update/status/{guid}/{status}`](#get-apiv1metaalertupdatestatusguidstatus)|
| [ `GET /api/v1/pcap/fixed`](#get-apiv1pcapfixed)|
| [ `GET /api/v1/pcap/query`](#get-apiv1pcapquery)|
| [ `POST /api/v1/pcap/fixed`](#post-apiv1pcapfixed)|
| [ `POST /api/v1/pcap/query`](#post-apiv1pcapquery)|
| [ `GET /api/v1/pcap`](#get-apiv1pcap)|
| [ `GET /api/v1/pcap/{jobId}`](#get-apiv1pcapjobid)|
| [ `GET /api/v1/pcap/{jobId}/pdml`](#get-apiv1pcapjobidpdml)|
| [ `GET /api/v1/pcap/{jobId}/raw`](#get-apiv1pcapjobidraw)|
Expand Down Expand Up @@ -516,15 +517,22 @@ Request and Response objects are JSON formatted. The JSON schemas are available
* Returns:
* 200 - Returns a job status with job ID.

### `POST /api/v1/pcap/{jobId}`
### `GET /api/v1/pcap`
* Description: Gets a list of job statuses for Pcap query jobs that match the requested state.
* Input:
* state - Job state
* Returns:
* 200 - Returns a list of job statuses for jobs that match the requested state.

### `GET /api/v1/pcap/{jobId}`
* Description: Gets job status for Pcap query job.
* Input:
* jobId - Job ID of submitted job
* Returns:
* 200 - Returns a job status for the Job ID.
* 404 - Job is missing.

### `POST /api/v1/pcap/{jobId}/pdml`
### `GET /api/v1/pcap/{jobId}/pdml`
* Description: Gets Pcap Results for a page in PDML format.
* Input:
* jobId - Job ID of submitted job
Expand All @@ -533,14 +541,21 @@ Request and Response objects are JSON formatted. The JSON schemas are available
* 200 - Returns PDML in json format.
* 404 - Job or page is missing.

### `POST /api/v1/pcap/{jobId}/raw`
### `GET /api/v1/pcap/{jobId}/raw`
* Description: Download Pcap Results for a page.
* Input:
* jobId - Job ID of submitted job
* page - Page number
* Returns:
* 200 - Returns Pcap as a file download.
* 404 - Job or page is missing.

### `DELETE /api/v1/pcap/kill/{jobId}`
* Description: Kills running job.
* Input:
* jobId - Job ID of submitted job
* Returns:
* 200 - Kills passed job.

### `POST /api/v1/search/search`
* Description: Searches the indexing store. GUIDs must be quoted to ensure correct results.
Expand Down
Expand Up @@ -72,6 +72,7 @@ public class MetronRestConstants {

public static final String USER_SETTINGS_HBASE_TABLE_SPRING_PROPERTY = "user.settings.table";
public static final String USER_SETTINGS_HBASE_CF_SPRING_PROPERTY = "user.settings.cf";
public static final String USER_JOB_LIMIT_SPRING_PROPERTY = "user.job.limit";

public static final String LOGGING_SYSTEM_PROPERTY = "org.springframework.boot.logging.LoggingSystem";

Expand Down
Expand Up @@ -22,6 +22,7 @@
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.apache.commons.io.IOUtils;
import org.apache.metron.job.JobStatus;
import org.apache.metron.rest.RestException;
import org.apache.metron.rest.model.pcap.FixedPcapRequest;
import org.apache.metron.rest.model.pcap.PcapStatus;
Expand All @@ -44,6 +45,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;

@RestController
@RequestMapping("/api/v1/pcap")
Expand Down Expand Up @@ -87,6 +89,17 @@ ResponseEntity<PcapStatus> getStatus(@ApiParam(name="jobId", value="Job ID of su
}
}

@ApiOperation(value = "Gets a list of job statuses for Pcap query jobs that match the requested state.")
@ApiResponses(value = {
@ApiResponse(message = "Returns a list of job statuses for jobs that match the requested state.", code = 200)
})
@RequestMapping(method = RequestMethod.GET)
ResponseEntity<List<PcapStatus>> getStatuses(@ApiParam(name="state", value="Job state", required=true)@RequestParam String state) throws RestException {

List<PcapStatus> jobs = pcapQueryService.getJobStatus(SecurityUtils.getCurrentUser(), JobStatus.State.valueOf(state));
return new ResponseEntity<>(jobs, HttpStatus.OK);
}

@ApiOperation(value = "Gets Pcap Results for a page in PDML format.")
@ApiResponses(value = {
@ApiResponse(message = "Returns PDML in json format.", code = 200),
Expand Down