diff --git a/.github/workflows/prod.yml b/.github/workflows/prod.yml index cb9c03fd61..155f56ce8d 100644 --- a/.github/workflows/prod.yml +++ b/.github/workflows/prod.yml @@ -23,6 +23,11 @@ on: type: boolean default: true description: Internal + threat_detection: + type: boolean + default: true + description: Threat Detection Client + threat_detection_backend: type: boolean default: true @@ -133,8 +138,13 @@ jobs: echo "::set-output name=image::$ECR_REGISTRY/akto-internal:$IMAGE_TAG" fi + if [[ "${{ github.event.inputs.threat_detection}}" == "true" ]]; then + cd ../threat-detection + docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/akto-threat-detection:$IMAGE_TAG . --push + fi + if [[ "${{ github.event.inputs.threat_detection_backend}}" == "true" ]]; then - cd apps/threat-detection-backend + cd ../threat-detection-backend docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/akto-threat-detection-backend:$IMAGE_TAG . --push fi - name: Configure AWS Credentials for ECR diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml index 5d9ee4f432..1ea6f0b94f 100644 --- a/.github/workflows/staging.yml +++ b/.github/workflows/staging.yml @@ -97,6 +97,8 @@ jobs: docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/akto-internal:$IMAGE_TAG . --push cd ../source-code-analyser docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/source-code-analyser:$IMAGE_TAG . --push + cd ../threat-detection + docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/akto-threat-detection:$IMAGE_TAG . --push cd ../threat-detection-backend docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/akto-threat-detection-backend:$IMAGE_TAG . --push diff --git a/Makefile b/Makefile index 0e5f9287bd..895ab09c1f 100644 --- a/Makefile +++ b/Makefile @@ -7,4 +7,4 @@ build: proto-gen mvn install -DskipTests build-clean: proto-gen - mvn clean install -DskipTests \ No newline at end of file + mvn clean install -DskipTests diff --git a/apps/api-threat-detection/Dockerfile b/apps/api-threat-detection/Dockerfile deleted file mode 100644 index 80e2dad6aa..0000000000 --- a/apps/api-threat-detection/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM openjdk -WORKDIR /app -COPY ./target/api-threat-detection-1.0-SNAPSHOT-jar-with-dependencies.jar /app/api-threat-detection-1.0-SNAPSHOT-jar-with-dependencies.jar -CMD "java" "-XX:+ExitOnOutOfMemoryError" "-jar" "/app/api-threat-detection-1.0-SNAPSHOT-jar-with-dependencies.jar" \ No newline at end of file diff --git a/apps/api-threat-detection/pom.xml b/apps/api-threat-detection/pom.xml deleted file mode 100644 index 64a129a342..0000000000 --- a/apps/api-threat-detection/pom.xml +++ /dev/null @@ -1,190 +0,0 @@ - - - 4.0.0 - - - com.akto.apps - apps - ${revision} - - - com.akto.apps.api-threat-detection - api-threat-detection - jar - - - - org.apache.commons - commons-lang3 - 3.12.0 - - - com.akto.libs.dao - dao - ${project.version} - - - com.akto.libs.utils - utils - ${project.version} - - - com.akto.apps.mini-runtime - mini-runtime - ${project.version} - - - com.akto.apps.testing - testing - ${project.version} - - - org.apache.httpcomponents - httpclient - 4.5.13 - - - org.jetbrains - annotations - RELEASE - compile - - - org.junit.jupiter - junit-jupiter-api - 5.4.2 - test - - - org.apache.kafka - kafka-clients - 3.0.0 - - - com.akto.libs.utils - utils - test-jar - ${project.version} - test - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - 8 - 8 - - - - - org.apache.maven.plugins - maven-dependency-plugin - 3.0.1 - - - copy-dependencies - package - - copy-dependencies - - - - - - - src/main/java - src/test/java - - - src/main/resources - true - - **/version.txt - - - - - - - - normal - - true - - - - - org.apache.maven.plugins - maven-assembly-plugin - - - package - - single - - - - - - com.akto.threat.detection.Main - - - - - jar-with-dependencies - - - - - - - - - - - devcontainer - - - - org.apache.maven.plugins - maven-jar-plugin - - api-threat-detection-1.0-SNAPSHOT-jar-with-dependencies - - - true - com.akto.threat.detection.Main - dependency-jars/ - - - - - - org.apache.maven.plugins - maven-dependency-plugin - - - copy-dependencies - package - - copy-dependencies - - - ${project.build.directory}/dependency-jars/ - - - - - - - - - - diff --git a/apps/api-threat-detection/src/main/java/com/akto/filters/HttpCallFilter.java b/apps/api-threat-detection/src/main/java/com/akto/filters/HttpCallFilter.java deleted file mode 100644 index ecbc8e5ac7..0000000000 --- a/apps/api-threat-detection/src/main/java/com/akto/filters/HttpCallFilter.java +++ /dev/null @@ -1,121 +0,0 @@ -package com.akto.filters; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.UUID; - -import com.akto.dao.context.Context; -import com.akto.dao.monitoring.FilterYamlTemplateDao; -import com.akto.data_actor.DataActor; -import com.akto.data_actor.DataActorFactory; -import com.akto.dto.ApiInfo.ApiInfoKey; -import com.akto.dto.HttpResponseParams; -import com.akto.dto.RawApi; -import com.akto.dto.bulk_updates.BulkUpdates; -import com.akto.dto.bulk_updates.UpdatePayload; -import com.akto.dto.monitoring.FilterConfig; -import com.akto.dto.test_editor.YamlTemplate; -import com.akto.dto.traffic.SuspectSampleData; -import com.akto.dto.type.URLMethods.Method; -import com.akto.hybrid_parsers.HttpCallParser; -import com.akto.log.LoggerMaker; -import com.akto.log.LoggerMaker.LogDb; -import com.akto.rules.TestPlugin; -import com.akto.runtime.policies.ApiAccessTypePolicy; -import com.akto.test_editor.execution.VariableResolver; -import com.akto.test_editor.filter.data_operands_impl.ValidationResult; - -public class HttpCallFilter { - private static final LoggerMaker loggerMaker = new LoggerMaker(HttpCallFilter.class, LogDb.THREAT_DETECTION); - - private Map apiFilters; - private List bulkUpdates = new ArrayList<>(); - private final int sync_threshold_count; - private final int sync_threshold_time; - private int last_synced; - private int sync_count; - private HttpCallParser httpCallParser; - - private static final int FILTER_REFRESH_INTERVAL = 10 * 60; - private int lastFilterFetch; - - private static final DataActor dataActor = DataActorFactory.fetchInstance(); - - public HttpCallFilter(int sync_threshold_count, int sync_threshold_time) { - apiFilters = new HashMap<>(); - bulkUpdates = new ArrayList<>(); - this.sync_threshold_count = sync_threshold_count; - this.sync_threshold_time = sync_threshold_time; - last_synced = 0; - sync_count = 0; - lastFilterFetch = 0; - httpCallParser = new HttpCallParser(sync_threshold_count, sync_threshold_time); - } - - public void filterFunction(List responseParams) { - - int now = Context.now(); - if ((lastFilterFetch + FILTER_REFRESH_INTERVAL) < now) { - // TODO: add support for only active templates. - List templates = dataActor.fetchFilterYamlTemplates(); - apiFilters = FilterYamlTemplateDao.instance.fetchFilterConfig(false, templates, false); - lastFilterFetch = now; - } - - if (apiFilters != null && !apiFilters.isEmpty()) { - for (HttpResponseParams responseParam : responseParams) { - for (Entry apiFilterEntry : apiFilters.entrySet()) { - try { - FilterConfig apiFilter = apiFilterEntry.getValue(); - String filterId = apiFilterEntry.getKey(); - String message = responseParam.getOrig(); - List sourceIps = ApiAccessTypePolicy.getSourceIps(responseParam); - RawApi rawApi = RawApi.buildFromMessage(message); - int apiCollectionId = httpCallParser.createApiCollectionId(responseParam); - responseParam.requestParams.setApiCollectionId(apiCollectionId); - String url = responseParam.getRequestParams().getURL(); - Method method = Method.fromString(responseParam.getRequestParams().getMethod()); - ApiInfoKey apiInfoKey = new ApiInfoKey(apiCollectionId, url, method); - Map varMap = apiFilter.resolveVarMap(); - VariableResolver.resolveWordList(varMap, new HashMap>() { - { - put(apiInfoKey, Arrays.asList(message)); - } - }, apiInfoKey); - String filterExecutionLogId = UUID.randomUUID().toString(); - ValidationResult res = TestPlugin.validateFilter(apiFilter.getFilter().getNode(), rawApi, - apiInfoKey, varMap, filterExecutionLogId); - if (res.getIsValid()) { - now = Context.now(); - SuspectSampleData sampleData = new SuspectSampleData( - sourceIps, apiCollectionId, url, method, - message, now, filterId); - Map filterMap = new HashMap<>(); - UpdatePayload updatePayload = new UpdatePayload("obj", sampleData, "set"); - ArrayList updates = new ArrayList<>(); - updates.add(updatePayload.toString()); - bulkUpdates.add(new BulkUpdates(filterMap, updates)); - } - } catch (Exception e) { - loggerMaker.errorAndAddToDb(e, String.format("Error in httpCallFilter %s", e.toString())); - } - } - } - } - sync_count = bulkUpdates.size(); - if (sync_count > 0 && (sync_count >= sync_threshold_count || - (Context.now() - last_synced) > sync_threshold_time)) { - List updates = new ArrayList<>(); - updates.addAll(bulkUpdates); - dataActor.bulkWriteSuspectSampleData(updates); - loggerMaker.infoAndAddToDb(String.format("Inserting %d records in SuspectSampleData", sync_count)); - last_synced = Context.now(); - sync_count = 0; - bulkUpdates.clear(); - } - } -} \ No newline at end of file diff --git a/apps/api-threat-detection/src/main/java/com/akto/threat/detection/Main.java b/apps/api-threat-detection/src/main/java/com/akto/threat/detection/Main.java deleted file mode 100644 index 28693a405c..0000000000 --- a/apps/api-threat-detection/src/main/java/com/akto/threat/detection/Main.java +++ /dev/null @@ -1,99 +0,0 @@ -package com.akto.threat.detection; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.commons.lang3.function.FailableFunction; -import org.apache.kafka.clients.consumer.ConsumerRecord; -import org.apache.kafka.clients.consumer.ConsumerRecords; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.akto.dao.context.Context; -import com.akto.dto.HttpResponseParams; -import com.akto.log.LoggerMaker; -import com.akto.log.LoggerMaker.LogDb; -import com.akto.metrics.AllMetrics; -import com.akto.runtime.utils.Utils; -import com.akto.traffic.KafkaRunner; -import com.akto.filters.HttpCallFilter; -import com.akto.parsers.HttpCallParser; - -public class Main { - private static final LogDb module = LogDb.THREAT_DETECTION; - private static final LoggerMaker loggerMaker = new LoggerMaker(Main.class, module); - private static final Logger logger = LoggerFactory.getLogger(Main.class); - private static final int sync_threshold_time = 120; - private static final int sync_threshold_count = 1000; - private static long lastSyncOffset = 0; - - public static void main(String[] args) { - - Map httpCallFilterMap = new HashMap<>(); - String topicName = System.getenv("AKTO_KAFKA_TOPIC_NAME"); - if (topicName == null) { - String defaultTopic = "akto.api.protection"; - loggerMaker.infoAndAddToDb(String.format("Kafka topic is not defined, using default topic : %s", defaultTopic)); - topicName = defaultTopic; - } - - FailableFunction, Void, Exception> func = records -> { - - long start = System.currentTimeMillis(); - - // TODO: what happens if exception - Map> responseParamsToAccountMap = new HashMap<>(); - for (ConsumerRecord r : records) { - HttpResponseParams httpResponseParams; - try { - Utils.printL(r.value()); - AllMetrics.instance.setRuntimeKafkaRecordCount(1); - AllMetrics.instance.setRuntimeKafkaRecordSize(r.value().length()); - lastSyncOffset++; - if (lastSyncOffset % 100 == 0) { - logger.info("Committing offset at position: " + lastSyncOffset); - } - httpResponseParams = HttpCallParser.parseKafkaMessage(r.value()); - } catch (Exception e) { - loggerMaker.errorAndAddToDb(e, "Error while parsing kafka message " + e, LogDb.RUNTIME); - continue; - } - String accountId = httpResponseParams.getAccountId(); - if (!responseParamsToAccountMap.containsKey(accountId)) { - responseParamsToAccountMap.put(accountId, new ArrayList<>()); - } - responseParamsToAccountMap.get(accountId).add(httpResponseParams); - } - - for (String accountId : responseParamsToAccountMap.keySet()) { - int accountIdInt; - try { - accountIdInt = Integer.parseInt(accountId); - } catch (Exception ignored) { - loggerMaker.errorAndAddToDb("Account id not string", LogDb.RUNTIME); - continue; - } - - Context.accountId.set(accountIdInt); - - if (!httpCallFilterMap.containsKey(accountId)) { - HttpCallFilter filter = new HttpCallFilter(sync_threshold_count, sync_threshold_time); - httpCallFilterMap.put(accountId, filter); - loggerMaker.infoAndAddToDb("New filter created for account: " + accountId); - } - - HttpCallFilter filter = httpCallFilterMap.get(accountId); - List accWiseResponse = responseParamsToAccountMap.get(accountId); - filter.filterFunction(accWiseResponse); - } - - AllMetrics.instance.setRuntimeProcessLatency(System.currentTimeMillis()-start); - - return null; - }; - KafkaRunner.processKafkaRecords(module, Arrays.asList(topicName), func); - } -} \ No newline at end of file diff --git a/apps/dashboard/src/main/java/com/akto/action/threat_detection/SuspectSampleDataAction.java b/apps/dashboard/src/main/java/com/akto/action/threat_detection/SuspectSampleDataAction.java index d7542eacad..35d8678b05 100644 --- a/apps/dashboard/src/main/java/com/akto/action/threat_detection/SuspectSampleDataAction.java +++ b/apps/dashboard/src/main/java/com/akto/action/threat_detection/SuspectSampleDataAction.java @@ -42,30 +42,47 @@ public SuspectSampleDataAction() { } public String fetchSampleData() { - HttpPost post = new HttpPost(String.format("%s/api/dashboard/list_malicious_requests", this.getBackendUrl())); + HttpPost post = new HttpPost( + String.format("%s/api/dashboard/list_malicious_requests", this.getBackendUrl())); post.addHeader("Authorization", "Bearer " + this.getApiToken()); post.addHeader("Content-Type", "application/json"); - System.out.print("API Token: " + this.getApiToken()); + Map filter = new HashMap<>(); + if (this.ips != null && !this.ips.isEmpty()) { + filter.put("ips", this.ips); + } + + if (this.urls != null && !this.urls.isEmpty()) { + filter.put("urls", this.urls); + } + + Map time_range = new HashMap<>(); + if (this.startTimestamp > 0) { + time_range.put("start", this.startTimestamp); + } + + if (this.endTimestamp > 0) { + time_range.put("end", this.endTimestamp); + } + + filter.put("detected_at_time_range", time_range); Map body = new HashMap() { { put("skip", skip); put("limit", LIMIT); + put("sort", sort); + put("filter", filter); } }; String msg = objectMapper.valueToTree(body).toString(); - System.out.println("Request body for list malicious requests" + msg); - StringEntity requestEntity = new StringEntity(msg, ContentType.APPLICATION_JSON); post.setEntity(requestEntity); try (CloseableHttpResponse resp = this.httpClient.execute(post)) { String responseBody = EntityUtils.toString(resp.getEntity()); - System.out.println(responseBody); - ProtoMessageUtils.toProtoMessage( ListMaliciousRequestsResponse.class, responseBody) .ifPresent( @@ -83,6 +100,7 @@ public String fetchSampleData() { smr.getCountry(), smr.getDetectedAt())) .collect(Collectors.toList()); + this.total = m.getTotal(); }); } catch (Exception e) { e.printStackTrace(); @@ -100,8 +118,6 @@ public String fetchFilters() { try (CloseableHttpResponse resp = this.httpClient.execute(get)) { String responseBody = EntityUtils.toString(resp.getEntity()); - System.out.println(responseBody); - ProtoMessageUtils.toProtoMessage( FetchAlertFiltersResponse.class, responseBody) .ifPresent( diff --git a/apps/dashboard/src/main/java/com/akto/action/threat_detection/ThreatActorAction.java b/apps/dashboard/src/main/java/com/akto/action/threat_detection/ThreatActorAction.java index fbfe0a34ca..6cdc6055a6 100644 --- a/apps/dashboard/src/main/java/com/akto/action/threat_detection/ThreatActorAction.java +++ b/apps/dashboard/src/main/java/com/akto/action/threat_detection/ThreatActorAction.java @@ -38,22 +38,23 @@ public ThreatActorAction() { } public String getActorsCountPerCounty() { - HttpGet get = new HttpGet(String.format("%s/api/dashboard/get_actors_count_per_country", this.getBackendUrl())); + HttpGet get = + new HttpGet( + String.format("%s/api/dashboard/get_actors_count_per_country", this.getBackendUrl())); get.addHeader("Authorization", "Bearer " + this.getApiToken()); get.addHeader("Content-Type", "application/json"); try (CloseableHttpResponse resp = this.httpClient.execute(get)) { String responseBody = EntityUtils.toString(resp.getEntity()); - System.out.println(responseBody); - ProtoMessageUtils.toProtoMessage( - ThreatActorByCountryResponse.class, responseBody) + ThreatActorByCountryResponse.class, responseBody) .ifPresent( m -> { - this.actorsCountPerCountry = m.getCountriesList().stream() - .map(smr -> new ThreatActorPerCountry(smr.getCode(), smr.getCount())) - .collect(Collectors.toList()); + this.actorsCountPerCountry = + m.getCountriesList().stream() + .map(smr -> new ThreatActorPerCountry(smr.getCode(), smr.getCount())) + .collect(Collectors.toList()); }); } catch (Exception e) { e.printStackTrace(); @@ -64,42 +65,45 @@ public String getActorsCountPerCounty() { } public String fetchThreatActors() { - HttpPost post = new HttpPost(String.format("%s/api/dashboard/list_threat_actors", this.getBackendUrl())); + HttpPost post = + new HttpPost(String.format("%s/api/dashboard/list_threat_actors", this.getBackendUrl())); post.addHeader("Authorization", "Bearer " + this.getApiToken()); post.addHeader("Content-Type", "application/json"); - Map body = new HashMap() { - { - put("skip", skip); - put("limit", LIMIT); - } - }; + Map body = + new HashMap() { + { + put("skip", skip); + put("limit", LIMIT); + put("sort", sort); + } + }; String msg = objectMapper.valueToTree(body).toString(); - System.out.println("Request body for list threat actors" + msg); - StringEntity requestEntity = new StringEntity(msg, ContentType.APPLICATION_JSON); post.setEntity(requestEntity); try (CloseableHttpResponse resp = this.httpClient.execute(post)) { String responseBody = EntityUtils.toString(resp.getEntity()); - System.out.println(responseBody); - ProtoMessageUtils.toProtoMessage( - ListThreatActorResponse.class, responseBody) + ListThreatActorResponse.class, responseBody) .ifPresent( m -> { - this.actors = m.getActorsList().stream() - .map( - smr -> new DashboardThreatActor( - smr.getId(), - smr.getLatestApiEndpoint(), - smr.getLatestApiIp(), - URLMethods.Method.fromString(smr.getLatestApiMethod()), - smr.getDiscoveredAt(), - smr.getCountry())) - .collect(Collectors.toList()); + this.actors = + m.getActorsList().stream() + .map( + smr -> + new DashboardThreatActor( + smr.getId(), + smr.getLatestApiEndpoint(), + smr.getLatestApiIp(), + URLMethods.Method.fromString(smr.getLatestApiMethod()), + smr.getDiscoveredAt(), + smr.getCountry())) + .collect(Collectors.toList()); + + this.total = m.getTotal(); }); } catch (Exception e) { e.printStackTrace(); diff --git a/apps/dashboard/src/main/java/com/akto/action/threat_detection/ThreatApiAction.java b/apps/dashboard/src/main/java/com/akto/action/threat_detection/ThreatApiAction.java index 82f5695ad3..046cb37e0f 100644 --- a/apps/dashboard/src/main/java/com/akto/action/threat_detection/ThreatApiAction.java +++ b/apps/dashboard/src/main/java/com/akto/action/threat_detection/ThreatApiAction.java @@ -38,24 +38,26 @@ public ThreatApiAction() { } public String fetchThreatCategoryCount() { - HttpGet get = new HttpGet(String.format("%s/api/dashboard/get_subcategory_wise_count", this.getBackendUrl())); + HttpGet get = + new HttpGet( + String.format("%s/api/dashboard/get_subcategory_wise_count", this.getBackendUrl())); get.addHeader("Authorization", "Bearer " + this.getApiToken()); get.addHeader("Content-Type", "application/json"); try (CloseableHttpResponse resp = this.httpClient.execute(get)) { String responseBody = EntityUtils.toString(resp.getEntity()); - System.out.println(responseBody); - ProtoMessageUtils.toProtoMessage( - ThreatCategoryWiseCountResponse.class, responseBody) + ThreatCategoryWiseCountResponse.class, responseBody) .ifPresent( m -> { - this.categoryCounts = m.getCategoryWiseCountsList().stream() - .map( - smr -> new ThreatCategoryCount( - smr.getCategory(), smr.getSubCategory(), smr.getCount())) - .collect(Collectors.toList()); + this.categoryCounts = + m.getCategoryWiseCountsList().stream() + .map( + smr -> + new ThreatCategoryCount( + smr.getCategory(), smr.getSubCategory(), smr.getCount())) + .collect(Collectors.toList()); }); } catch (Exception e) { e.printStackTrace(); @@ -66,41 +68,44 @@ public String fetchThreatCategoryCount() { } public String fetchThreatApis() { - HttpPost post = new HttpPost(String.format("%s/api/dashboard/list_threat_apis", this.getBackendUrl())); + HttpPost post = + new HttpPost(String.format("%s/api/dashboard/list_threat_apis", this.getBackendUrl())); post.addHeader("Authorization", "Bearer " + this.getApiToken()); post.addHeader("Content-Type", "application/json"); - Map body = new HashMap() { - { - put("skip", skip); - put("limit", LIMIT); - } - }; + Map body = + new HashMap() { + { + put("skip", skip); + put("limit", LIMIT); + put("sort", sort); + } + }; String msg = objectMapper.valueToTree(body).toString(); - System.out.println("Request body for list threat actors" + msg); - StringEntity requestEntity = new StringEntity(msg, ContentType.APPLICATION_JSON); post.setEntity(requestEntity); try (CloseableHttpResponse resp = this.httpClient.execute(post)) { String responseBody = EntityUtils.toString(resp.getEntity()); - System.out.println(responseBody); - ProtoMessageUtils.toProtoMessage( - ListThreatApiResponse.class, responseBody) + ListThreatApiResponse.class, responseBody) .ifPresent( m -> { - this.apis = m.getApisList().stream() - .map( - smr -> new DashboardThreatApi( - smr.getEndpoint(), - URLMethods.Method.fromString(smr.getMethod()), - smr.getActorsCount(), - smr.getRequestsCount(), - smr.getDiscoveredAt())) - .collect(Collectors.toList()); + this.apis = + m.getApisList().stream() + .map( + smr -> + new DashboardThreatApi( + smr.getEndpoint(), + URLMethods.Method.fromString(smr.getMethod()), + smr.getActorsCount(), + smr.getRequestsCount(), + smr.getDiscoveredAt())) + .collect(Collectors.toList()); + + this.total = m.getTotal(); }); } catch (Exception e) { e.printStackTrace(); diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/components/layouts/leftnav/LeftNav.js b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/components/layouts/leftnav/LeftNav.js index 1e17e6f3ec..d7dcadd158 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/components/layouts/leftnav/LeftNav.js +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/components/layouts/leftnav/LeftNav.js @@ -1,194 +1,288 @@ -import {Navigation, Text} from "@shopify/polaris" -import {SettingsFilledMinor,AppsFilledMajor, InventoryFilledMajor, MarketingFilledMinor, FileFilledMinor, AnalyticsFilledMinor, ReportFilledMinor, DiamondAlertMinor} from "@shopify/polaris-icons" -import {useLocation, useNavigate} from "react-router-dom" +import {Navigation, Text} from "@shopify/polaris"; +import { + SettingsFilledMinor, + AppsFilledMajor, + InventoryFilledMajor, + MarketingFilledMinor, + FileFilledMinor, + AnalyticsFilledMinor, + ReportFilledMinor, + DiamondAlertMinor, +} from "@shopify/polaris-icons"; +import {useLocation, useNavigate} from "react-router-dom"; -import './LeftNav.css' -import PersistStore from "../../../../main/PersistStore" -import { useState } from "react" -import func from "@/util/func" +import "./LeftNav.css"; +import PersistStore from "../../../../main/PersistStore"; +import {useState} from "react"; +import func from "@/util/func"; +export default function LeftNav() { + const navigate = useNavigate(); + const location = useLocation(); + const currPathString = func.transformString(location.pathname); -export default function LeftNav(){ + const [leftNavSelected, setLeftNavSelected] = useState(currPathString); - const navigate = useNavigate(); - const location = useLocation(); - const currPathString = func.transformString(location.pathname) - - const[leftNavSelected, setLeftNavSelected] = useState(currPathString) + const active = PersistStore((state) => state.active); + const setActive = PersistStore((state) => state.setActive); - const active = PersistStore((state) => state.active) - const setActive = PersistStore((state) => state.setActive) + const handleSelect = (selectedId) => { + setLeftNavSelected(selectedId); + }; - const handleSelect = (selectedId) => { - setLeftNavSelected(selectedId); - }; - const navigationMarkup = ( -
- - Quick Start, - icon: AppsFilledMajor, - onClick: ()=>{ - handleSelect("dashboard_quick_start") - setActive("normal") - navigate("/dashboard/quick-start") - }, - selected: leftNavSelected === 'dashboard_quick_start', - key: '1', - }, - { - label: 'API Security Posture', - icon: ReportFilledMinor, - onClick: ()=>{ - handleSelect("dashboard_home") - navigate("/dashboard/home") - setActive("normal") - }, - selected: leftNavSelected === 'dashboard_home', - key: '2', - }, - { - url: '#', - label: API Discovery, - icon: InventoryFilledMajor, - onClick: ()=>{ - handleSelect("dashboard_observe_inventory") - navigate('/dashboard/observe/inventory') - setActive("normal") - }, - selected: leftNavSelected.includes('_observe'), - subNavigationItems:[ - { - label: 'API Collections', - onClick: ()=>{ - navigate('/dashboard/observe/inventory') - handleSelect("dashboard_observe_inventory") - setActive('active') - }, - selected: leftNavSelected === "dashboard_observe_inventory" - }, - { - label: 'API Changes', - onClick: ()=>{ - navigate('/dashboard/observe/changes') - handleSelect("dashboard_observe_changes") - setActive('active') - }, - selected: leftNavSelected === "dashboard_observe_changes" - }, - { - label: 'Sensitive Data', - onClick: ()=>{ - navigate('/dashboard/observe/sensitive') - handleSelect("dashboard_observe_sensitive") - setActive('active') - }, - selected: leftNavSelected === "dashboard_observe_sensitive" - } - ], - key: '3', - }, - { - url: '#', - label: Testing, - icon: MarketingFilledMinor, - onClick: ()=>{ - navigate('/dashboard/testing/') - handleSelect('dashboard_testing') - setActive("normal") - }, - selected: leftNavSelected.includes('_testing'), - subNavigationItems:[ - { - label: 'Results', - onClick: ()=>{ - navigate('/dashboard/testing/') - handleSelect('dashboard_testing') - setActive('active') - }, - selected: leftNavSelected === 'dashboard_testing' - }, - { - label: 'Test Roles', - onClick: ()=>{ - navigate('/dashboard/testing/roles') - handleSelect('dashboard_testing_roles') - setActive('active') - }, - selected: leftNavSelected === 'dashboard_testing_roles' - }, - { - label: 'User Config', - onClick: ()=>{ - navigate('/dashboard/testing/user-config') - handleSelect('dashboard_testing_user_config') - setActive('active') - }, - selected: leftNavSelected === 'dashboard_testing_user_config' - } - ], - key: '4', - }, - { - label: Test Editor, - icon: FileFilledMinor, - onClick: ()=>{ - handleSelect("dashboard_test_editor") - navigate("/dashboard/test-editor/REMOVE_TOKENS") - setActive("normal") - }, - selected: leftNavSelected.includes("dashboard_test_editor"), - key: '5', - }, - { - label: Issues, - icon: AnalyticsFilledMinor, - onClick: ()=>{ - handleSelect("dashboard_issues") - navigate("/dashboard/issues") - setActive("normal") - }, - selected: leftNavSelected === 'dashboard_issues', - key: '6', - }, - window?.STIGG_FEATURE_WISE_ALLOWED?.THREAT_DETECTION?.isGranted ? - { - label: API Runtime Threats, - icon: DiamondAlertMinor, - onClick: () => { - handleSelect("dashboard_threat_detection") - navigate("/dashboard/threat-detection") - setActive("normal") - }, - selected: leftNavSelected === 'dashboard_threat_detection', - key: '7', - } : {} - ]} - /> - Settings, - icon: SettingsFilledMinor, - onClick: ()=>{ - navigate("/dashboard/settings/about") - setActive("normal") - }, - selected: currPathString === 'settings', - key: '7', - } - ]} - /> - +
+ + + Quick Start + + ), + icon: AppsFilledMajor, + onClick: () => { + handleSelect("dashboard_quick_start"); + setActive("normal"); + navigate("/dashboard/quick-start"); + }, + selected: leftNavSelected === "dashboard_quick_start", + key: "1", + }, + { + label: "API Security Posture", + icon: ReportFilledMinor, + onClick: () => { + handleSelect("dashboard_home"); + navigate("/dashboard/home"); + setActive("normal"); + }, + selected: leftNavSelected === "dashboard_home", + key: "2", + }, + { + url: "#", + label: ( + + API Discovery + + ), + icon: InventoryFilledMajor, + onClick: () => { + handleSelect("dashboard_observe_inventory"); + navigate("/dashboard/observe/inventory"); + setActive("normal"); + }, + selected: leftNavSelected.includes("_observe"), + subNavigationItems: [ + { + label: "API Collections", + onClick: () => { + navigate("/dashboard/observe/inventory"); + handleSelect("dashboard_observe_inventory"); + setActive("active"); + }, + selected: leftNavSelected === "dashboard_observe_inventory", + }, + { + label: "API Changes", + onClick: () => { + navigate("/dashboard/observe/changes"); + handleSelect("dashboard_observe_changes"); + setActive("active"); + }, + selected: leftNavSelected === "dashboard_observe_changes", + }, + { + label: "Sensitive Data", + onClick: () => { + navigate("/dashboard/observe/sensitive"); + handleSelect("dashboard_observe_sensitive"); + setActive("active"); + }, + selected: leftNavSelected === "dashboard_observe_sensitive", + }, + ], + key: "3", + }, + { + url: "#", + label: ( + + Testing + + ), + icon: MarketingFilledMinor, + onClick: () => { + navigate("/dashboard/testing/"); + handleSelect("dashboard_testing"); + setActive("normal"); + }, + selected: leftNavSelected.includes("_testing"), + subNavigationItems: [ + { + label: "Results", + onClick: () => { + navigate("/dashboard/testing/"); + handleSelect("dashboard_testing"); + setActive("active"); + }, + selected: leftNavSelected === "dashboard_testing", + }, + { + label: "Test Roles", + onClick: () => { + navigate("/dashboard/testing/roles"); + handleSelect("dashboard_testing_roles"); + setActive("active"); + }, + selected: leftNavSelected === "dashboard_testing_roles", + }, + { + label: "User Config", + onClick: () => { + navigate("/dashboard/testing/user-config"); + handleSelect("dashboard_testing_user_config"); + setActive("active"); + }, + selected: leftNavSelected === "dashboard_testing_user_config", + }, + ], + key: "4", + }, + { + label: ( + + Test Editor + + ), + icon: FileFilledMinor, + onClick: () => { + handleSelect("dashboard_test_editor"); + navigate("/dashboard/test-editor/REMOVE_TOKENS"); + setActive("normal"); + }, + selected: leftNavSelected.includes("dashboard_test_editor"), + key: "5", + }, + { + label: ( + + Issues + + ), + icon: AnalyticsFilledMinor, + onClick: () => { + handleSelect("dashboard_issues"); + navigate("/dashboard/issues"); + setActive("normal"); + }, + selected: leftNavSelected === "dashboard_issues", + key: "6", + }, + window?.STIGG_FEATURE_WISE_ALLOWED?.THREAT_DETECTION?.isGranted + ? { + label: ( + + API Protection + + ), + icon: DiamondAlertMinor, + onClick: () => { + handleSelect("dashboard_threat_activity"); + navigate("/dashboard/protection/threat-activity"); + setActive("normal"); + }, + selected: leftNavSelected.includes("_threat"), + url: "#", + key: "7", + subNavigationItems: [ + { + label: "Threat Activity", + onClick: () => { + navigate("/dashboard/protection/threat-activity"); + handleSelect("dashboard_threat_activity"); + setActive("active"); + }, + selected: + leftNavSelected === "dashboard_threat_activity", + }, + { + label: "Threat Actors", + onClick: () => { + navigate("/dashboard/protection/threat-actor"); + handleSelect("dashboard_threat_actor"); + setActive("active"); + }, + selected: leftNavSelected === "dashboard_threat_actor", + }, + { + label: "APIs Under Threat", + onClick: () => { + navigate("/dashboard/protection/threat-api"); + handleSelect("dashboard_threat_api"); + setActive("active"); + }, + selected: + leftNavSelected === "dashboard_threat_api", + }, + { + label: "Threat Policy", + onClick: () => { + navigate("/dashboard/protection/threat-policy"); + handleSelect("dashboard_threat_policy"); + setActive("active"); + }, + selected: + leftNavSelected === "dashboard_threat_policy", + }, + ], + } + : {}, + ]} + /> + + Settings + + ), + icon: SettingsFilledMinor, + onClick: () => { + navigate("/dashboard/settings/about"); + setActive("normal"); + }, + selected: currPathString === "settings", + key: "7", + }, + ]} + /> +
- ); + ); - return( - navigationMarkup - ) + return navigationMarkup; } - - diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/GetPrettifyEndpoint.jsx b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/GetPrettifyEndpoint.jsx index 28d627aa74..f52f0574cd 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/GetPrettifyEndpoint.jsx +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/GetPrettifyEndpoint.jsx @@ -5,38 +5,80 @@ import transform from '../onboarding/transform' import observeFunc from "./transform" function GetPrettifyEndpoint({method,url, isNew, maxWidth}){ const ref = useRef(null) + const localUrl = url || "/" const [copyActive, setCopyActive] = useState(false) - return( -
setCopyActive(true)} onMouseLeave={() => setCopyActive(false)}> - - - {method} - - - -
-
- - {observeFunc.getTruncatedUrl(url)} - - {copyActive ? -
{e.stopPropagation();func.copyToClipboard(method + " " + url, ref, "URL copied");}}> - - - - - - -
- :null} -
- - {isNew ? New : null} - + return ( +
setCopyActive(true)} + onMouseLeave={() => setCopyActive(false)} + > + + + + {method} + + + + +
+
+ + + {observeFunc.getTruncatedUrl(localUrl)} + + + {copyActive ? ( +
{ + e.stopPropagation(); + func.copyToClipboard( + method + " " + localUrl, + ref, + "URL copied" + ); + }} + > + + + + + +
- -
- ) + ) : null} +
+ {isNew ? New : null} +
+ +
+ ); } diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/threat_detection/ThreatDetectionPage.jsx b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/threat_detection/ThreatDetectionPage.jsx index d762e307e7..d33f9594a7 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/threat_detection/ThreatDetectionPage.jsx +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/threat_detection/ThreatDetectionPage.jsx @@ -33,19 +33,15 @@ function ThreatDetectionPage() { const components = [ - horizontalComponent, , - ] return } diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/threat_detection/ThreatPolicyPage.jsx b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/threat_detection/ThreatPolicyPage.jsx new file mode 100644 index 0000000000..0b9db6ddd1 --- /dev/null +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/threat_detection/ThreatPolicyPage.jsx @@ -0,0 +1,45 @@ +import {useReducer, useState} from "react"; +import DateRangeFilter from "../../components/layouts/DateRangeFilter"; +import PageWithMultipleCards from "../../components/layouts/PageWithMultipleCards"; +import TitleWithInfo from "../../components/shared/TitleWithInfo"; +import FilterComponent from "./components/FilterComponent"; +import SusDataTable from "./components/SusDataTable"; +import values from "@/util/values"; +import {produce} from "immer" +import func from "@/util/func"; +import transform from "../observe/transform"; +import {HorizontalGrid} from "@shopify/polaris"; +import SampleDetails from "./components/SampleDetails"; + +function ThreatPolicyPage() { + + const initialVal = values.ranges[3] + const [currDateRange, dispatchCurrDateRange] = useReducer(produce((draft, action) => func.dateRangeReducer(draft, action)), initialVal); + + const horizontalComponent = + + + + const components = [ + horizontalComponent, + ] + + return + } + isFirstPage={true} + primaryAction={ dispatchCurrDateRange({ + type: "update", + period: dateObj.period, + title: dateObj.title, + alias: dateObj.alias + })}/>} + components={components} + /> +} + +export default ThreatPolicyPage; \ No newline at end of file diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/threat_detection/api.js b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/threat_detection/api.js index 61379cdc98..bdf879d7bc 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/threat_detection/api.js +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/threat_detection/api.js @@ -38,21 +38,23 @@ const threatDetectionRequests = { data: {} }) }, - fetchThreatActors(skip) { + fetchThreatActors(skip, sort) { return request({ url: '/api/fetchThreatActors', method: 'post', data: { - skip: skip + skip: skip, + sort: sort } }) }, - fetchThreatApis(skip) { + fetchThreatApis(skip, sort) { return request({ url: '/api/fetchThreatApis', method: 'post', data: { - skip: skip + skip: skip, + sort: sort } }) }, diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/threat_detection/components/SusDataTable.jsx b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/threat_detection/components/SusDataTable.jsx index 4af459eab5..8b1755786f 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/threat_detection/components/SusDataTable.jsx +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/threat_detection/components/SusDataTable.jsx @@ -46,26 +46,22 @@ const headers = [ title: "Source IP", value: "sourceIPComponent", }, - { - title: "", - type: CellType.ACTION, - }, ]; const sortOptions = [ { label: "Discovered time", - value: "discovered asc", + value: "detectedAt asc", directionLabel: "Newest", - sortKey: "discovered", - columnIndex: 3, + sortKey: "detectedAt", + columnIndex: 5, }, { label: "Discovered time", - value: "discovered desc", + value: "detectedAt desc", directionLabel: "Oldest", - sortKey: "discovered", - columnIndex: 3, + sortKey: "detectedAt", + columnIndex: 5, }, ]; @@ -118,6 +114,7 @@ function SusDataTable({ currDateRange, rowClicked }) { let ret = res?.maliciousEvents.map((x) => { return { ...x, + id: x.id, actorComp: x?.actor, endpointComp: ( @@ -152,12 +149,6 @@ function SusDataTable({ currDateRange, rowClicked }) { }); filters = [ - { - key: "apiCollectionId", - label: "Collection", - title: "Collection", - choices: apiCollectionFilterChoices, - }, { key: "sourceIps", label: "Source IP", @@ -186,24 +177,6 @@ function SusDataTable({ currDateRange, rowClicked }) { } } - const getActions = (item) => { - return [ - { - items: [ - { - content: "View in collection", - onAction: () => { - window.open( - `/dashboard/observe/inventory/${item.apiCollectionId}`, - "_blank" - ); - }, - }, - ], - }, - ]; - }; - const key = startTimestamp + endTimestamp; return ( rowClicked(data)} [For now removing on row click functionality] fetchData={fetchData} filters={filters} selectable={false} hasRowActions={true} - getActions={getActions} + getActions={() => []} hideQueryField={true} headings={headers} useNewRow={true} diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/threat_detection/components/ThreatActorsTable.jsx b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/threat_detection/components/ThreatActorsTable.jsx index a4ff602489..ff3ca78ae5 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/threat_detection/components/ThreatActorsTable.jsx +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/threat_detection/components/ThreatActorsTable.jsx @@ -35,7 +35,22 @@ const headers = [ }, ]; -const sortOptions = []; +const sortOptions = [ + { + label: "Discovered time", + value: "discoveredAt asc", + directionLabel: "Newest", + sortKey: "discoveredAt", + columnIndex: 4, + }, + { + label: "Discovered time", + value: "discoveredAt desc", + directionLabel: "Oldest", + sortKey: "discoveredAt", + columnIndex: 4, + }, +]; let filters = []; @@ -55,7 +70,7 @@ function ThreatActorTable({ data, currDateRange, rowClicked }) { async function fetchData(sortKey, sortOrder, skip) { setLoading(true); const sort = { [sortKey]: sortOrder }; - const res = await api.fetchThreatActors(skip); + const res = await api.fetchThreatActors(skip, sort); let total = res.total; let ret = res?.actors?.map((x) => { return { diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/threat_detection/components/ThreatApisTable.jsx b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/threat_detection/components/ThreatApisTable.jsx index 0e7ae16d47..04cb5eb90c 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/threat_detection/components/ThreatApisTable.jsx +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/threat_detection/components/ThreatApisTable.jsx @@ -36,7 +36,22 @@ const headers = [ }, ]; -const sortOptions = []; +const sortOptions = [ + { + label: "Discovered time", + value: "discoveredAt asc", + directionLabel: "Newest", + sortKey: "discoveredAt", + columnIndex: 4, + }, + { + label: "Discovered time", + value: "discoveredAt desc", + directionLabel: "Oldest", + sortKey: "discoveredAt", + columnIndex: 4, + }, +]; let filters = []; @@ -60,7 +75,7 @@ function ThreatApiTable({ currDateRange, rowClicked }) { async function fetchData(sortKey, sortOrder, skip) { setLoading(true); const sort = { [sortKey]: sortOrder }; - const res = await api.fetchThreatApis(skip); + const res = await api.fetchThreatApis(skip, sort); let total = res.total; let ret = res?.apis?.map((x) => { return { diff --git a/apps/dashboard/web/polaris_web/web/src/apps/main/App.js b/apps/dashboard/web/polaris_web/web/src/apps/main/App.js index 42bad35beb..c533d47eb4 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/main/App.js +++ b/apps/dashboard/web/polaris_web/web/src/apps/main/App.js @@ -4,15 +4,15 @@ import SingleTestRunPage from "../dashboard/pages/testing/SingleTestRunPage/Sing import AllSensitiveData from "../dashboard/pages/observe/AllSensitiveData/AllSensitiveData"; import ApiCollections from "../dashboard/pages/observe/api_collections/ApiCollections"; import ApiQuery from "../dashboard/pages/observe/api_collections/APIQuery"; -import ApiEndpoints from "../dashboard/pages/observe/api_collections/ApiEndpoints"; +import ApiEndpoints from "../dashboard/pages/observe/api_collections/ApiEndpoints"; import SensitiveDataExposure from "../dashboard/pages/observe/SensitiveDataExposure/SensitiveDataExposure"; import SingleRequest from "../dashboard/pages/observe/SingleRequest/SingleRequest"; import PageObserve from "../dashboard/pages/observe/PageObserve" import PageTesting from "../dashboard/pages/testing/PageTesting"; import { - createBrowserRouter, - RouterProvider, - Navigate, + createBrowserRouter, + RouterProvider, + Navigate, } from "react-router-dom"; import BurpSuite from "../dashboard/pages/settings/integrations/BurpSuite"; import Integrations from "../dashboard/pages/settings/integrations/Integrations"; @@ -49,8 +49,8 @@ import Slack from "../dashboard/pages/settings/integrations/Slack"; import ApiChanges from "../dashboard/pages/observe/api_collections/ApiChanges"; import Store from "../dashboard/store"; -import { generateSearchData } from "@/util/searchItems" -import { useEffect } from "react"; +import {generateSearchData} from "@/util/searchItems" +import {useEffect} from "react"; import CICD from "../dashboard/pages/settings/integrations/CICD"; import ErrorComponent from "../dashboard/components/shared/ErrorComponent"; import OktaIntegration from "../dashboard/pages/settings/integrations/OktaIntegration"; @@ -58,18 +58,18 @@ import AzureSso from "../dashboard/pages/settings/integrations/sso/AzureSso"; import HomeDashboard from "../dashboard/pages/dashboard/HomeDashboard"; import TestLibrary from "../dashboard/pages/settings/test_library/TestLibrary"; -import { useStiggContext } from '@stigg/react-sdk'; +import {useStiggContext} from '@stigg/react-sdk'; import DependencyTable from "../dashboard/pages/testing/DependencyTable/DependencyTable"; import TestRoleAccessMatrix from "../dashboard/pages/testing/TestRoleAccessMatrix/TestRoleAccessMatrix"; import SignupPage from "../signup/pages/SignupPage"; import PageCheckInbox from "../signup/pages/PageCheckInbox" import PageBusinessEmail from "../signup/pages/PageBusinessEmail" import TokenValidator from "./TokenValidator" -import { TableContextProvider } from "@/apps/dashboard/components/tables/TableContext"; +import {TableContextProvider} from "@/apps/dashboard/components/tables/TableContext"; import VulnerabilityReport from "../dashboard/pages/testing/vulnerability_report/VulnerabilityReport"; import ThreatDetectionPage from "../dashboard/pages/threat_detection/ThreatDetectionPage"; -import { PollingProvider } from "./PollingProvider"; +import {PollingProvider} from "./PollingProvider"; import Help from "../dashboard/pages/settings/help_and_support/Help"; import AdvancedTrafficFilters from "../dashboard/pages/settings/traffic-conditions/AdvancedTrafficFilters"; import GoogleSamlSso from "../dashboard/pages/settings/integrations/sso/GoogleSamlSso"; @@ -80,328 +80,338 @@ import TeamsWebhook from "../dashboard/pages/settings/integrations/teamsWebhooks import AuditLogs from "../dashboard/pages/settings/audit_logs/AuditLogs"; import ThreatApiPage from "../dashboard/pages/threat_detection/ThreatApiPage"; import ThreatActorPage from "../dashboard/pages/threat_detection/ThreatActorPage"; +import ThreatPolicyPage from "../dashboard/pages/threat_detection/ThreatPolicyPage"; // if you add a component in a new path, please verify the search implementation in function -> 'getSearchItemsArr' in func.js const router = createBrowserRouter([ - { - path: "/dashboard", - element: , - children: [ - { - path: "", - element: , + { + path: "/dashboard", + element: , children: [ - { - path: "home", - element: , - }, - { - path: "testing", - element: , - children:[ - ...(["", "active", "cicd", "inactive"].map((i) => { - return { - path: i, - element: - } - })), - { - path: ":hexId", - element: - }, - { - path:"roles", - element: - }, - { - path:"roles/details", - element: - }, - { - path:"roles/access-matrix", - element: - }, - { - path:"user-config", - element: - }, - { - path:"dependency", - element: - } - ] - }, - { - path: "observe", - element: , - children: [ - { - path: "sensitive", - element: - }, - { - path: "inventory", - element: - }, - { - path: "query_mode", - element: - }, - { - path: "changes", - element: - }, - { - path: "inventory/:apiCollectionId", - element: - }, - { - path: "data-types", - element: - }, - { - path: "sensitive/:subType", - element: - }, - { - path: "sensitive/:subType/:apiCollectionId/:urlAndMethod", - element: - } - ] - }, - { - path:"issues", - element: - }, - { - path: "quick-start", - element: , - }, - { - path:"threat-detection", - element: - }, - { - path: "threat-api", - element: - }, - { - path: "threat-actor", - element: - } - ] - }, - { - path: "settings", - element: , - children: [ - { - path: "users", - element: - }, - { - path: "Help", - element: - }, - { - path: "integrations", - element: , - }, - { - path: "about", - element: , - }, - { - path: "metrics", - element: , - }, - { - path: "integrations/burp", - element: , - }, - { - path: "integrations/ci-cd", - element: , - }, - { - path: "integrations/postman", - element: , - }, - { - path: "integrations/jira", - element: , - }, - { - path: "integrations/akto_apis", - element: , - }, - { - path: "integrations/akto_gpt", - element: , - }, - { - path: "integrations/github_sso", - element: - }, - { - path: "integrations/okta_sso", - element: - }, - { - path: "integrations/azure_sso", - element: - }, - { - path: "integrations/google_workspace_sso", - element: - }, - { - path: "integrations/github_app", - element: - }, - { - path: "integrations/slack", - element: , - }, - { - path: "integrations/webhooks", - element: , - }, - { - path: "integrations/webhooks/:webhookId", - element: , - }, - { - path: "integrations/webhooks/create_custom_webhook", - element: , - }, - { - path: "integrations/teamsWebhooks", - element: , - }, - { - path: "integrations/teamsWebhooks/:webhookId", - element: , - }, - { - path: "integrations/teamsWebhooks/create_custom_webhook", - element: , - }, + { + path: "", + element: , + children: [ + { + path: "home", + element: , + }, + { + path: "testing", + element: , + children: [ + ...(["", "active", "cicd", "inactive"].map((i) => { + return { + path: i, + element: + } + })), + { + path: ":hexId", + element: + }, + { + path: "roles", + element: + }, + { + path: "roles/details", + element: + }, + { + path: "roles/access-matrix", + element: + }, + { + path: "user-config", + element: + }, + { + path: "dependency", + element: + } + ] + }, + { + path: "observe", + element: , + children: [ + { + path: "sensitive", + element: + }, + { + path: "inventory", + element: + }, + { + path: "query_mode", + element: + }, + { + path: "changes", + element: + }, + { + path: "inventory/:apiCollectionId", + element: + }, + { + path: "data-types", + element: + }, + { + path: "sensitive/:subType", + element: + }, + { + path: "sensitive/:subType/:apiCollectionId/:urlAndMethod", + element: + } + ] + }, + { + path: "issues", + element: + }, + { + path: "protection", + children: [ + { + path: "threat-activity", + element: + }, + { + path: "threat-api", + element: + }, + { + path: "threat-actor", + element: + }, + { + path: "threat-policy", + element: + } + ] + }, + { + path: "quick-start", + element: , + }, + ] + }, + { + path: "settings", + element: , + children: [ + { + path: "users", + element: + }, + { + path: "Help", + element: + }, + { + path: "integrations", + element: , + }, + { + path: "about", + element: , + }, + { + path: "metrics", + element: , + }, + { + path: "integrations/burp", + element: , + }, + { + path: "integrations/ci-cd", + element: , + }, + { + path: "integrations/postman", + element: , + }, + { + path: "integrations/jira", + element: , + }, + { + path: "integrations/akto_apis", + element: , + }, + { + path: "integrations/akto_gpt", + element: , + }, + { + path: "integrations/github_sso", + element: + }, + { + path: "integrations/okta_sso", + element: + }, + { + path: "integrations/azure_sso", + element: + }, + { + path: "integrations/google_workspace_sso", + element: + }, + { + path: "integrations/github_app", + element: + }, + { + path: "integrations/slack", + element: , + }, + { + path: "integrations/webhooks", + element: , + }, + { + path: "integrations/webhooks/:webhookId", + element: , + }, + { + path: "integrations/webhooks/create_custom_webhook", + element: , + }, + { + path: "integrations/teamsWebhooks", + element: , + }, + { + path: "integrations/teamsWebhooks/:webhookId", + element: , + }, + { + path: "integrations/teamsWebhooks/create_custom_webhook", + element: , + }, - { - path: "logs", - element: , - }, - { - path: "auth-types", - element: - }, - { - path: "default-payloads", - element: - }, - { - path: 'advanced-filters', - element: - }, - { - path: "auth-types/details", - element: - }, - { - path: "tags", - element: - }, - { - path: "tags/details", - element: - }, - { - path: "test-library", - element: - }, - { - path: "billing", - element: - }, - { - path: "self-hosted", - element: - }, - { - path: 'audit-logs', - element: - } - ] - }, - { - path: "test-editor/:testId", - element: - }, - { - path: "test-editor", - element: - }, - { - path: "onboarding", - element: - }, - { - path: "testing/summary/:reportId", - element: - }, - { - path: "issues/summary/:reportId", - element: - } - ], - errorElement: - }, - { - path: "/login", - element: , - }, - { - path: "/", - element: , - }, - { - path: "/signup", - element: , - }, - { - path: "/check-inbox", - element: - }, - { - path: "/business-email", - element: - }, - { - path: "/sso-login", - element: - }, - // catches all undefined paths and redirects to homepage. - { - path: "*", - element: , - }, + { + path: "logs", + element: , + }, + { + path: "auth-types", + element: + }, + { + path: "default-payloads", + element: + }, + { + path: 'advanced-filters', + element: + }, + { + path: "auth-types/details", + element: + }, + { + path: "tags", + element: + }, + { + path: "tags/details", + element: + }, + { + path: "test-library", + element: + }, + { + path: "billing", + element: + }, + { + path: "self-hosted", + element: + }, + { + path: 'audit-logs', + element: + } + ] + }, + { + path: "test-editor/:testId", + element: + }, + { + path: "test-editor", + element: + }, + { + path: "onboarding", + element: + }, + { + path: "testing/summary/:reportId", + element: + }, + { + path: "issues/summary/:reportId", + element: + } + ], + errorElement: + }, + { + path: "/login", + element: , + }, + { + path: "/", + element: , + }, + { + path: "/signup", + element: , + }, + { + path: "/check-inbox", + element: + }, + { + path: "/business-email", + element: + }, + { + path: "/sso-login", + element: + }, + // catches all undefined paths and redirects to homepage. + { + path: "*", + element: , + }, ]) function App() { - const setAllRoutes = Store(state => state.setAllRoutes) - const searchData= generateSearchData(router.routes) - const { stigg } = useStiggContext(); - useEffect(() => { - stigg.setCustomerId(window.STIGG_CUSTOMER_ID, window.STIGG_CUSTOMER_TOKEN) - - }) + const setAllRoutes = Store(state => state.setAllRoutes) + const searchData = generateSearchData(router.routes) + const {stigg} = useStiggContext(); + useEffect(() => { + stigg.setCustomerId(window.STIGG_CUSTOMER_ID, window.STIGG_CUSTOMER_TOKEN) + + }) - useEffect(() => { - const script = document.createElement('script') - const scriptText = document.createTextNode(` + useEffect(() => { + const script = document.createElement('script') + const scriptText = document.createTextNode(` self.MonacoEnvironment = { getWorkerUrl: function (moduleId, label) { if (label === 'json') { @@ -411,18 +421,18 @@ function App() { } }; `); - setAllRoutes(searchData) - script.appendChild(scriptText); - document.body.appendChild(script) - }, []) + setAllRoutes(searchData) + script.appendChild(scriptText); + document.body.appendChild(script) + }, []) - return ( - - - - - - ); + return ( + + + + + + ); } export default App; \ No newline at end of file diff --git a/apps/pom.xml b/apps/pom.xml index 20dcc1cb26..d6c4886121 100644 --- a/apps/pom.xml +++ b/apps/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 @@ -148,4 +149,4 @@ - + \ No newline at end of file diff --git a/apps/api-threat-detection/.gitignore b/apps/threat-detection/.gitignore similarity index 100% rename from apps/api-threat-detection/.gitignore rename to apps/threat-detection/.gitignore diff --git a/apps/threat-detection/Dockerfile b/apps/threat-detection/Dockerfile new file mode 100644 index 0000000000..41b66dbbac --- /dev/null +++ b/apps/threat-detection/Dockerfile @@ -0,0 +1,4 @@ +FROM openjdk +WORKDIR /app +COPY ./target/threat-detection-1.0-SNAPSHOT-jar-with-dependencies.jar /app/threat-detection-1.0-SNAPSHOT-jar-with-dependencies.jar +CMD "java" "-XX:+ExitOnOutOfMemoryError" "-jar" "/app/threat-detection-1.0-SNAPSHOT-jar-with-dependencies.jar" \ No newline at end of file diff --git a/apps/api-threat-detection/README.md b/apps/threat-detection/README.md similarity index 100% rename from apps/api-threat-detection/README.md rename to apps/threat-detection/README.md diff --git a/apps/threat-detection/pom.xml b/apps/threat-detection/pom.xml new file mode 100644 index 0000000000..bd143c2dc5 --- /dev/null +++ b/apps/threat-detection/pom.xml @@ -0,0 +1,260 @@ + + + 4.0.0 + + + com.akto.apps + apps + ${revision} + + + com.akto.apps.threat-detection + threat-detection + jar + + + + confluent + https://packages.confluent.io/maven/ + + + + + + org.apache.commons + commons-lang3 + 3.12.0 + + + com.akto.libs.dao + dao + ${project.version} + + + com.akto.libs.utils + utils + ${project.version} + + + com.akto.apps.mini-runtime + mini-runtime + ${project.version} + + + com.akto.apps.testing + testing + ${project.version} + + + org.apache.httpcomponents + httpclient + 4.5.13 + + + org.jetbrains + annotations + RELEASE + compile + + + org.junit.jupiter + junit-jupiter-api + 5.4.2 + test + + + org.apache.kafka + kafka-clients + 3.0.0 + + + com.akto.libs.utils + utils + test-jar + ${project.version} + test + + + io.confluent + kafka-protobuf-serializer + 7.5.0 + + + + com.akto.libs.protobuf + protobuf + 1.0-SNAPSHOT + compile + + + + io.lettuce + lettuce-core + 6.4.0.RELEASE + + + + com.github.ben-manes.caffeine + caffeine + 2.9.3 + + + com.fasterxml.jackson.core + jackson-databind + 2.16.1 + compile + + + + org.postgresql + postgresql + 42.7.4 + + + + org.flywaydb + flyway-core + 9.22.3 + + + + org.hibernate + hibernate-core + 5.6.15.Final + + + + org.apache.logging.log4j + log4j-core + 2.24.2 + + + + org.apache.logging.log4j + log4j-api + 2.24.2 + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 8 + 8 + + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.0.1 + + + copy-dependencies + package + + copy-dependencies + + + + + + + src/main/java + src/test/java + + + src/main/resources + false + + + + + + + + normal + + true + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + package + + single + + + + + + com.akto.threat.detection.Main + + + + + jar-with-dependencies + + + + + + + + + + + devcontainer + + + + org.apache.maven.plugins + maven-jar-plugin + + threat-detection-1.0-SNAPSHOT-jar-with-dependencies + + + true + com.akto.threat.detection.Main + dependency-jars/ + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + package + + copy-dependencies + + + ${project.build.directory}/dependency-jars/ + + + + + + + + + + \ No newline at end of file diff --git a/apps/threat-detection/src/main/java/com/akto/threat/detection/Main.java b/apps/threat-detection/src/main/java/com/akto/threat/detection/Main.java new file mode 100644 index 0000000000..0ea77e9470 --- /dev/null +++ b/apps/threat-detection/src/main/java/com/akto/threat/detection/Main.java @@ -0,0 +1,87 @@ +package com.akto.threat.detection; + +import com.akto.DaoInit; +import com.akto.kafka.KafkaConfig; +import com.akto.kafka.KafkaConsumerConfig; +import com.akto.kafka.KafkaProducerConfig; +import com.akto.kafka.Serializer; +import com.akto.threat.detection.constants.KafkaTopic; +import com.akto.threat.detection.session_factory.SessionFactoryUtils; +import com.akto.threat.detection.tasks.CleanupTask; +import com.akto.threat.detection.tasks.FlushSampleDataTask; +import com.akto.threat.detection.tasks.MaliciousTrafficDetectorTask; +import com.akto.threat.detection.tasks.SendMaliciousEventsToBackend; +import com.mongodb.ConnectionString; +import io.lettuce.core.RedisClient; +import org.flywaydb.core.Flyway; +import org.hibernate.SessionFactory; + +public class Main { + + private static final String CONSUMER_GROUP_ID = "akto.threat_detection"; + + public static void main(String[] args) { + runMigrations(); + + SessionFactory sessionFactory = SessionFactoryUtils.createFactory(); + + // TODO: Remove this before merging. Will be using cyborg for fetching templates + DaoInit.init(new ConnectionString(System.getenv("AKTO_MONGO_CONN"))); + KafkaConfig trafficKafka = + KafkaConfig.newBuilder() + .setGroupId(CONSUMER_GROUP_ID) + .setBootstrapServers(System.getenv("AKTO_TRAFFIC_KAFKA_BOOTSTRAP_SERVER")) + .setConsumerConfig( + KafkaConsumerConfig.newBuilder() + .setMaxPollRecords(100) + .setPollDurationMilli(100) + .build()) + .setProducerConfig( + KafkaProducerConfig.newBuilder().setBatchSize(100).setLingerMs(100).build()) + .setKeySerializer(Serializer.STRING) + .setValueSerializer(Serializer.BYTE_ARRAY) + .build(); + + KafkaConfig internalKafka = + KafkaConfig.newBuilder() + .setGroupId(CONSUMER_GROUP_ID) + .setBootstrapServers(System.getenv("AKTO_INTERNAL_KAFKA_BOOTSTRAP_SERVER")) + .setConsumerConfig( + KafkaConsumerConfig.newBuilder() + .setMaxPollRecords(100) + .setPollDurationMilli(100) + .build()) + .setProducerConfig( + KafkaProducerConfig.newBuilder().setBatchSize(100).setLingerMs(100).build()) + .setKeySerializer(Serializer.STRING) + .setValueSerializer(Serializer.BYTE_ARRAY) + .build(); + + new MaliciousTrafficDetectorTask(trafficKafka, internalKafka, createRedisClient()).run(); + new FlushSampleDataTask( + sessionFactory, internalKafka, KafkaTopic.ThreatDetection.MALICIOUS_EVENTS) + .run(); + new SendMaliciousEventsToBackend( + sessionFactory, internalKafka, KafkaTopic.ThreatDetection.ALERTS) + .run(); + new CleanupTask(sessionFactory).run(); + } + + public static RedisClient createRedisClient() { + return RedisClient.create(System.getenv("AKTO_THREAT_DETECTION_REDIS_URI")); + } + + public static void runMigrations() { + String url = System.getenv("AKTO_THREAT_DETECTION_POSTGRES"); + String user = System.getenv("AKTO_THREAT_DETECTION_POSTGRES_USER"); + String password = System.getenv("AKTO_THREAT_DETECTION_POSTGRES_PASSWORD"); + Flyway flyway = + Flyway.configure() + .dataSource(url, user, password) + .locations("classpath:db/migration") + .schemas("flyway") + .load(); + + flyway.migrate(); + } +} diff --git a/apps/threat-detection/src/main/java/com/akto/threat/detection/actor/ActorGenerator.java b/apps/threat-detection/src/main/java/com/akto/threat/detection/actor/ActorGenerator.java new file mode 100644 index 0000000000..9f27be49bc --- /dev/null +++ b/apps/threat-detection/src/main/java/com/akto/threat/detection/actor/ActorGenerator.java @@ -0,0 +1,10 @@ +package com.akto.threat.detection.actor; + +import com.akto.dto.HttpResponseParams; + +import java.util.Optional; + +public interface ActorGenerator { + + Optional generate(HttpResponseParams responseParams); +} diff --git a/apps/threat-detection/src/main/java/com/akto/threat/detection/actor/SourceIPActorGenerator.java b/apps/threat-detection/src/main/java/com/akto/threat/detection/actor/SourceIPActorGenerator.java new file mode 100644 index 0000000000..ebe444a2f1 --- /dev/null +++ b/apps/threat-detection/src/main/java/com/akto/threat/detection/actor/SourceIPActorGenerator.java @@ -0,0 +1,24 @@ +package com.akto.threat.detection.actor; + +import com.akto.dto.HttpResponseParams; +import com.akto.runtime.policies.ApiAccessTypePolicy; + +import java.util.List; +import java.util.Optional; + +public class SourceIPActorGenerator implements ActorGenerator { + + private SourceIPActorGenerator() {} + + public static SourceIPActorGenerator instance = new SourceIPActorGenerator(); + + @Override + public Optional generate(HttpResponseParams responseParams) { + List sourceIPs = ApiAccessTypePolicy.getSourceIps(responseParams); + if (sourceIPs.isEmpty()) { + return Optional.of(responseParams.getSourceIP()); + } + + return Optional.of(sourceIPs.get(0)); + } +} diff --git a/apps/threat-detection/src/main/java/com/akto/threat/detection/cache/CounterCache.java b/apps/threat-detection/src/main/java/com/akto/threat/detection/cache/CounterCache.java new file mode 100644 index 0000000000..f1eaeffa90 --- /dev/null +++ b/apps/threat-detection/src/main/java/com/akto/threat/detection/cache/CounterCache.java @@ -0,0 +1,14 @@ +package com.akto.threat.detection.cache; + +public interface CounterCache { + + void incrementBy(String key, long val); + + void increment(String key); + + long get(String key); + + boolean exists(String key); + + void clear(String key); +} diff --git a/apps/threat-detection/src/main/java/com/akto/threat/detection/cache/LongValueCodec.java b/apps/threat-detection/src/main/java/com/akto/threat/detection/cache/LongValueCodec.java new file mode 100644 index 0000000000..54879be184 --- /dev/null +++ b/apps/threat-detection/src/main/java/com/akto/threat/detection/cache/LongValueCodec.java @@ -0,0 +1,32 @@ +package com.akto.threat.detection.cache; + +import io.lettuce.core.codec.RedisCodec; +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; + +public class LongValueCodec implements RedisCodec { + + @Override + public String decodeKey(ByteBuffer bytes) { + return StandardCharsets.UTF_8.decode(bytes).toString(); + } + + @Override + public Long decodeValue(ByteBuffer bytes) { + if (!bytes.hasRemaining()) return null; + return bytes.getLong(); + } + + @Override + public ByteBuffer encodeKey(String key) { + return StandardCharsets.UTF_8.encode(key); + } + + @Override + public ByteBuffer encodeValue(Long value) { + ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES); + buffer.putLong(value); + buffer.flip(); + return buffer; + } +} diff --git a/apps/threat-detection/src/main/java/com/akto/threat/detection/cache/RedisBackedCounterCache.java b/apps/threat-detection/src/main/java/com/akto/threat/detection/cache/RedisBackedCounterCache.java new file mode 100644 index 0000000000..2182be09c6 --- /dev/null +++ b/apps/threat-detection/src/main/java/com/akto/threat/detection/cache/RedisBackedCounterCache.java @@ -0,0 +1,126 @@ +package com.akto.threat.detection.cache; + +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; +import io.lettuce.core.ExpireArgs; +import io.lettuce.core.RedisClient; +import io.lettuce.core.api.StatefulRedisConnection; +import java.util.HashSet; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.*; + +public class RedisBackedCounterCache implements CounterCache { + + static class Op { + private final String key; + private final long value; + + public Op(String key, long value) { + this.key = key; + this.value = value; + } + + public String getKey() { + return key; + } + + public long getValue() { + return value; + } + } + + private final StatefulRedisConnection redis; + + private final Cache localCache; + + private final ConcurrentLinkedQueue pendingIncOps; + private final ConcurrentMap deletedKeys; + private final String prefix; + + public RedisBackedCounterCache(RedisClient redisClient, String prefix) { + this.prefix = prefix; + this.redis = redisClient.connect(new LongValueCodec()); + this.localCache = Caffeine.newBuilder().maximumSize(100000).expireAfterWrite(3, TimeUnit.HOURS).build(); + + ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); + executor.scheduleAtFixedRate(this::syncToRedis, 60, 5, TimeUnit.SECONDS); + + this.pendingIncOps = new ConcurrentLinkedQueue<>(); + this.deletedKeys = new ConcurrentHashMap<>(); + } + + private String addPrefixToKey(String key) { + return new StringBuilder().append(prefix).append("|").append(key).toString(); + } + + @Override + public void increment(String key) { + incrementBy(key, 1); + } + + @Override + public void incrementBy(String key, long val) { + String _key = addPrefixToKey(key); + localCache.asMap().merge(_key, val, Long::sum); + pendingIncOps.add(new Op(_key, val)); + } + + @Override + public long get(String key) { + return Optional.ofNullable(this.localCache.getIfPresent(addPrefixToKey(key))).orElse(0L); + } + + @Override + public boolean exists(String key) { + return localCache.asMap().containsKey(addPrefixToKey(key)); + } + + @Override + public void clear(String key) { + String _key = addPrefixToKey(key); + localCache.invalidate(_key); + this.deletedKeys.put(_key, true); + redis.async().del(_key); + } + + private void setExpiryIfNotSet(String key, long seconds) { + // We only set expiry for redis entry. For local cache we have lower expiry for + // all entries. + ExpireArgs args = ExpireArgs.Builder.nx(); + redis.async().expire(addPrefixToKey(key), seconds, args); + } + + private void syncToRedis() { + Set _keys = new HashSet<>(); + while (!pendingIncOps.isEmpty()) { + Op op = pendingIncOps.poll(); + String key = op.getKey(); + long val = op.getValue(); + + if (this.deletedKeys.containsKey(key)) { + continue; + } + + redis + .async() + .incrby(key, val) + .whenComplete( + (result, ex) -> { + if (ex != null) { + ex.printStackTrace(); + } + + _keys.add(key); + + if (result != null) { + localCache.asMap().put(key, result); + } + }); + } + + _keys.forEach(key -> setExpiryIfNotSet(key, 3 * 60 * 60)); + + this.deletedKeys.clear(); + } +} diff --git a/apps/threat-detection/src/main/java/com/akto/threat/detection/constants/KafkaTopic.java b/apps/threat-detection/src/main/java/com/akto/threat/detection/constants/KafkaTopic.java new file mode 100644 index 0000000000..7c13df8d87 --- /dev/null +++ b/apps/threat-detection/src/main/java/com/akto/threat/detection/constants/KafkaTopic.java @@ -0,0 +1,8 @@ +package com.akto.threat.detection.constants; + +public class KafkaTopic { + public static class ThreatDetection { + public static final String MALICIOUS_EVENTS = "akto.threat_detection.malicious_events"; + public static final String ALERTS = "akto.threat_detection.alerts"; + } +} \ No newline at end of file diff --git a/apps/threat-detection/src/main/java/com/akto/threat/detection/db/entity/MaliciousEventEntity.java b/apps/threat-detection/src/main/java/com/akto/threat/detection/db/entity/MaliciousEventEntity.java new file mode 100644 index 0000000000..41bf2422ee --- /dev/null +++ b/apps/threat-detection/src/main/java/com/akto/threat/detection/db/entity/MaliciousEventEntity.java @@ -0,0 +1,209 @@ +package com.akto.threat.detection.db.entity; + +import com.akto.dto.type.URLMethods; +import java.time.LocalDateTime; +import java.time.ZoneOffset; +import java.util.UUID; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.PrePersist; +import javax.persistence.Table; +import org.hibernate.annotations.GenericGenerator; + +@Entity +@Table(name = "malicious_event", schema = "threat_detection") +public class MaliciousEventEntity { + + @Id + @GeneratedValue(generator = "UUID") + @GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator") + private UUID id; + + @Column(name = "actor") + private String actor; + + @Column(name = "filter_id") + private String filterId; + + @Column(name = "url") + private String url; + + @Column(name = "method") + @Enumerated(EnumType.STRING) + private URLMethods.Method method; + + @Column(name = "timestamp") + private long timestamp; + + @Column(name = "orig") + private String orig; + + // Geo location data + @Column(name = "ip") + private String ip; + + @Column(name = "api_collection_id") + private int apiCollectionId; + + @Column(name = "created_at", updatable = false) + private LocalDateTime createdAt; + + @Column(name = "_alerted_to_backend") + private boolean alertedToBackend; + + public MaliciousEventEntity() {} + + @PrePersist + protected void onCreate() { + this.createdAt = LocalDateTime.now(ZoneOffset.UTC); + } + + public MaliciousEventEntity(Builder builder) { + this.actor = builder.actorId; + this.filterId = builder.filterId; + this.url = builder.url; + this.method = builder.method; + this.timestamp = builder.timestamp; + this.orig = builder.orig; + this.ip = builder.ip; + this.apiCollectionId = builder.apiCollectionId; + } + + public static class Builder { + private String actorId; + private String filterId; + private String url; + private URLMethods.Method method; + private long timestamp; + private String orig; + private String ip; + private int apiCollectionId; + + public Builder setActor(String actorId) { + this.actorId = actorId; + return this; + } + + public Builder setFilterId(String filterId) { + this.filterId = filterId; + return this; + } + + public Builder setUrl(String url) { + this.url = url; + return this; + } + + public Builder setMethod(URLMethods.Method method) { + this.method = method; + return this; + } + + public Builder setTimestamp(long timestamp) { + this.timestamp = timestamp; + return this; + } + + public Builder setOrig(String orig) { + this.orig = orig; + return this; + } + + public Builder setIp(String ip) { + this.ip = ip; + return this; + } + + public Builder setApiCollectionId(int apiCollectionId) { + this.apiCollectionId = apiCollectionId; + return this; + } + + public MaliciousEventEntity build() { + return new MaliciousEventEntity(this); + } + } + + public static Builder newBuilder() { + return new Builder(); + } + + public UUID getId() { + return id; + } + + public String getActor() { + return actor; + } + + public String getFilterId() { + return filterId; + } + + public String getUrl() { + return url; + } + + public URLMethods.Method getMethod() { + return method; + } + + public long getTimestamp() { + return timestamp; + } + + public String getOrig() { + return orig; + } + + public String getIp() { + return ip; + } + + public int getApiCollectionId() { + return apiCollectionId; + } + + public LocalDateTime getCreatedAt() { + return createdAt; + } + + public boolean isAlertedToBackend() { + return alertedToBackend; + } + + @Override + public String toString() { + return "MaliciousEventEntity{" + + "createdAt=" + + createdAt + + ", apiCollectionId=" + + apiCollectionId + + ", ip='" + + ip + + '\'' + + ", orig='" + + orig + + '\'' + + ", timestamp=" + + timestamp + + ", method=" + + method + + ", url='" + + url + + '\'' + + ", filterId='" + + filterId + + '\'' + + ", actor='" + + actor + + '\'' + + ", id=" + + id + + '}'; + } +} diff --git a/apps/threat-detection/src/main/java/com/akto/threat/detection/dto/MessageEnvelope.java b/apps/threat-detection/src/main/java/com/akto/threat/detection/dto/MessageEnvelope.java new file mode 100644 index 0000000000..06fe644be4 --- /dev/null +++ b/apps/threat-detection/src/main/java/com/akto/threat/detection/dto/MessageEnvelope.java @@ -0,0 +1,78 @@ +package com.akto.threat.detection.dto; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.protobuf.InvalidProtocolBufferException; +import com.google.protobuf.Message; +import com.google.protobuf.util.JsonFormat; +import java.util.Optional; + +// Kafka Message Wrapper for suspect data +public class MessageEnvelope { + private String accountId; + private String data; + private String actor; + + private static final ObjectMapper objectMapper = new ObjectMapper(); + + public MessageEnvelope() {} + + public MessageEnvelope(String accountId, String actor, String data) { + this.accountId = accountId; + this.actor = actor; + this.data = data; + } + + public String getAccountId() { + return accountId; + } + + public void setAccountId(String accountId) { + this.accountId = accountId; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + + public Optional marshal() { + try { + return Optional.ofNullable(objectMapper.writeValueAsString(this)); + } catch (Exception e) { + e.printStackTrace(); + } + + return Optional.empty(); + } + + public static Optional unmarshal(String message) { + try { + return Optional.ofNullable(objectMapper.readValue(message, MessageEnvelope.class)); + } catch (Exception e) { + e.printStackTrace(); + } + + return Optional.empty(); + } + + public static MessageEnvelope generateEnvelope(String accountId, String actor, Message msg) + throws InvalidProtocolBufferException { + String data = JsonFormat.printer().print(msg); + return new MessageEnvelope(accountId, actor, data); + } + + public String getActor() { + return actor; + } + + public void setActor(String actor) { + this.actor = actor; + } + + public static ObjectMapper getObjectmapper() { + return objectMapper; + } +} diff --git a/apps/threat-detection/src/main/java/com/akto/threat/detection/kafka/KafkaProtoProducer.java b/apps/threat-detection/src/main/java/com/akto/threat/detection/kafka/KafkaProtoProducer.java new file mode 100644 index 0000000000..913eec9a78 --- /dev/null +++ b/apps/threat-detection/src/main/java/com/akto/threat/detection/kafka/KafkaProtoProducer.java @@ -0,0 +1,49 @@ +package com.akto.threat.detection.kafka; + +import com.akto.kafka.KafkaConfig; +import com.akto.kafka.Serializer; +import com.google.protobuf.Message; +import java.time.Duration; +import java.util.Properties; +import org.apache.kafka.clients.producer.*; + +public class KafkaProtoProducer { + private final KafkaProducer producer; + public boolean producerReady; + + public KafkaProtoProducer(KafkaConfig kafkaConfig) { + this.producer = + generateProducer( + kafkaConfig.getBootstrapServers(), + kafkaConfig.getProducerConfig().getLingerMs(), + kafkaConfig.getProducerConfig().getBatchSize()); + } + + public void send(String topic, Message message) { + byte[] messageBytes = message.toByteArray(); + this.producer.send(new ProducerRecord<>(topic, messageBytes)); + } + + public void close() { + this.producerReady = false; + producer.close(Duration.ofMillis(0)); // close immediately + } + + private KafkaProducer generateProducer( + String brokerIP, int lingerMS, int batchSize) { + if (producer != null) close(); // close existing producer connection + + int requestTimeoutMs = 5000; + Properties kafkaProps = new Properties(); + kafkaProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, brokerIP); + kafkaProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, Serializer.STRING.getSerializer()); + kafkaProps.put( + ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, Serializer.BYTE_ARRAY.getSerializer()); + kafkaProps.put(ProducerConfig.BATCH_SIZE_CONFIG, batchSize); + kafkaProps.put(ProducerConfig.LINGER_MS_CONFIG, lingerMS); + kafkaProps.put(ProducerConfig.RETRIES_CONFIG, 0); + kafkaProps.put(ProducerConfig.REQUEST_TIMEOUT_MS_CONFIG, requestTimeoutMs); + kafkaProps.put(ProducerConfig.DELIVERY_TIMEOUT_MS_CONFIG, lingerMS + requestTimeoutMs); + return new KafkaProducer<>(kafkaProps); + } +} diff --git a/apps/threat-detection/src/main/java/com/akto/threat/detection/session_factory/SessionFactoryUtils.java b/apps/threat-detection/src/main/java/com/akto/threat/detection/session_factory/SessionFactoryUtils.java new file mode 100644 index 0000000000..7bf80f0f7b --- /dev/null +++ b/apps/threat-detection/src/main/java/com/akto/threat/detection/session_factory/SessionFactoryUtils.java @@ -0,0 +1,29 @@ +package com.akto.threat.detection.session_factory; + +import com.akto.threat.detection.db.entity.MaliciousEventEntity; +import org.hibernate.SessionFactory; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.cfg.Configuration; + +public class SessionFactoryUtils { + + public static SessionFactory createFactory() { + final String url = System.getenv("AKTO_THREAT_DETECTION_POSTGRES"); + final String user = System.getenv("AKTO_THREAT_DETECTION_POSTGRES_USER"); + final String password = System.getenv("AKTO_THREAT_DETECTION_POSTGRES_PASSWORD"); + + final Configuration cfg = new Configuration(); + cfg.setProperty("hibernate.connection.url", url); + cfg.setProperty("hibernate.connection.user", user); + cfg.setProperty("hibernate.connection.password", password); + cfg.setProperty("dialect", "org.hibernate.dialect.PostgreSQL92Dialect"); + cfg.setProperty("connection.driver_class", "org.postgresql.Driver"); + cfg.setProperty("show_sql", "false"); + cfg.setProperty("format_sql", "false"); + + cfg.addAnnotatedClass(MaliciousEventEntity.class); + + return cfg.buildSessionFactory( + new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()).build()); + } +} diff --git a/apps/threat-detection/src/main/java/com/akto/threat/detection/smart_event_detector/window_based/Bin.java b/apps/threat-detection/src/main/java/com/akto/threat/detection/smart_event_detector/window_based/Bin.java new file mode 100644 index 0000000000..fa1202f2dd --- /dev/null +++ b/apps/threat-detection/src/main/java/com/akto/threat/detection/smart_event_detector/window_based/Bin.java @@ -0,0 +1,19 @@ +package com.akto.threat.detection.smart_event_detector.window_based; + +public class Bin { + int binId; + long count; + + public Bin(int binId, long count) { + this.binId = binId; + this.count = count; + } + + public int getBinId() { + return binId; + } + + public long getCount() { + return count; + } +} diff --git a/apps/threat-detection/src/main/java/com/akto/threat/detection/smart_event_detector/window_based/Data.java b/apps/threat-detection/src/main/java/com/akto/threat/detection/smart_event_detector/window_based/Data.java new file mode 100644 index 0000000000..43f928a6ab --- /dev/null +++ b/apps/threat-detection/src/main/java/com/akto/threat/detection/smart_event_detector/window_based/Data.java @@ -0,0 +1,49 @@ +package com.akto.threat.detection.smart_event_detector.window_based; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.ArrayList; +import java.util.List; + +public class Data { + @JsonProperty("ln") + public long lastNotifiedAt = 0; + + @JsonProperty("rq") + public List requests = new ArrayList<>(); + + public static class Request { + private long receivedAt; + + public Request() {} + + public Request(long receivedAt) { + this.receivedAt = receivedAt; + } + + public long getReceivedAt() { + return receivedAt; + } + + public void setReceivedAt(long receivedAt) { + this.receivedAt = receivedAt; + } + } + + public Data() {} + + public long getLastNotifiedAt() { + return lastNotifiedAt; + } + + public void setLastNotifiedAt(long lastNotifiedAt) { + this.lastNotifiedAt = lastNotifiedAt; + } + + public List getRequests() { + return requests; + } + + public void setRequests(List requests) { + this.requests = requests; + } +} diff --git a/apps/threat-detection/src/main/java/com/akto/threat/detection/smart_event_detector/window_based/WindowBasedThresholdNotifier.java b/apps/threat-detection/src/main/java/com/akto/threat/detection/smart_event_detector/window_based/WindowBasedThresholdNotifier.java new file mode 100644 index 0000000000..01d3b531a7 --- /dev/null +++ b/apps/threat-detection/src/main/java/com/akto/threat/detection/smart_event_detector/window_based/WindowBasedThresholdNotifier.java @@ -0,0 +1,90 @@ +package com.akto.threat.detection.smart_event_detector.window_based; + +import com.akto.dto.api_protection_parse_layer.Rule; +import com.akto.proto.generated.threat_detection.message.sample_request.v1.SampleMaliciousRequest; +import com.akto.threat.detection.cache.CounterCache; +import java.util.ArrayList; +import java.util.List; + +public class WindowBasedThresholdNotifier { + + private final Config config; + + public static class Config { + private final int threshold; + private final int windowSizeInMinutes; + private int notificationCooldownInSeconds = 60 * 30; // 30 mins + + public Config(int threshold, int windowInSeconds) { + this.threshold = threshold; + this.windowSizeInMinutes = windowInSeconds; + } + + public int getThreshold() { + return threshold; + } + + public int getWindowSizeInMinutes() { + return windowSizeInMinutes; + } + + public int getNotificationCooldownInSeconds() { + return notificationCooldownInSeconds; + } + } + + public static class Result { + private final boolean shouldNotify; + + public Result(boolean shouldNotify) { + this.shouldNotify = shouldNotify; + } + + public boolean shouldNotify() { + return shouldNotify; + } + } + + public Config getConfig() { + return config; + } + + private final CounterCache cache; + + public WindowBasedThresholdNotifier(CounterCache cache, Config config) { + this.cache = cache; + this.config = config; + } + + public Result shouldNotify(String aggKey, SampleMaliciousRequest maliciousEvent, Rule rule) { + int binId = (int) maliciousEvent.getTimestamp() / 60; + String cacheKey = aggKey + "|" + binId; + this.cache.increment(cacheKey); + + long windowCount = 0L; + List bins = getBins(aggKey, binId - rule.getCondition().getWindowThreshold() + 1, binId); + for (Bin data : bins) { + windowCount += data.getCount(); + } + + boolean thresholdBreached = windowCount >= rule.getCondition().getMatchCount(); + + if (thresholdBreached) { + this.cache.clear(cacheKey); + } + + return new Result(thresholdBreached); + } + + public List getBins(String aggKey, int binStart, int binEnd) { + List binData = new ArrayList<>(); + for (int i = binStart; i <= binEnd; i++) { + String key = aggKey + "|" + i; + if (!this.cache.exists(key)) { + continue; + } + binData.add(new Bin(i, this.cache.get(key))); + } + return binData; + } +} diff --git a/apps/threat-detection/src/main/java/com/akto/threat/detection/tasks/AbstractKafkaConsumerTask.java b/apps/threat-detection/src/main/java/com/akto/threat/detection/tasks/AbstractKafkaConsumerTask.java new file mode 100644 index 0000000000..dd344ba281 --- /dev/null +++ b/apps/threat-detection/src/main/java/com/akto/threat/detection/tasks/AbstractKafkaConsumerTask.java @@ -0,0 +1,74 @@ +package com.akto.threat.detection.tasks; + +import com.akto.kafka.KafkaConfig; + +import java.time.Duration; +import java.util.Collections; +import java.util.Properties; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import org.apache.kafka.clients.consumer.Consumer; +import org.apache.kafka.clients.consumer.ConsumerRecords; +import org.apache.kafka.clients.consumer.KafkaConsumer; +import org.apache.kafka.clients.consumer.ConsumerConfig; + +public abstract class AbstractKafkaConsumerTask implements Task { + + protected Consumer kafkaConsumer; + protected KafkaConfig kafkaConfig; + protected String kafkaTopic; + + public AbstractKafkaConsumerTask(KafkaConfig kafkaConfig, String kafkaTopic) { + this.kafkaTopic = kafkaTopic; + this.kafkaConfig = kafkaConfig; + + Properties properties = new Properties(); + properties.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaConfig.getBootstrapServers()); + properties.put( + ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, + kafkaConfig.getValueSerializer().getDeserializer()); + properties.put( + ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, + kafkaConfig.getValueSerializer().getDeserializer()); + properties.put( + ConsumerConfig.MAX_POLL_RECORDS_CONFIG, + kafkaConfig.getConsumerConfig().getMaxPollRecords()); + properties.put(ConsumerConfig.GROUP_ID_CONFIG, kafkaConfig.getGroupId()); + properties.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); + properties.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, false); + + this.kafkaConsumer = new KafkaConsumer<>(properties); + } + + @Override + public void run() { + this.kafkaConsumer.subscribe(Collections.singletonList(this.kafkaTopic)); + + ExecutorService pollingExecutor = Executors.newSingleThreadExecutor(); + + pollingExecutor.execute( + () -> { + // Poll data from Kafka topic + while (true) { + ConsumerRecords records = + kafkaConsumer.poll( + Duration.ofMillis(kafkaConfig.getConsumerConfig().getPollDurationMilli())); + if (records.isEmpty()) { + continue; + } + + try { + processRecords(records); + + if (!records.isEmpty()) { + kafkaConsumer.commitSync(); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + }); + } + + abstract void processRecords(ConsumerRecords records); +} diff --git a/apps/threat-detection/src/main/java/com/akto/threat/detection/tasks/CleanupTask.java b/apps/threat-detection/src/main/java/com/akto/threat/detection/tasks/CleanupTask.java new file mode 100644 index 0000000000..93a6d7c906 --- /dev/null +++ b/apps/threat-detection/src/main/java/com/akto/threat/detection/tasks/CleanupTask.java @@ -0,0 +1,39 @@ +package com.akto.threat.detection.tasks; + +import java.time.LocalDateTime; +import java.time.ZoneOffset; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; + +public class CleanupTask implements Task { + + private final SessionFactory sessionFactory; + + public CleanupTask(SessionFactory sessionFactory) { + this.sessionFactory = sessionFactory; + } + + @Override + public void run() { + ScheduledExecutorService cronExecutorService = Executors.newScheduledThreadPool(1); + cronExecutorService.scheduleAtFixedRate(this::cleanup, 5, 30, TimeUnit.MINUTES); + } + + private void cleanup() { + try (Session session = this.sessionFactory.openSession()) { + Transaction txn = session.beginTransaction(); + int deletedCount = + session + .createQuery("delete from MaliciousEventEntity m where m.createdAt < :startDate") + .setParameter("startDate", LocalDateTime.now(ZoneOffset.UTC).minusDays(7)) + .executeUpdate(); + + txn.commit(); + System.out.println("Number of rows deleted: " + deletedCount); + } + } +} diff --git a/apps/threat-detection/src/main/java/com/akto/threat/detection/tasks/FlushSampleDataTask.java b/apps/threat-detection/src/main/java/com/akto/threat/detection/tasks/FlushSampleDataTask.java new file mode 100644 index 0000000000..4b857c389e --- /dev/null +++ b/apps/threat-detection/src/main/java/com/akto/threat/detection/tasks/FlushSampleDataTask.java @@ -0,0 +1,76 @@ +package com.akto.threat.detection.tasks; + +import com.akto.dto.type.URLMethods; +import com.akto.kafka.KafkaConfig; +import com.akto.proto.generated.threat_detection.message.sample_request.v1.SampleMaliciousRequest; +import com.akto.proto.generated.threat_detection.message.sample_request.v1.SampleRequestKafkaEnvelope; +import com.akto.threat.detection.db.entity.MaliciousEventEntity; +import com.akto.threat.detection.dto.MessageEnvelope; +import com.google.protobuf.InvalidProtocolBufferException; +import com.google.protobuf.util.JsonFormat; +import java.util.ArrayList; +import java.util.List; +import org.apache.kafka.clients.consumer.ConsumerRecords; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; + +/* +This will read sample malicious data from kafka topic and save it to DB. + */ +public class FlushSampleDataTask extends AbstractKafkaConsumerTask { + + private final SessionFactory sessionFactory; + + public FlushSampleDataTask( + SessionFactory sessionFactory, KafkaConfig trafficConfig, String topic) { + super(trafficConfig, topic); + this.sessionFactory = sessionFactory; + } + + protected void processRecords(ConsumerRecords records) { + List events = new ArrayList<>(); + records.forEach( + r -> { + SampleRequestKafkaEnvelope envelope; + try { + envelope = SampleRequestKafkaEnvelope.parseFrom(r.value()); + SampleMaliciousRequest evt = envelope.getMaliciousRequest(); + + events.add( + MaliciousEventEntity.newBuilder() + .setActor(envelope.getActor()) + .setFilterId(evt.getFilterId()) + .setUrl(evt.getUrl()) + .setMethod(URLMethods.Method.fromString(evt.getMethod())) + .setTimestamp(evt.getTimestamp()) + .setOrig(evt.getPayload()) + .setApiCollectionId(evt.getApiCollectionId()) + .setIp(evt.getIp()) + .build()); + } catch (InvalidProtocolBufferException e) { + e.printStackTrace(); + } + }); + + Session session = this.sessionFactory.openSession(); + Transaction txn = session.beginTransaction(); + try { + // Commit these events in 2 batches + for (int i = 0; i < events.size(); i++) { + session.persist(events.get(i)); + if (i % 50 == 0) { + session.flush(); + session.clear(); + } + } + + txn.commit(); + } catch (Exception e) { + e.printStackTrace(); + txn.rollback(); + } finally { + session.close(); + } + } +} diff --git a/apps/threat-detection/src/main/java/com/akto/threat/detection/tasks/MaliciousTrafficDetectorTask.java b/apps/threat-detection/src/main/java/com/akto/threat/detection/tasks/MaliciousTrafficDetectorTask.java new file mode 100644 index 0000000000..3ba3603d50 --- /dev/null +++ b/apps/threat-detection/src/main/java/com/akto/threat/detection/tasks/MaliciousTrafficDetectorTask.java @@ -0,0 +1,346 @@ +package com.akto.threat.detection.tasks; + +import com.akto.dao.context.Context; +import com.akto.dao.monitoring.FilterYamlTemplateDao; +import com.akto.data_actor.DataActor; +import com.akto.data_actor.DataActorFactory; +import com.akto.dto.ApiInfo; +import com.akto.dto.HttpRequestParams; +import com.akto.dto.HttpResponseParams; +import com.akto.dto.RawApi; +import com.akto.dto.api_protection_parse_layer.AggregationRules; +import com.akto.dto.api_protection_parse_layer.Condition; +import com.akto.dto.api_protection_parse_layer.Rule; +import com.akto.dto.monitoring.FilterConfig; +import com.akto.dto.test_editor.YamlTemplate; +import com.akto.dto.type.URLMethods; +import com.akto.hybrid_parsers.HttpCallParser; +import com.akto.kafka.KafkaConfig; +import com.akto.proto.generated.threat_detection.message.malicious_event.event_type.v1.EventType; +import com.akto.proto.generated.threat_detection.message.malicious_event.v1.MaliciousEventKafkaEnvelope; +import com.akto.proto.generated.threat_detection.message.malicious_event.v1.MaliciousEventMessage; +import com.akto.proto.generated.threat_detection.message.sample_request.v1.SampleMaliciousRequest; +import com.akto.proto.generated.threat_detection.message.sample_request.v1.SampleRequestKafkaEnvelope; +import com.akto.proto.http_response_param.v1.HttpResponseParam; +import com.akto.rules.TestPlugin; +import com.akto.test_editor.execution.VariableResolver; +import com.akto.test_editor.filter.data_operands_impl.ValidationResult; +import com.akto.threat.detection.actor.SourceIPActorGenerator; +import com.akto.threat.detection.cache.RedisBackedCounterCache; +import com.akto.threat.detection.constants.KafkaTopic; +import com.akto.threat.detection.kafka.KafkaProtoProducer; +import com.akto.threat.detection.smart_event_detector.window_based.WindowBasedThresholdNotifier; +import com.akto.util.HttpRequestResponseUtils; +import io.lettuce.core.RedisClient; +import java.time.Duration; +import java.util.*; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import org.apache.commons.lang3.math.NumberUtils; +import org.apache.kafka.clients.consumer.*; + +/* +Class is responsible for consuming traffic data from the Kafka topic. +Pass data through filters and identify malicious traffic. + */ +public class MaliciousTrafficDetectorTask implements Task { + + private final Consumer kafkaConsumer; + private final KafkaConfig kafkaConfig; + private final HttpCallParser httpCallParser; + private final WindowBasedThresholdNotifier windowBasedThresholdNotifier; + + private Map apiFilters; + private int filterLastUpdatedAt = 0; + private int filterUpdateIntervalSec = 900; + + private final KafkaProtoProducer internalKafka; + + private static final DataActor dataActor = DataActorFactory.fetchInstance(); + + public MaliciousTrafficDetectorTask( + KafkaConfig trafficConfig, KafkaConfig internalConfig, RedisClient redisClient) { + this.kafkaConfig = trafficConfig; + + Properties properties = new Properties(); + properties.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, trafficConfig.getBootstrapServers()); + properties.put( + ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, + trafficConfig.getKeySerializer().getDeserializer()); + properties.put( + ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, + trafficConfig.getValueSerializer().getDeserializer()); + properties.put( + ConsumerConfig.MAX_POLL_RECORDS_CONFIG, + trafficConfig.getConsumerConfig().getMaxPollRecords()); + properties.put(ConsumerConfig.GROUP_ID_CONFIG, trafficConfig.getGroupId()); + properties.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); + properties.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, false); + this.kafkaConsumer = new KafkaConsumer<>(properties); + + this.httpCallParser = new HttpCallParser(120, 1000); + + this.windowBasedThresholdNotifier = + new WindowBasedThresholdNotifier( + new RedisBackedCounterCache(redisClient, "wbt"), + new WindowBasedThresholdNotifier.Config(100, 10 * 60)); + + this.internalKafka = new KafkaProtoProducer(internalConfig); + } + + public void run() { + this.kafkaConsumer.subscribe(Collections.singletonList("akto.api.logs")); + ExecutorService pollingExecutor = Executors.newSingleThreadExecutor(); + pollingExecutor.execute( + () -> { + // Poll data from Kafka topic + while (true) { + ConsumerRecords records = + kafkaConsumer.poll( + Duration.ofMillis(kafkaConfig.getConsumerConfig().getPollDurationMilli())); + + try { + for (ConsumerRecord record : records) { + HttpResponseParam httpResponseParam = HttpResponseParam.parseFrom(record.value()); + processRecord(httpResponseParam); + } + + if (!records.isEmpty()) { + // Should we commit even if there are no records ? + kafkaConsumer.commitSync(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + + private Map getFilters() { + int now = (int) (System.currentTimeMillis() / 1000); + if (now - filterLastUpdatedAt < filterUpdateIntervalSec) { + return apiFilters; + } + + List templates = dataActor.fetchFilterYamlTemplates(); + apiFilters = FilterYamlTemplateDao.fetchFilterConfig(false, templates, false); + this.filterLastUpdatedAt = now; + return apiFilters; + } + + private boolean validateFilterForRequest( + FilterConfig apiFilter, RawApi rawApi, ApiInfo.ApiInfoKey apiInfoKey, String message) { + try { + Map varMap = apiFilter.resolveVarMap(); + VariableResolver.resolveWordList( + varMap, + new HashMap>() { + { + put(apiInfoKey, Collections.singletonList(message)); + } + }, + apiInfoKey); + + String filterExecutionLogId = UUID.randomUUID().toString(); + ValidationResult res = + TestPlugin.validateFilter( + apiFilter.getFilter().getNode(), rawApi, apiInfoKey, varMap, filterExecutionLogId); + + return res.getIsValid(); + } catch (Exception e) { + e.printStackTrace(); + } + + return false; + } + + private void processRecord(HttpResponseParam record) throws Exception { + HttpResponseParams responseParam = buildHttpResponseParam(record); + + Context.accountId.set(Integer.parseInt(responseParam.getAccountId())); + Map filters = this.getFilters(); + if (filters.isEmpty()) { + return; + } + + List maliciousMessages = new ArrayList<>(); + + String message = responseParam.getOrig(); + RawApi rawApi = RawApi.buildFromMessageNew(responseParam); + int apiCollectionId = httpCallParser.createApiCollectionId(responseParam); + responseParam.requestParams.setApiCollectionId(apiCollectionId); + String url = responseParam.getRequestParams().getURL(); + URLMethods.Method method = + URLMethods.Method.fromString(responseParam.getRequestParams().getMethod()); + ApiInfo.ApiInfoKey apiInfoKey = new ApiInfo.ApiInfoKey(apiCollectionId, url, method); + + for (FilterConfig apiFilter : apiFilters.values()) { + boolean hasPassedFilter = validateFilterForRequest(apiFilter, rawApi, apiInfoKey, message); + + // If a request passes any of the filter, then it's a malicious request, + // and so we push it to kafka + if (hasPassedFilter) { + // Later we will also add aggregation support + // Eg: 100 4xx requests in last 10 minutes. + // But regardless of whether request falls in aggregation or not, + // we still push malicious requests to kafka + + // todo: modify fetch yaml and read aggregate rules from it + List rules = new ArrayList<>(); + rules.add(new Rule("Lfi Rule 1", new Condition(10, 10))); + AggregationRules aggRules = new AggregationRules(); + aggRules.setRule(rules); + + boolean isAggFilter = aggRules != null && !aggRules.getRule().isEmpty(); + + SourceIPActorGenerator.instance + .generate(responseParam) + .ifPresent( + actor -> { + String groupKey = apiFilter.getId(); + String aggKey = actor + "|" + groupKey; + + SampleMaliciousRequest maliciousReq = + SampleMaliciousRequest.newBuilder() + .setUrl(responseParam.getRequestParams().getURL()) + .setMethod(responseParam.getRequestParams().getMethod()) + .setPayload(responseParam.getOrig()) + .setIp(actor) // For now using actor as IP + .setApiCollectionId(responseParam.getRequestParams().getApiCollectionId()) + .setTimestamp(responseParam.getTime()) + .setFilterId(apiFilter.getId()) + .build(); + + maliciousMessages.add( + SampleRequestKafkaEnvelope.newBuilder() + .setActor(actor) + .setAccountId(responseParam.getAccountId()) + .setMaliciousRequest(maliciousReq) + .build()); + + if (!isAggFilter) { + generateAndPushMaliciousEventRequest( + apiFilter, actor, responseParam, maliciousReq, EventType.EVENT_TYPE_SINGLE); + return; + } + + // Aggregation rules + for (Rule rule : aggRules.getRule()) { + WindowBasedThresholdNotifier.Result result = + this.windowBasedThresholdNotifier.shouldNotify(aggKey, maliciousReq, rule); + + if (result.shouldNotify()) { + generateAndPushMaliciousEventRequest( + apiFilter, + actor, + responseParam, + maliciousReq, + EventType.EVENT_TYPE_AGGREGATED); + } + } + }); + } + } + + // Should we push all the messages in one go + // or call kafka.send for each HttpRequestParams + try { + maliciousMessages.forEach( + sample -> { + internalKafka.send(KafkaTopic.ThreatDetection.MALICIOUS_EVENTS, sample); + }); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void generateAndPushMaliciousEventRequest( + FilterConfig apiFilter, + String actor, + HttpResponseParams responseParam, + SampleMaliciousRequest maliciousReq, + EventType eventType) { + MaliciousEventMessage maliciousEvent = + MaliciousEventMessage.newBuilder() + .setFilterId(apiFilter.getId()) + .setActor(actor) + .setDetectedAt(responseParam.getTime()) + .setEventType(eventType) + .setLatestApiCollectionId(maliciousReq.getApiCollectionId()) + .setLatestApiIp(maliciousReq.getIp()) + .setLatestApiPayload(maliciousReq.getPayload()) + .setLatestApiMethod(maliciousReq.getMethod()) + .setDetectedAt(responseParam.getTime()) + .build(); + MaliciousEventKafkaEnvelope envelope = + MaliciousEventKafkaEnvelope.newBuilder() + .setActor(actor) + .setAccountId(responseParam.getAccountId()) + .setMaliciousEvent(maliciousEvent) + .build(); + internalKafka.send(KafkaTopic.ThreatDetection.ALERTS, envelope); + } + + public static HttpResponseParams buildHttpResponseParam( + HttpResponseParam httpResponseParamProto) { + + String apiCollectionIdStr = httpResponseParamProto.getAktoVxlanId(); + int apiCollectionId = 0; + if (NumberUtils.isDigits(apiCollectionIdStr)) { + apiCollectionId = NumberUtils.toInt(apiCollectionIdStr, 0); + } + + String requestPayload = + HttpRequestResponseUtils.rawToJsonString(httpResponseParamProto.getRequestPayload(), null); + + Map> reqHeaders = (Map) httpResponseParamProto.getRequestHeadersMap(); + + // for (Map.Entry entry : + // httpResponseParamProto.getRequestHeadersMap().entrySet()) { + // ArrayList list = new ArrayList<>(entry.getValue().getValuesList()); + // reqHeaders.put(entry.getKey(), list); + // } + + HttpRequestParams requestParams = + new HttpRequestParams( + httpResponseParamProto.getMethod(), + httpResponseParamProto.getPath(), + httpResponseParamProto.getType(), + reqHeaders, + requestPayload, + apiCollectionId); + + String responsePayload = + HttpRequestResponseUtils.rawToJsonString(httpResponseParamProto.getResponsePayload(), null); + + String sourceStr = httpResponseParamProto.getSource(); + if (sourceStr == null || sourceStr == "") { + sourceStr = HttpResponseParams.Source.OTHER.name(); + } + + HttpResponseParams.Source source = HttpResponseParams.Source.valueOf(sourceStr); + Map> respHeaders = (Map) httpResponseParamProto.getResponseHeadersMap(); + + // for (Map.Entry entry : + // httpResponseParamProto.getResponseHeadersMap().entrySet()) { + // ArrayList list = new ArrayList<>(entry.getValue().getValuesList()); + // respHeaders.put(entry.getKey(), list); + // } + + return new HttpResponseParams( + httpResponseParamProto.getType(), + httpResponseParamProto.getStatusCode(), + httpResponseParamProto.getStatus(), + respHeaders, + responsePayload, + requestParams, + httpResponseParamProto.getTime(), + httpResponseParamProto.getAktoAccountId(), + httpResponseParamProto.getIsPending(), + source, + "", + httpResponseParamProto.getIp(), + httpResponseParamProto.getDestIp(), + httpResponseParamProto.getDirection()); + } +} diff --git a/apps/threat-detection/src/main/java/com/akto/threat/detection/tasks/SendMaliciousEventsToBackend.java b/apps/threat-detection/src/main/java/com/akto/threat/detection/tasks/SendMaliciousEventsToBackend.java new file mode 100644 index 0000000000..08e634069e --- /dev/null +++ b/apps/threat-detection/src/main/java/com/akto/threat/detection/tasks/SendMaliciousEventsToBackend.java @@ -0,0 +1,156 @@ +package com.akto.threat.detection.tasks; + +import com.akto.kafka.KafkaConfig; +import com.akto.proto.generated.threat_detection.message.malicious_event.event_type.v1.EventType; +import com.akto.proto.generated.threat_detection.message.malicious_event.v1.MaliciousEventKafkaEnvelope; +import com.akto.proto.generated.threat_detection.message.malicious_event.v1.MaliciousEventMessage; +import com.akto.proto.generated.threat_detection.message.sample_request.v1.SampleMaliciousRequest; +import com.akto.proto.generated.threat_detection.service.malicious_alert_service.v1.RecordMaliciousEventRequest; +import com.akto.proto.utils.ProtoMessageUtils; +import com.akto.threat.detection.db.entity.MaliciousEventEntity; +import com.google.protobuf.InvalidProtocolBufferException; +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.kafka.clients.consumer.ConsumerRecords; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; + +/* +This will send alerts to threat detection backend + */ +public class SendMaliciousEventsToBackend extends AbstractKafkaConsumerTask { + + private final SessionFactory sessionFactory; + private final CloseableHttpClient httpClient; + + public SendMaliciousEventsToBackend( + SessionFactory sessionFactory, KafkaConfig trafficConfig, String topic) { + super(trafficConfig, topic); + this.sessionFactory = sessionFactory; + this.httpClient = HttpClients.createDefault(); + } + + private void markSampleDataAsSent(List ids) { + Session session = this.sessionFactory.openSession(); + Transaction txn = session.beginTransaction(); + try { + session + .createQuery( + "update MaliciousEventEntity m set m.alertedToBackend = true where m.id in :ids") + .setParameterList("ids", ids) + .executeUpdate(); + } catch (Exception ex) { + ex.printStackTrace(); + txn.rollback(); + } finally { + txn.commit(); + session.close(); + } + } + + private List getSampleMaliciousRequests(String actor, String filterId) { + Session session = this.sessionFactory.openSession(); + Transaction txn = session.beginTransaction(); + try { + return session + .createQuery( + "from MaliciousEventEntity m where m.actor = :actor and m.filterId = :filterId and" + + " m.alertedToBackend = false order by m.createdAt desc", + MaliciousEventEntity.class) + .setParameter("actor", actor) + .setParameter("filterId", filterId) + .setMaxResults(50) + .getResultList(); + } catch (Exception ex) { + ex.printStackTrace(); + txn.rollback(); + } finally { + txn.commit(); + session.close(); + } + + return Collections.emptyList(); + } + + protected void processRecords(ConsumerRecords records) { + records.forEach( + r -> { + MaliciousEventKafkaEnvelope envelope; + try { + envelope = MaliciousEventKafkaEnvelope.parseFrom(r.value()); + } catch (InvalidProtocolBufferException e) { + e.printStackTrace(); + return; + } + + if (envelope == null) { + return; + } + + try { + MaliciousEventMessage evt = envelope.getMaliciousEvent(); + + // Get sample data from postgres for this alert + List sampleData = + this.getSampleMaliciousRequests(evt.getActor(), evt.getFilterId()); + RecordMaliciousEventRequest.Builder reqBuilder = + RecordMaliciousEventRequest.newBuilder().setMaliciousEvent(evt); + if (EventType.EVENT_TYPE_AGGREGATED.equals(evt.getEventType())) { + sampleData = this.getSampleMaliciousRequests(evt.getActor(), evt.getFilterId()); + + reqBuilder.addAllSampleRequests( + sampleData.stream() + .map( + d -> + SampleMaliciousRequest.newBuilder() + .setUrl(d.getUrl()) + .setMethod(d.getMethod().name()) + .setTimestamp(d.getTimestamp()) + .setPayload(d.getOrig()) + .setIp(d.getIp()) + .setApiCollectionId(d.getApiCollectionId()) + .build()) + .collect(Collectors.toList())); + } + + List sampleIds = + sampleData.stream().map(MaliciousEventEntity::getId).collect(Collectors.toList()); + + RecordMaliciousEventRequest maliciousEventRequest = reqBuilder.build(); + String url = System.getenv("AKTO_THREAT_PROTECTION_BACKEND_URL"); + String token = System.getenv("AKTO_THREAT_PROTECTION_BACKEND_TOKEN"); + ProtoMessageUtils.toString(maliciousEventRequest) + .ifPresent( + msg -> { + StringEntity requestEntity = + new StringEntity(msg, ContentType.APPLICATION_JSON); + HttpPost req = + new HttpPost( + String.format("%s/api/threat_detection/record_malicious_event", url)); + req.addHeader("Authorization", "Bearer " + token); + req.setEntity(requestEntity); + try { + this.httpClient.execute(req); + } catch (IOException e) { + e.printStackTrace(); + } + + if (!sampleIds.isEmpty()) { + markSampleDataAsSent(sampleIds); + } + }); + } catch (Exception e) { + e.printStackTrace(); + } + }); + } +} diff --git a/apps/threat-detection/src/main/java/com/akto/threat/detection/tasks/Task.java b/apps/threat-detection/src/main/java/com/akto/threat/detection/tasks/Task.java new file mode 100644 index 0000000000..1156ccbd8b --- /dev/null +++ b/apps/threat-detection/src/main/java/com/akto/threat/detection/tasks/Task.java @@ -0,0 +1,6 @@ +package com.akto.threat.detection.tasks; + +public interface Task { + + void run(); +} diff --git a/apps/threat-detection/src/main/resources/db/migration/V1__enable_uuid.sql b/apps/threat-detection/src/main/resources/db/migration/V1__enable_uuid.sql new file mode 100644 index 0000000000..e5c340505a --- /dev/null +++ b/apps/threat-detection/src/main/resources/db/migration/V1__enable_uuid.sql @@ -0,0 +1,2 @@ +-- enabling uuid extension +create extension if not exists "uuid-ossp"; \ No newline at end of file diff --git a/apps/threat-detection/src/main/resources/db/migration/V2__create_malicious_event_table.sql b/apps/threat-detection/src/main/resources/db/migration/V2__create_malicious_event_table.sql new file mode 100644 index 0000000000..17e1b9d80c --- /dev/null +++ b/apps/threat-detection/src/main/resources/db/migration/V2__create_malicious_event_table.sql @@ -0,0 +1,17 @@ +-- create schema and table for malicious events +create schema if not exists threat_detection; +create table if not exists threat_detection.malicious_event ( + id uuid primary key default uuid_generate_v4(), + actor varchar(255) not null, + filter_id varchar(255) not null, + url varchar(1024), + ip varchar(255), + method varchar(255), + timestamp bigint not null, + orig text not null, + api_collection_id int not null, + created_at timestamp default (timezone('utc', now())) +); + +-- add index on actor and filter_id and sort data by timestamp +create index malicious_events_actor_filter_id_timestamp_idx on threat_detection.malicious_event(actor, filter_id, timestamp desc); diff --git a/apps/threat-detection/src/main/resources/db/migration/V3__add_alert_to_backend_column.sql b/apps/threat-detection/src/main/resources/db/migration/V3__add_alert_to_backend_column.sql new file mode 100644 index 0000000000..756815e5b0 --- /dev/null +++ b/apps/threat-detection/src/main/resources/db/migration/V3__add_alert_to_backend_column.sql @@ -0,0 +1,4 @@ +alter table threat_detection.malicious_event add column _alerted_to_backend boolean default false; + +-- set all existing rows to false +update threat_detection.malicious_event set _alerted_to_backend = false; diff --git a/apps/threat-detection/src/main/resources/log4j2.xml b/apps/threat-detection/src/main/resources/log4j2.xml new file mode 100644 index 0000000000..133e6bdd7e --- /dev/null +++ b/apps/threat-detection/src/main/resources/log4j2.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/apps/api-threat-detection/src/main/resources/version.txt b/apps/threat-detection/src/main/resources/version.txt similarity index 100% rename from apps/api-threat-detection/src/main/resources/version.txt rename to apps/threat-detection/src/main/resources/version.txt diff --git a/libs/dao/src/main/java/com/akto/DaoInit.java b/libs/dao/src/main/java/com/akto/DaoInit.java index 7e4ea5a2fe..04ced65abf 100644 --- a/libs/dao/src/main/java/com/akto/DaoInit.java +++ b/libs/dao/src/main/java/com/akto/DaoInit.java @@ -72,6 +72,8 @@ import com.mongodb.ConnectionString; import com.mongodb.MongoClientSettings; import com.mongodb.ReadPreference; +import com.mongodb.client.MongoClient; +import com.mongodb.WriteConcern; import com.mongodb.WriteConcern; import com.mongodb.client.MongoClients; @@ -88,327 +90,471 @@ public class DaoInit { - private static final Logger logger = LoggerFactory.getLogger(DaoInit.class); + private static final Logger logger = LoggerFactory.getLogger(DaoInit.class); - public static CodecRegistry createCodecRegistry(){ - ClassModel configClassModel = ClassModel.builder(Config.class).enableDiscriminator(true).build(); - ClassModel signupInfoClassModel = ClassModel.builder(SignupInfo.class).enableDiscriminator(true) - .build(); - ClassModel apiAuthClassModel = ClassModel.builder(APIAuth.class).enableDiscriminator(true).build(); - ClassModel attempResultModel = ClassModel.builder(AttemptResult.class).enableDiscriminator(true) - .build(); - ClassModel urlTemplateModel = ClassModel.builder(URLTemplate.class).enableDiscriminator(true) - .build(); - ClassModel pendingInviteCodeClassModel = ClassModel.builder(PendingInviteCode.class) - .enableDiscriminator(true).build(); - ClassModel rbacClassModel = ClassModel.builder(RBAC.class).enableDiscriminator(true).build(); - ClassModel singleTypeInfoClassModel = ClassModel.builder(SingleTypeInfo.class) - .enableDiscriminator(true).build(); - ClassModel kafkaHealthMetricClassModel = ClassModel.builder(KafkaHealthMetric.class) - .enableDiscriminator(true).build(); - ClassModel thirdPartyAccessClassModel = ClassModel.builder(ThirdPartyAccess.class) - .enableDiscriminator(true).build(); - ClassModel credentialClassModel = ClassModel.builder(Credential.class).enableDiscriminator(true) - .build(); - ClassModel apiTokenClassModel = ClassModel.builder(ApiToken.class).enableDiscriminator(true).build(); - ClassModel apiInfoClassModel = ClassModel.builder(ApiInfo.class).enableDiscriminator(true).build(); - ClassModel apiInfoKeyClassModel = ClassModel.builder(ApiInfo.ApiInfoKey.class) - .enableDiscriminator(true).build(); - ClassModel customFilterClassModel = ClassModel.builder(CustomFilter.class) - .enableDiscriminator(true).build(); - ClassModel fieldExistsFilterClassModel = ClassModel.builder(FieldExistsFilter.class) - .enableDiscriminator(true).build(); - ClassModel responseCodeRuntimeFilterClassModel = ClassModel - .builder(ResponseCodeRuntimeFilter.class).enableDiscriminator(true).build(); - ; - ClassModel runtimeFilterClassModel = ClassModel.builder(RuntimeFilter.class) - .enableDiscriminator(true).build(); - ClassModel filterSampleDataClassModel = ClassModel.builder(FilterSampleData.class) - .enableDiscriminator(true).build(); - ClassModel accountSettingsClassModel = ClassModel.builder(AccountSettings.class) - .enableDiscriminator(true).build(); - ClassModel predicateClassModel = ClassModel.builder(Predicate.class).enableDiscriminator(true) - .build(); - ClassModel regexPredicateClassModel = ClassModel.builder(RegexPredicate.class) - .enableDiscriminator(true).build(); - ClassModel startsWithPredicateClassModel = ClassModel.builder(StartsWithPredicate.class) - .enableDiscriminator(true).build(); - ClassModel endsWithPredicateClassModel = ClassModel.builder(EndsWithPredicate.class) - .enableDiscriminator(true).build(); - ClassModel equalsToPredicateClassModel = ClassModel.builder(EqualsToPredicate.class) - .enableDiscriminator(true).build(); - ClassModel isNumberPredicateClassModel = ClassModel.builder(IsNumberPredicate.class) - .enableDiscriminator(true).build(); - ClassModel conditionsClassModel = ClassModel.builder(Conditions.class).enableDiscriminator(true) - .build(); - ClassModel cappedListClassModel = ClassModel.builder(CappedList.class).enableDiscriminator(true) - .build(); - ClassModel testingRunClassModel = ClassModel.builder(TestingRun.class).enableDiscriminator(true) - .build(); - ClassModel testingRunResultClassModel = ClassModel.builder(TestingRunResult.class) - .enableDiscriminator(true).build(); - ClassModel testResultClassModel = ClassModel.builder(TestResult.class).enableDiscriminator(true) - .build(); - ClassModel multiExecTestResultClassModel = ClassModel.builder(MultiExecTestResult.class).enableDiscriminator(true) - .build(); - ClassModel genericTestResultClassModel = ClassModel.builder(GenericTestResult.class).enableDiscriminator(true) - .build(); - ClassModel authMechanismClassModel = ClassModel.builder(AuthMechanism.class) - .enableDiscriminator(true).build(); - ClassModel setupClassModel = ClassModel.builder(Setup.class) - .enableDiscriminator(true).build(); - ClassModel authParamClassModel = ClassModel.builder(AuthParam.class).enableDiscriminator(true) - .build(); - ClassModel hardcodedAuthParamClassModel = ClassModel.builder(HardcodedAuthParam.class) - .enableDiscriminator(true).build(); - ClassModel loginReqAuthParamClassModel = ClassModel.builder(LoginRequestAuthParam.class) - .enableDiscriminator(true).build(); - ClassModel testingEndpointsClassModel = ClassModel.builder(TestingEndpoints.class) - .enableDiscriminator(true).build(); - ClassModel customTestingEndpointsClassModel = ClassModel - .builder(CustomTestingEndpoints.class).enableDiscriminator(true).build(); - ClassModel allTestingEndpointsClassModel = ClassModel - .builder(AllTestingEndpoints.class).enableDiscriminator(true).build(); - ClassModel collectionWiseTestingEndpointsClassModel = ClassModel - .builder(CollectionWiseTestingEndpoints.class).enableDiscriminator(true).build(); - ClassModel workflowTestingEndpointsClassModel = ClassModel - .builder(WorkflowTestingEndpoints.class).enableDiscriminator(true).build(); - ClassModel workflowTestResultClassModel = ClassModel.builder(WorkflowTestResult.class) - .enableDiscriminator(true).build(); - ClassModel workflowTestClassModel = ClassModel.builder(WorkflowTest.class) - .enableDiscriminator(true).build(); - ClassModel cappedSetClassModel = ClassModel.builder(CappedSet.class).enableDiscriminator(true) - .build(); - ClassModel CustomWebhookClassModel = ClassModel.builder(CustomWebhook.class) - .enableDiscriminator(true).build(); - ClassModel WorkflowNodeDetailsClassModel = ClassModel.builder(WorkflowNodeDetails.class) - .enableDiscriminator(true).build(); - ClassModel CustomWebhookResultClassModel = ClassModel.builder(CustomWebhookResult.class) - .enableDiscriminator(true).build(); - ClassModel nodeResultClassModel = ClassModel - .builder(WorkflowTestResult.NodeResult.class).enableDiscriminator(true).build(); - ClassModel testingRunIssuesClassModel = ClassModel - .builder(TestingRunIssues.class).enableDiscriminator(true).build(); - ClassModel testingIssuesIdClassModel = ClassModel - .builder(TestingIssuesId.class).enableDiscriminator(true).build(); - ClassModel testSourceConfigClassModel = ClassModel - .builder(TestSourceConfig.class).enableDiscriminator(true).build(); - ClassModel endpointLogicalGroupClassModel = ClassModel - .builder(EndpointLogicalGroup.class).enableDiscriminator(true).build(); - ClassModel testRolesClassModel = ClassModel - .builder(TestRoles.class).enableDiscriminator(true).build(); - ClassModel logicalGroupTestingEndpointClassModel = ClassModel - .builder(LogicalGroupTestingEndpoint.class).enableDiscriminator(true).build(); - ClassModel customAuthTypeModel = ClassModel - .builder(CustomAuthType.class).enableDiscriminator(true).build(); - ClassModel containsPredicateClassModel = ClassModel - .builder(ContainsPredicate.class).enableDiscriminator(true).build(); - ClassModel notBelongsToPredicateClassModel = ClassModel - .builder(NotBelongsToPredicate.class).enableDiscriminator(true).build(); - ClassModel belongsToPredicateClassModel = ClassModel - .builder(BelongsToPredicate.class).enableDiscriminator(true).build(); - ClassModel yamlNodeDetails = ClassModel - .builder(YamlNodeDetails.class).enableDiscriminator(true).build(); - ClassModel unauthenticatedEndpointsClassModel = ClassModel - .builder(UnauthenticatedEndpoint.class).enableDiscriminator(true).build(); - ClassModel eventsExampleClassModel = ClassModel - .builder(EventsExample.class).enableDiscriminator(true).build(); - // ClassModel awsResourceModel = - // ClassModel.builder(AwsResource.class).enableDiscriminator(true) - // .build(); - ClassModel awsResourcesModel = ClassModel.builder(AwsResources.class).enableDiscriminator(true) - .build(); - ClassModel AktoDataTypeClassModel = ClassModel.builder(AktoDataType.class).enableDiscriminator(true).build(); - ClassModel testInfoClassModel = ClassModel.builder(TestInfo.class).enableDiscriminator(true).build(); - ClassModel bflaTestInfoClassModel = ClassModel.builder(BFLATestInfo.class).enableDiscriminator(true).build(); - ClassModel accessMatrixUrlToRoleClassModel = ClassModel.builder(AccessMatrixUrlToRole.class).enableDiscriminator(true).build(); - ClassModel accessMatrixTaskInfoClassModel = ClassModel.builder(AccessMatrixTaskInfo.class).enableDiscriminator(true).build(); - ClassModel loaderClassModel = ClassModel.builder(Loader.class).enableDiscriminator(true).build(); - ClassModel normalLoaderClassModel = ClassModel.builder(NormalLoader.class).enableDiscriminator(true).build(); - ClassModel postmanUploadLoaderClassModel = ClassModel.builder(PostmanUploadLoader.class).enableDiscriminator(true).build(); - ClassModel aktoGptConfigClassModel = ClassModel.builder(AktoGptConfig.class).enableDiscriminator(true).build(); + public static CodecRegistry createCodecRegistry() { + ClassModel configClassModel = + ClassModel.builder(Config.class).enableDiscriminator(true).build(); + ClassModel signupInfoClassModel = + ClassModel.builder(SignupInfo.class).enableDiscriminator(true).build(); + ClassModel apiAuthClassModel = + ClassModel.builder(APIAuth.class).enableDiscriminator(true).build(); + ClassModel attempResultModel = + ClassModel.builder(AttemptResult.class).enableDiscriminator(true).build(); + ClassModel urlTemplateModel = + ClassModel.builder(URLTemplate.class).enableDiscriminator(true).build(); + ClassModel pendingInviteCodeClassModel = + ClassModel.builder(PendingInviteCode.class).enableDiscriminator(true).build(); + ClassModel rbacClassModel = + ClassModel.builder(RBAC.class).enableDiscriminator(true).build(); + ClassModel singleTypeInfoClassModel = + ClassModel.builder(SingleTypeInfo.class).enableDiscriminator(true).build(); + ClassModel kafkaHealthMetricClassModel = + ClassModel.builder(KafkaHealthMetric.class).enableDiscriminator(true).build(); + ClassModel thirdPartyAccessClassModel = + ClassModel.builder(ThirdPartyAccess.class).enableDiscriminator(true).build(); + ClassModel credentialClassModel = + ClassModel.builder(Credential.class).enableDiscriminator(true).build(); + ClassModel apiTokenClassModel = + ClassModel.builder(ApiToken.class).enableDiscriminator(true).build(); + ClassModel apiInfoClassModel = + ClassModel.builder(ApiInfo.class).enableDiscriminator(true).build(); + ClassModel apiInfoKeyClassModel = + ClassModel.builder(ApiInfo.ApiInfoKey.class).enableDiscriminator(true).build(); + ClassModel customFilterClassModel = + ClassModel.builder(CustomFilter.class).enableDiscriminator(true).build(); + ClassModel fieldExistsFilterClassModel = + ClassModel.builder(FieldExistsFilter.class).enableDiscriminator(true).build(); + ClassModel responseCodeRuntimeFilterClassModel = + ClassModel.builder(ResponseCodeRuntimeFilter.class).enableDiscriminator(true).build(); + ; + ClassModel runtimeFilterClassModel = + ClassModel.builder(RuntimeFilter.class).enableDiscriminator(true).build(); + ClassModel filterSampleDataClassModel = + ClassModel.builder(FilterSampleData.class).enableDiscriminator(true).build(); + ClassModel accountSettingsClassModel = + ClassModel.builder(AccountSettings.class).enableDiscriminator(true).build(); + ClassModel predicateClassModel = + ClassModel.builder(Predicate.class).enableDiscriminator(true).build(); + ClassModel regexPredicateClassModel = + ClassModel.builder(RegexPredicate.class).enableDiscriminator(true).build(); + ClassModel startsWithPredicateClassModel = + ClassModel.builder(StartsWithPredicate.class).enableDiscriminator(true).build(); + ClassModel endsWithPredicateClassModel = + ClassModel.builder(EndsWithPredicate.class).enableDiscriminator(true).build(); + ClassModel equalsToPredicateClassModel = + ClassModel.builder(EqualsToPredicate.class).enableDiscriminator(true).build(); + ClassModel isNumberPredicateClassModel = + ClassModel.builder(IsNumberPredicate.class).enableDiscriminator(true).build(); + ClassModel conditionsClassModel = + ClassModel.builder(Conditions.class).enableDiscriminator(true).build(); + ClassModel cappedListClassModel = + ClassModel.builder(CappedList.class).enableDiscriminator(true).build(); + ClassModel testingRunClassModel = + ClassModel.builder(TestingRun.class).enableDiscriminator(true).build(); + ClassModel testingRunResultClassModel = + ClassModel.builder(TestingRunResult.class).enableDiscriminator(true).build(); + ClassModel testResultClassModel = + ClassModel.builder(TestResult.class).enableDiscriminator(true).build(); + ClassModel multiExecTestResultClassModel = + ClassModel.builder(MultiExecTestResult.class).enableDiscriminator(true).build(); + ClassModel genericTestResultClassModel = + ClassModel.builder(GenericTestResult.class).enableDiscriminator(true).build(); + ClassModel authMechanismClassModel = + ClassModel.builder(AuthMechanism.class).enableDiscriminator(true).build(); + ClassModel setupClassModel = + ClassModel.builder(Setup.class).enableDiscriminator(true).build(); + ClassModel authParamClassModel = + ClassModel.builder(AuthParam.class).enableDiscriminator(true).build(); + ClassModel hardcodedAuthParamClassModel = + ClassModel.builder(HardcodedAuthParam.class).enableDiscriminator(true).build(); + ClassModel loginReqAuthParamClassModel = + ClassModel.builder(LoginRequestAuthParam.class).enableDiscriminator(true).build(); + ClassModel testingEndpointsClassModel = + ClassModel.builder(TestingEndpoints.class).enableDiscriminator(true).build(); + ClassModel customTestingEndpointsClassModel = + ClassModel.builder(CustomTestingEndpoints.class).enableDiscriminator(true).build(); + ClassModel allTestingEndpointsClassModel = + ClassModel.builder(AllTestingEndpoints.class).enableDiscriminator(true).build(); + ClassModel collectionWiseTestingEndpointsClassModel = + ClassModel.builder(CollectionWiseTestingEndpoints.class).enableDiscriminator(true).build(); + ClassModel workflowTestingEndpointsClassModel = + ClassModel.builder(WorkflowTestingEndpoints.class).enableDiscriminator(true).build(); + ClassModel workflowTestResultClassModel = + ClassModel.builder(WorkflowTestResult.class).enableDiscriminator(true).build(); + ClassModel workflowTestClassModel = + ClassModel.builder(WorkflowTest.class).enableDiscriminator(true).build(); + ClassModel cappedSetClassModel = + ClassModel.builder(CappedSet.class).enableDiscriminator(true).build(); + ClassModel CustomWebhookClassModel = + ClassModel.builder(CustomWebhook.class).enableDiscriminator(true).build(); + ClassModel WorkflowNodeDetailsClassModel = + ClassModel.builder(WorkflowNodeDetails.class).enableDiscriminator(true).build(); + ClassModel CustomWebhookResultClassModel = + ClassModel.builder(CustomWebhookResult.class).enableDiscriminator(true).build(); + ClassModel nodeResultClassModel = + ClassModel.builder(WorkflowTestResult.NodeResult.class).enableDiscriminator(true).build(); + ClassModel testingRunIssuesClassModel = + ClassModel.builder(TestingRunIssues.class).enableDiscriminator(true).build(); + ClassModel testingIssuesIdClassModel = + ClassModel.builder(TestingIssuesId.class).enableDiscriminator(true).build(); + ClassModel testSourceConfigClassModel = + ClassModel.builder(TestSourceConfig.class).enableDiscriminator(true).build(); + ClassModel endpointLogicalGroupClassModel = + ClassModel.builder(EndpointLogicalGroup.class).enableDiscriminator(true).build(); + ClassModel testRolesClassModel = + ClassModel.builder(TestRoles.class).enableDiscriminator(true).build(); + ClassModel logicalGroupTestingEndpointClassModel = + ClassModel.builder(LogicalGroupTestingEndpoint.class).enableDiscriminator(true).build(); + ClassModel customAuthTypeModel = + ClassModel.builder(CustomAuthType.class).enableDiscriminator(true).build(); + ClassModel containsPredicateClassModel = + ClassModel.builder(ContainsPredicate.class).enableDiscriminator(true).build(); + ClassModel notBelongsToPredicateClassModel = + ClassModel.builder(NotBelongsToPredicate.class).enableDiscriminator(true).build(); + ClassModel belongsToPredicateClassModel = + ClassModel.builder(BelongsToPredicate.class).enableDiscriminator(true).build(); + ClassModel yamlNodeDetails = + ClassModel.builder(YamlNodeDetails.class).enableDiscriminator(true).build(); + ClassModel unauthenticatedEndpointsClassModel = + ClassModel.builder(UnauthenticatedEndpoint.class).enableDiscriminator(true).build(); + ClassModel eventsExampleClassModel = + ClassModel.builder(EventsExample.class).enableDiscriminator(true).build(); + // ClassModel awsResourceModel = + // ClassModel.builder(AwsResource.class).enableDiscriminator(true) + // .build(); + ClassModel awsResourcesModel = + ClassModel.builder(AwsResources.class).enableDiscriminator(true).build(); + ClassModel AktoDataTypeClassModel = + ClassModel.builder(AktoDataType.class).enableDiscriminator(true).build(); + ClassModel testInfoClassModel = + ClassModel.builder(TestInfo.class).enableDiscriminator(true).build(); + ClassModel bflaTestInfoClassModel = + ClassModel.builder(BFLATestInfo.class).enableDiscriminator(true).build(); + ClassModel accessMatrixUrlToRoleClassModel = + ClassModel.builder(AccessMatrixUrlToRole.class).enableDiscriminator(true).build(); + ClassModel accessMatrixTaskInfoClassModel = + ClassModel.builder(AccessMatrixTaskInfo.class).enableDiscriminator(true).build(); + ClassModel loaderClassModel = + ClassModel.builder(Loader.class).enableDiscriminator(true).build(); + ClassModel normalLoaderClassModel = + ClassModel.builder(NormalLoader.class).enableDiscriminator(true).build(); + ClassModel postmanUploadLoaderClassModel = + ClassModel.builder(PostmanUploadLoader.class).enableDiscriminator(true).build(); + ClassModel aktoGptConfigClassModel = + ClassModel.builder(AktoGptConfig.class).enableDiscriminator(true).build(); - ClassModel loginFlowStepsData = ClassModel.builder(LoginFlowStepsData.class) - .enableDiscriminator(true).build(); - ClassModel vulnerableRequestForTemplateClassModel = ClassModel.builder(VulnerableRequestForTemplate.class).enableDiscriminator(true).build(); - ClassModel trafficMetricsAlertClassModel = ClassModel.builder(TrafficMetricsAlert.class).enableDiscriminator(true).build(); - ClassModel jiraintegrationClassModel = ClassModel.builder(JiraIntegration.class).enableDiscriminator(true).build(); - ClassModel methodConditionClassModel = ClassModel.builder(MethodCondition.class).enableDiscriminator(true).build(); - ClassModel regexTestingEndpointsClassModel = ClassModel.builder(RegexTestingEndpoints.class).enableDiscriminator(true).build(); - ClassModel hostRegexTestingEndpointsClassModel = ClassModel.builder(HostRegexTestingEndpoints.class).enableDiscriminator(true).build(); - ClassModel dependencyNodeClassModel = ClassModel.builder(DependencyNode.class).enableDiscriminator(true).build(); - ClassModel paramInfoClassModel = ClassModel.builder(ParamInfo.class).enableDiscriminator(true).build(); - ClassModel nodeClassModel = ClassModel.builder(Node.class).enableDiscriminator(true).build(); - ClassModel connectionClassModel = ClassModel.builder(Connection.class).enableDiscriminator(true).build(); - ClassModel edgeClassModel = ClassModel.builder(Edge.class).enableDiscriminator(true).build(); - ClassModel cronTimersClassModel = ClassModel.builder(LastCronRunInfo.class) - .enableDiscriminator(true).build(); - ClassModel connectionInfoClassModel = ClassModel.builder(ConnectionInfo.class) - .enableDiscriminator(true).build(); - ClassModel testLibraryClassModel = ClassModel.builder(TestLibrary.class).enableDiscriminator(true).build(); + ClassModel loginFlowStepsData = + ClassModel.builder(LoginFlowStepsData.class).enableDiscriminator(true).build(); + ClassModel vulnerableRequestForTemplateClassModel = + ClassModel.builder(VulnerableRequestForTemplate.class).enableDiscriminator(true).build(); + ClassModel trafficMetricsAlertClassModel = + ClassModel.builder(TrafficMetricsAlert.class).enableDiscriminator(true).build(); + ClassModel jiraintegrationClassModel = + ClassModel.builder(JiraIntegration.class).enableDiscriminator(true).build(); + ClassModel methodConditionClassModel = + ClassModel.builder(MethodCondition.class).enableDiscriminator(true).build(); + ClassModel regexTestingEndpointsClassModel = + ClassModel.builder(RegexTestingEndpoints.class).enableDiscriminator(true).build(); + ClassModel hostRegexTestingEndpointsClassModel = + ClassModel.builder(HostRegexTestingEndpoints.class).enableDiscriminator(true).build(); + ClassModel dependencyNodeClassModel = + ClassModel.builder(DependencyNode.class).enableDiscriminator(true).build(); + ClassModel paramInfoClassModel = + ClassModel.builder(ParamInfo.class).enableDiscriminator(true).build(); + ClassModel nodeClassModel = + ClassModel.builder(Node.class).enableDiscriminator(true).build(); + ClassModel connectionClassModel = + ClassModel.builder(Connection.class).enableDiscriminator(true).build(); + ClassModel edgeClassModel = + ClassModel.builder(Edge.class).enableDiscriminator(true).build(); + ClassModel cronTimersClassModel = + ClassModel.builder(LastCronRunInfo.class).enableDiscriminator(true).build(); + ClassModel connectionInfoClassModel = + ClassModel.builder(ConnectionInfo.class).enableDiscriminator(true).build(); + ClassModel testLibraryClassModel = + ClassModel.builder(TestLibrary.class).enableDiscriminator(true).build(); - ClassModel UsageMetricClassModel = ClassModel.builder(UsageMetric.class).enableDiscriminator(true).build(); - ClassModel UsageMetricInfoClassModel = ClassModel.builder(UsageMetricInfo.class).enableDiscriminator(true).build(); - ClassModel UsageSyncClassModel = ClassModel.builder(UsageSync.class).enableDiscriminator(true).build(); - ClassModel OrganizationClassModel = ClassModel.builder(Organization.class).enableDiscriminator(true).build(); - ClassModel replaceDetailClassModel = ClassModel.builder(ReplaceDetail.class).enableDiscriminator(true).build(); - ClassModel modifyHostDetailClassModel = ClassModel.builder(ModifyHostDetail.class).enableDiscriminator(true).build(); - ClassModel fileUploadClassModel = ClassModel.builder(FileUpload.class).enableDiscriminator(true).build(); - ClassModel fileUploadLogClassModel = ClassModel.builder(FileUploadLog.class).enableDiscriminator(true).build(); - ClassModel codeAnalysisCollectionClassModel = ClassModel.builder(CodeAnalysisCollection.class).enableDiscriminator(true).build(); - ClassModel codeAnalysisApiLocationClassModel = ClassModel.builder(CodeAnalysisApiLocation.class).enableDiscriminator(true).build(); - ClassModel codeAnalysisApiInfoClassModel = ClassModel.builder(CodeAnalysisApiInfo.class).enableDiscriminator(true).build(); - ClassModel codeAnalysisApiInfoKeyClassModel = ClassModel.builder(CodeAnalysisApiInfo.CodeAnalysisApiInfoKey.class).enableDiscriminator(true).build(); - ClassModel riskScoreTestingEndpointsClassModel = ClassModel.builder(RiskScoreTestingEndpoints.class).enableDiscriminator(true).build(); - ClassModel OrganizationFlagsClassModel = ClassModel.builder(OrganizationFlags.class).enableDiscriminator(true).build(); - ClassModel sensitiveDataEndpointsClassModel = ClassModel.builder(SensitiveDataEndpoints.class).enableDiscriminator(true).build(); - ClassModel allApisGroupClassModel = ClassModel.builder(AllAPIsGroup.class).enableDiscriminator(true).build(); + ClassModel UsageMetricClassModel = + ClassModel.builder(UsageMetric.class).enableDiscriminator(true).build(); + ClassModel UsageMetricInfoClassModel = + ClassModel.builder(UsageMetricInfo.class).enableDiscriminator(true).build(); + ClassModel UsageSyncClassModel = + ClassModel.builder(UsageSync.class).enableDiscriminator(true).build(); + ClassModel OrganizationClassModel = + ClassModel.builder(Organization.class).enableDiscriminator(true).build(); + ClassModel replaceDetailClassModel = + ClassModel.builder(ReplaceDetail.class).enableDiscriminator(true).build(); + ClassModel modifyHostDetailClassModel = + ClassModel.builder(ModifyHostDetail.class).enableDiscriminator(true).build(); + ClassModel fileUploadClassModel = + ClassModel.builder(FileUpload.class).enableDiscriminator(true).build(); + ClassModel fileUploadLogClassModel = + ClassModel.builder(FileUploadLog.class).enableDiscriminator(true).build(); + ClassModel codeAnalysisCollectionClassModel = + ClassModel.builder(CodeAnalysisCollection.class).enableDiscriminator(true).build(); + ClassModel codeAnalysisApiLocationClassModel = + ClassModel.builder(CodeAnalysisApiLocation.class).enableDiscriminator(true).build(); + ClassModel codeAnalysisApiInfoClassModel = + ClassModel.builder(CodeAnalysisApiInfo.class).enableDiscriminator(true).build(); + ClassModel codeAnalysisApiInfoKeyClassModel = + ClassModel.builder(CodeAnalysisApiInfo.CodeAnalysisApiInfoKey.class) + .enableDiscriminator(true) + .build(); + ClassModel riskScoreTestingEndpointsClassModel = + ClassModel.builder(RiskScoreTestingEndpoints.class).enableDiscriminator(true).build(); + ClassModel OrganizationFlagsClassModel = + ClassModel.builder(OrganizationFlags.class).enableDiscriminator(true).build(); + ClassModel sensitiveDataEndpointsClassModel = + ClassModel.builder(SensitiveDataEndpoints.class).enableDiscriminator(true).build(); + ClassModel allApisGroupClassModel = + ClassModel.builder(AllAPIsGroup.class).enableDiscriminator(true).build(); - ClassModel RuntimeMetricsClassModel = ClassModel.builder(RuntimeMetrics.class).enableDiscriminator(true).build(); - ClassModel codeAnalysisApiModel = ClassModel.builder(CodeAnalysisApi.class).enableDiscriminator(true).build(); - ClassModel codeAnalysisRepoModel = ClassModel.builder(CodeAnalysisRepo.class).enableDiscriminator(true).build(); - ClassModel historicalDataClassModel = ClassModel.builder(HistoricalData.class).enableDiscriminator(true).build(); - ClassModel configSettingClassModel = ClassModel.builder(TestConfigsAdvancedSettings.class).enableDiscriminator(true).build(); - ClassModel configSettingsConditionTypeClassModel = ClassModel.builder(ConditionsType.class).enableDiscriminator(true).build(); - CodecRegistry pojoCodecRegistry = fromProviders(PojoCodecProvider.builder().register( - configClassModel, signupInfoClassModel, apiAuthClassModel, attempResultModel, urlTemplateModel, - pendingInviteCodeClassModel, rbacClassModel, kafkaHealthMetricClassModel, singleTypeInfoClassModel, - thirdPartyAccessClassModel, credentialClassModel, apiTokenClassModel, apiInfoClassModel, - apiInfoKeyClassModel, customFilterClassModel, runtimeFilterClassModel, filterSampleDataClassModel, - predicateClassModel, conditionsClassModel, regexPredicateClassModel, startsWithPredicateClassModel, - endsWithPredicateClassModel, - fieldExistsFilterClassModel, accountSettingsClassModel, responseCodeRuntimeFilterClassModel, - cappedListClassModel, - equalsToPredicateClassModel, isNumberPredicateClassModel, testingRunClassModel, - testingRunResultClassModel, testResultClassModel, genericTestResultClassModel, - authMechanismClassModel, authParamClassModel, hardcodedAuthParamClassModel, loginReqAuthParamClassModel, - testingEndpointsClassModel, customTestingEndpointsClassModel, collectionWiseTestingEndpointsClassModel, - workflowTestingEndpointsClassModel, workflowTestResultClassModel, - cappedSetClassModel, CustomWebhookClassModel, WorkflowNodeDetailsClassModel, CustomWebhookResultClassModel, - nodeResultClassModel, awsResourcesModel, AktoDataTypeClassModel, testingRunIssuesClassModel, - testingIssuesIdClassModel, testSourceConfigClassModel, endpointLogicalGroupClassModel, testRolesClassModel, - logicalGroupTestingEndpointClassModel, testInfoClassModel, bflaTestInfoClassModel, customAuthTypeModel, - containsPredicateClassModel, notBelongsToPredicateClassModel, belongsToPredicateClassModel, loginFlowStepsData, - accessMatrixUrlToRoleClassModel, accessMatrixTaskInfoClassModel, - loaderClassModel, normalLoaderClassModel, postmanUploadLoaderClassModel, aktoGptConfigClassModel, - vulnerableRequestForTemplateClassModel, trafficMetricsAlertClassModel,jiraintegrationClassModel, setupClassModel, - cronTimersClassModel, connectionInfoClassModel, testLibraryClassModel, - methodConditionClassModel, regexTestingEndpointsClassModel, hostRegexTestingEndpointsClassModel, allTestingEndpointsClassModel, - UsageMetricClassModel, UsageMetricInfoClassModel, UsageSyncClassModel, OrganizationClassModel, - yamlNodeDetails, multiExecTestResultClassModel, workflowTestClassModel, dependencyNodeClassModel, paramInfoClassModel, - nodeClassModel, connectionClassModel, edgeClassModel, replaceDetailClassModel, modifyHostDetailClassModel, fileUploadClassModel - ,fileUploadLogClassModel, codeAnalysisCollectionClassModel, codeAnalysisApiLocationClassModel, codeAnalysisApiInfoClassModel, codeAnalysisApiInfoKeyClassModel, - riskScoreTestingEndpointsClassModel, OrganizationFlagsClassModel, sensitiveDataEndpointsClassModel, unauthenticatedEndpointsClassModel, allApisGroupClassModel, - eventsExampleClassModel, RuntimeMetricsClassModel, codeAnalysisRepoModel, codeAnalysisApiModel, historicalDataClassModel, configSettingClassModel, configSettingsConditionTypeClassModel).automatic(true).build()); + ClassModel RuntimeMetricsClassModel = + ClassModel.builder(RuntimeMetrics.class).enableDiscriminator(true).build(); + ClassModel codeAnalysisApiModel = + ClassModel.builder(CodeAnalysisApi.class).enableDiscriminator(true).build(); + ClassModel codeAnalysisRepoModel = + ClassModel.builder(CodeAnalysisRepo.class).enableDiscriminator(true).build(); + ClassModel historicalDataClassModel = + ClassModel.builder(HistoricalData.class).enableDiscriminator(true).build(); + ClassModel configSettingClassModel = + ClassModel.builder(TestConfigsAdvancedSettings.class).enableDiscriminator(true).build(); + ClassModel configSettingsConditionTypeClassModel = + ClassModel.builder(ConditionsType.class).enableDiscriminator(true).build(); + CodecRegistry pojoCodecRegistry = + fromProviders( + PojoCodecProvider.builder() + .register( + configClassModel, + signupInfoClassModel, + apiAuthClassModel, + attempResultModel, + urlTemplateModel, + pendingInviteCodeClassModel, + rbacClassModel, + kafkaHealthMetricClassModel, + singleTypeInfoClassModel, + thirdPartyAccessClassModel, + credentialClassModel, + apiTokenClassModel, + apiInfoClassModel, + apiInfoKeyClassModel, + customFilterClassModel, + runtimeFilterClassModel, + filterSampleDataClassModel, + predicateClassModel, + conditionsClassModel, + regexPredicateClassModel, + startsWithPredicateClassModel, + endsWithPredicateClassModel, + fieldExistsFilterClassModel, + accountSettingsClassModel, + responseCodeRuntimeFilterClassModel, + cappedListClassModel, + equalsToPredicateClassModel, + isNumberPredicateClassModel, + testingRunClassModel, + testingRunResultClassModel, + testResultClassModel, + genericTestResultClassModel, + authMechanismClassModel, + authParamClassModel, + hardcodedAuthParamClassModel, + loginReqAuthParamClassModel, + testingEndpointsClassModel, + customTestingEndpointsClassModel, + collectionWiseTestingEndpointsClassModel, + workflowTestingEndpointsClassModel, + workflowTestResultClassModel, + cappedSetClassModel, + CustomWebhookClassModel, + WorkflowNodeDetailsClassModel, + CustomWebhookResultClassModel, + nodeResultClassModel, + awsResourcesModel, + AktoDataTypeClassModel, + testingRunIssuesClassModel, + testingIssuesIdClassModel, + testSourceConfigClassModel, + endpointLogicalGroupClassModel, + testRolesClassModel, + logicalGroupTestingEndpointClassModel, + testInfoClassModel, + bflaTestInfoClassModel, + customAuthTypeModel, + containsPredicateClassModel, + notBelongsToPredicateClassModel, + belongsToPredicateClassModel, + loginFlowStepsData, + accessMatrixUrlToRoleClassModel, + accessMatrixTaskInfoClassModel, + loaderClassModel, + normalLoaderClassModel, + postmanUploadLoaderClassModel, + aktoGptConfigClassModel, + vulnerableRequestForTemplateClassModel, + trafficMetricsAlertClassModel, + jiraintegrationClassModel, + setupClassModel, + cronTimersClassModel, + connectionInfoClassModel, + testLibraryClassModel, + methodConditionClassModel, + regexTestingEndpointsClassModel, + hostRegexTestingEndpointsClassModel, + allTestingEndpointsClassModel, + UsageMetricClassModel, + UsageMetricInfoClassModel, + UsageSyncClassModel, + OrganizationClassModel, + yamlNodeDetails, + multiExecTestResultClassModel, + workflowTestClassModel, + dependencyNodeClassModel, + paramInfoClassModel, + nodeClassModel, + connectionClassModel, + edgeClassModel, + replaceDetailClassModel, + modifyHostDetailClassModel, + fileUploadClassModel, + fileUploadLogClassModel, + codeAnalysisCollectionClassModel, + codeAnalysisApiLocationClassModel, + codeAnalysisApiInfoClassModel, + codeAnalysisApiInfoKeyClassModel, + riskScoreTestingEndpointsClassModel, + OrganizationFlagsClassModel, + sensitiveDataEndpointsClassModel, + unauthenticatedEndpointsClassModel, + allApisGroupClassModel, + eventsExampleClassModel, + RuntimeMetricsClassModel, + codeAnalysisRepoModel, + codeAnalysisApiModel, + historicalDataClassModel, + configSettingClassModel, + configSettingsConditionTypeClassModel) + .automatic(true) + .build()); - final CodecRegistry customEnumCodecs = CodecRegistries.fromCodecs( - new EnumCodec<>(Conditions.Operator.class), - new EnumCodec<>(SingleTypeInfo.SuperType.class), - new EnumCodec<>(Method.class), - new EnumCodec<>(RBAC.Role.class), - new EnumCodec<>(Credential.Type.class), - new EnumCodec<>(ApiToken.Utility.class), - new EnumCodec<>(ApiInfo.AuthType.class), - new EnumCodec<>(ApiInfo.ApiAccessType.class), - new EnumCodec<>(TestResult.TestError.class), - new EnumCodec<>(AuthParam.Location.class), - new EnumCodec<>(TestingEndpoints.Type.class), - new EnumCodec<>(TestingRun.State.class), - new EnumCodec<>(AccountSettings.SetupType.class), - new EnumCodec<>(WorkflowNodeDetails.Type.class), - new EnumCodec<>(SingleTypeInfo.Domain.class), - new EnumCodec<>(CustomWebhook.ActiveStatus.class), - new EnumCodec<>(TestResult.Confidence.class), - new EnumCodec<>(SingleTypeInfo.Position.class), - new EnumCodec<>(TestResult.Confidence.class), - new EnumCodec<>(GlobalEnums.TestRunIssueStatus.class), - new EnumCodec<>(GlobalEnums.TestErrorSource.class), - new EnumCodec<>(GlobalEnums.TestCategory.class), - new EnumCodec<>(GlobalEnums.IssueTags.class), - new EnumCodec<>(GlobalEnums.Severity.class), - new EnumCodec<>(TrafficMetrics.Name.class), - new EnumCodec<>(Loader.Type.class), - new EnumCodec<>(CustomWebhook.WebhookOptions.class), - new EnumCodec<>(GlobalEnums.YamlTemplateSource.class), - new EnumCodec<>(AktoGptConfigState.class), - new EnumCodec<>(CustomWebhook.WebhookOptions.class), - new EnumCodec<>(TestingEndpoints.Operator.class), - new EnumCodec<>(MetricTypes.class), - new EnumCodec<>(User.AktoUIMode.class), - new EnumCodec<>(TrafficMetricsAlert.FilterType.class), - new EnumCodec<>(KVPair.KVType.class), - new EnumCodec<>(ApiCollection.ENV_TYPE.class), - new EnumCodec<>(FileUpload.UploadType.class), - new EnumCodec<>(FileUpload.UploadStatus.class), - new EnumCodec<>(FileUploadLog.UploadLogStatus.class), - new EnumCodec<>(TestCollectionProperty.Id.class), - new EnumCodec<>(CustomAuthType.TypeOfToken.class), - new EnumCodec<>(TrafficAlerts.ALERT_TYPE.class), - new EnumCodec<>(ApiInfo.ApiType.class), - new EnumCodec<>(CodeAnalysisRepo.SourceCodeType.class) - ); + final CodecRegistry customEnumCodecs = + CodecRegistries.fromCodecs( + new EnumCodec<>(Conditions.Operator.class), + new EnumCodec<>(SingleTypeInfo.SuperType.class), + new EnumCodec<>(Method.class), + new EnumCodec<>(RBAC.Role.class), + new EnumCodec<>(Credential.Type.class), + new EnumCodec<>(ApiToken.Utility.class), + new EnumCodec<>(ApiInfo.AuthType.class), + new EnumCodec<>(ApiInfo.ApiAccessType.class), + new EnumCodec<>(TestResult.TestError.class), + new EnumCodec<>(AuthParam.Location.class), + new EnumCodec<>(TestingEndpoints.Type.class), + new EnumCodec<>(TestingRun.State.class), + new EnumCodec<>(AccountSettings.SetupType.class), + new EnumCodec<>(WorkflowNodeDetails.Type.class), + new EnumCodec<>(SingleTypeInfo.Domain.class), + new EnumCodec<>(CustomWebhook.ActiveStatus.class), + new EnumCodec<>(TestResult.Confidence.class), + new EnumCodec<>(SingleTypeInfo.Position.class), + new EnumCodec<>(TestResult.Confidence.class), + new EnumCodec<>(GlobalEnums.TestRunIssueStatus.class), + new EnumCodec<>(GlobalEnums.TestErrorSource.class), + new EnumCodec<>(GlobalEnums.TestCategory.class), + new EnumCodec<>(GlobalEnums.IssueTags.class), + new EnumCodec<>(GlobalEnums.Severity.class), + new EnumCodec<>(TrafficMetrics.Name.class), + new EnumCodec<>(Loader.Type.class), + new EnumCodec<>(CustomWebhook.WebhookOptions.class), + new EnumCodec<>(GlobalEnums.YamlTemplateSource.class), + new EnumCodec<>(AktoGptConfigState.class), + new EnumCodec<>(CustomWebhook.WebhookOptions.class), + new EnumCodec<>(TestingEndpoints.Operator.class), + new EnumCodec<>(MetricTypes.class), + new EnumCodec<>(User.AktoUIMode.class), + new EnumCodec<>(TrafficMetricsAlert.FilterType.class), + new EnumCodec<>(KVPair.KVType.class), + new EnumCodec<>(ApiCollection.ENV_TYPE.class), + new EnumCodec<>(FileUpload.UploadType.class), + new EnumCodec<>(FileUpload.UploadStatus.class), + new EnumCodec<>(FileUploadLog.UploadLogStatus.class), + new EnumCodec<>(TestCollectionProperty.Id.class), + new EnumCodec<>(CustomAuthType.TypeOfToken.class), + new EnumCodec<>(TrafficAlerts.ALERT_TYPE.class), + new EnumCodec<>(ApiInfo.ApiType.class), + new EnumCodec<>(CodeAnalysisRepo.SourceCodeType.class)); - return fromRegistries(MongoClientSettings.getDefaultCodecRegistry(), pojoCodecRegistry, - customEnumCodecs); - } + return fromRegistries( + MongoClientSettings.getDefaultCodecRegistry(), pojoCodecRegistry, customEnumCodecs); + } - public static void init(ConnectionString connectionString, ReadPreference readPreference, WriteConcern writeConcern) { - DbMode.refreshDbType(connectionString.getConnectionString()); - logger.info("DB type: {}", DbMode.dbType); - DbMode.refreshSetupType(connectionString); - logger.info("DB setup type: {}", DbMode.setupType); + public static MongoClient createMongoClient( + ConnectionString connectionString, ReadPreference readPreference, WriteConcern writeConcern) { + DbMode.refreshDbType(connectionString.getConnectionString()); + logger.info("DB type: {}", DbMode.dbType); + DbMode.refreshSetupType(connectionString); + logger.info("DB setup type: {}", DbMode.setupType); - CodecRegistry codecRegistry = createCodecRegistry(); + CodecRegistry codecRegistry = createCodecRegistry(); - MongoClientSettings clientSettings = MongoClientSettings.builder() - .readPreference(readPreference) - .writeConcern(writeConcern) - .applyConnectionString(connectionString) - .codecRegistry(codecRegistry) - .build(); + MongoClientSettings clientSettings = + MongoClientSettings.builder() + .readPreference(readPreference) + .writeConcern(writeConcern) + .applyConnectionString(connectionString) + .codecRegistry(codecRegistry) + .build(); - clients[0] = MongoClients.create(clientSettings); - } - public static void init(ConnectionString connectionString) { - init(connectionString, ReadPreference.secondary(), WriteConcern.ACKNOWLEDGED); - } + return MongoClients.create(clientSettings); + } - public static void createIndices() { - try { - TestingRunResultDao.instance.convertToCappedCollection(); - } catch (Exception e) { - logger.error("Error while converting TestingRunResults to capped collection: " + e.getMessage()); - } + public static void init( + ConnectionString connectionString, ReadPreference readPreference, WriteConcern writeConcern) { + clients[0] = createMongoClient(connectionString, readPreference, writeConcern); + } - OrganizationsDao.createIndexIfAbsent(); - UsageMetricsDao.createIndexIfAbsent(); - SingleTypeInfoDao.instance.createIndicesIfAbsent(); - TrafficMetricsDao.instance.createIndicesIfAbsent(); - TestRolesDao.instance.createIndicesIfAbsent(); - UsersDao.instance.createIndicesIfAbsent(); - AccountsDao.instance.createIndexIfAbsent(); + public static void init(ConnectionString connectionString) { + init(connectionString, ReadPreference.secondary(), WriteConcern.ACKNOWLEDGED); + } - ApiInfoDao.instance.createIndicesIfAbsent(); - RuntimeLogsDao.instance.createIndicesIfAbsent(); - LogsDao.instance.createIndicesIfAbsent(); - DashboardLogsDao.instance.createIndicesIfAbsent(); - AnalyserLogsDao.instance.createIndicesIfAbsent(); - SampleDataDao.instance.createIndicesIfAbsent(); - LoadersDao.instance.createIndicesIfAbsent(); - TestingRunResultDao.instance.createIndicesIfAbsent(); - TestingRunResultSummariesDao.instance.createIndicesIfAbsent(); - TestingRunDao.instance.createIndicesIfAbsent(); - TestingRunIssuesDao.instance.createIndicesIfAbsent(); - ApiCollectionsDao.instance.createIndicesIfAbsent(); - ActivitiesDao.instance.createIndicesIfAbsent(); - DependencyNodeDao.instance.createIndicesIfAbsent(); - DependencyFlowNodesDao.instance.createIndicesIfAbsent(); - CodeAnalysisCollectionDao.instance.createIndicesIfAbsent(); - CodeAnalysisApiInfoDao.instance.createIndicesIfAbsent(); - RBACDao.instance.createIndicesIfAbsent(); - TrafficAlertsDao.instance.createIndicesIfAbsent(); - RuntimeMetricsDao.instance.createIndicesIfAbsent(); - ApiAuditLogsDao.instance.createIndicesIfAbsent(); + public static void createIndices() { + try { + TestingRunResultDao.instance.convertToCappedCollection(); + } catch (Exception e) { + logger.error( + "Error while converting TestingRunResults to capped collection: " + e.getMessage()); } + OrganizationsDao.createIndexIfAbsent(); + UsageMetricsDao.createIndexIfAbsent(); + SingleTypeInfoDao.instance.createIndicesIfAbsent(); + TrafficMetricsDao.instance.createIndicesIfAbsent(); + TestRolesDao.instance.createIndicesIfAbsent(); + UsersDao.instance.createIndicesIfAbsent(); + AccountsDao.instance.createIndexIfAbsent(); + + ApiInfoDao.instance.createIndicesIfAbsent(); + RuntimeLogsDao.instance.createIndicesIfAbsent(); + LogsDao.instance.createIndicesIfAbsent(); + DashboardLogsDao.instance.createIndicesIfAbsent(); + AnalyserLogsDao.instance.createIndicesIfAbsent(); + SampleDataDao.instance.createIndicesIfAbsent(); + LoadersDao.instance.createIndicesIfAbsent(); + TestingRunResultDao.instance.createIndicesIfAbsent(); + TestingRunResultSummariesDao.instance.createIndicesIfAbsent(); + TestingRunDao.instance.createIndicesIfAbsent(); + TestingRunIssuesDao.instance.createIndicesIfAbsent(); + ApiCollectionsDao.instance.createIndicesIfAbsent(); + ActivitiesDao.instance.createIndicesIfAbsent(); + DependencyNodeDao.instance.createIndicesIfAbsent(); + DependencyFlowNodesDao.instance.createIndicesIfAbsent(); + CodeAnalysisCollectionDao.instance.createIndicesIfAbsent(); + CodeAnalysisApiInfoDao.instance.createIndicesIfAbsent(); + RBACDao.instance.createIndicesIfAbsent(); + TrafficAlertsDao.instance.createIndicesIfAbsent(); + RuntimeMetricsDao.instance.createIndicesIfAbsent(); + ApiAuditLogsDao.instance.createIndicesIfAbsent(); + } } diff --git a/libs/dao/src/main/java/com/akto/dao/api_protection_parse_layer/AggregationLayerParser.java b/libs/dao/src/main/java/com/akto/dao/api_protection_parse_layer/AggregationLayerParser.java new file mode 100644 index 0000000000..90af26affe --- /dev/null +++ b/libs/dao/src/main/java/com/akto/dao/api_protection_parse_layer/AggregationLayerParser.java @@ -0,0 +1,37 @@ +package com.akto.dao.api_protection_parse_layer; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import com.akto.dto.api_protection_parse_layer.AggregationRules; +import com.akto.dto.api_protection_parse_layer.Rule; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class AggregationLayerParser { + + ObjectMapper objectMapper = new ObjectMapper(); + + public AggregationLayerParser() { + } + + public AggregationRules parse(Map aggregationRules) throws Exception { + + List rules = new ArrayList<>(); + AggregationRules aggRules = new AggregationRules(rules); + + try { + for (Object aggObj: (List) aggregationRules.get("aggregation_rules")) { + Map aggObjMap = (Map) aggObj; + Rule rule = objectMapper.convertValue(aggObjMap.get("rule"), Rule.class); + rules.add(rule); + } + aggRules.setRule(rules); + } catch (Exception e) { + throw e; + } + + return aggRules; + } + +} diff --git a/libs/dao/src/main/java/com/akto/dao/monitoring/FilterYamlTemplateDao.java b/libs/dao/src/main/java/com/akto/dao/monitoring/FilterYamlTemplateDao.java index 8a898c387c..1e6ad20238 100644 --- a/libs/dao/src/main/java/com/akto/dao/monitoring/FilterYamlTemplateDao.java +++ b/libs/dao/src/main/java/com/akto/dao/monitoring/FilterYamlTemplateDao.java @@ -13,17 +13,23 @@ public class FilterYamlTemplateDao extends AccountsContextDao { public static final FilterYamlTemplateDao instance = new FilterYamlTemplateDao(); - public Map fetchFilterConfig(boolean includeYamlContent, boolean shouldParseExecutor) { + public Map fetchFilterConfig( + boolean includeYamlContent, boolean shouldParseExecutor) { List yamlTemplates = FilterYamlTemplateDao.instance.findAll(Filters.empty()); return fetchFilterConfig(includeYamlContent, yamlTemplates, shouldParseExecutor); } - public Map fetchFilterConfig(boolean includeYamlContent, List yamlTemplates, boolean shouldParseExecutor) { + public static Map fetchFilterConfig( + boolean includeYamlContent, + List yamlTemplates, + boolean shouldParseExecutor) { Map filterConfigMap = new HashMap<>(); for (YamlTemplate yamlTemplate : yamlTemplates) { try { if (yamlTemplate != null) { - FilterConfig filterConfig = FilterConfigYamlParser.parseTemplate(yamlTemplate.getContent(), shouldParseExecutor); + FilterConfig filterConfig = + FilterConfigYamlParser.parseTemplate( + yamlTemplate.getContent(), shouldParseExecutor); filterConfig.setAuthor(yamlTemplate.getAuthor()); filterConfig.setCreatedAt(yamlTemplate.getCreatedAt()); filterConfig.setUpdatedAt(yamlTemplate.getUpdatedAt()); diff --git a/libs/dao/src/main/java/com/akto/dto/OriginalHttpRequest.java b/libs/dao/src/main/java/com/akto/dto/OriginalHttpRequest.java index f6c85ebc52..952469ac4b 100644 --- a/libs/dao/src/main/java/com/akto/dto/OriginalHttpRequest.java +++ b/libs/dao/src/main/java/com/akto/dto/OriginalHttpRequest.java @@ -83,6 +83,24 @@ public void buildFromSampleMessage(String message) { this.headers = buildHeadersMap(json, "requestHeaders"); } + public void buildFromSampleMessageNew(HttpResponseParams responseParam) { + String rawUrl = responseParam.getRequestParams().getURL(); + String[] rawUrlArr = rawUrl.split("\\?"); + this.url = rawUrlArr[0]; + if (rawUrlArr.length > 1) { + this.queryParams = rawUrlArr[1]; + } + + this.type = responseParam.getRequestParams().type; + + this.method = responseParam.getRequestParams().getMethod(); + + String requestPayload = responseParam.getRequestParams().getPayload(); + this.body = requestPayload.trim(); + + this.headers = responseParam.getRequestParams().getHeaders(); + } + public String getJsonRequestBody() { return HttpRequestResponseUtils.rawToJsonString(this.body, this.headers); } diff --git a/libs/dao/src/main/java/com/akto/dto/OriginalHttpResponse.java b/libs/dao/src/main/java/com/akto/dto/OriginalHttpResponse.java index 1d011082a2..5a058ac5a9 100644 --- a/libs/dao/src/main/java/com/akto/dto/OriginalHttpResponse.java +++ b/libs/dao/src/main/java/com/akto/dto/OriginalHttpResponse.java @@ -1,6 +1,8 @@ package com.akto.dto; import com.akto.util.HttpRequestResponseUtils; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; import com.google.gson.Gson; import org.apache.commons.lang3.math.NumberUtils; @@ -43,6 +45,13 @@ public void buildFromSampleMessage(String message) { this.statusCode = Integer.parseInt(obj.toString()); } + public void buildFromSampleMessageNew(HttpResponseParams responseParam) { + String responsePayload = responseParam.getPayload(); + this.body = responsePayload != null ? responsePayload.trim() : null; + this.headers = responseParam.getHeaders(); + this.statusCode = responseParam.getStatusCode(); + } + public void addHeaderFromLine(String line) { if (this.headers == null || this.headers.isEmpty()) { this.headers = new HashMap<>(); diff --git a/libs/dao/src/main/java/com/akto/dto/RawApi.java b/libs/dao/src/main/java/com/akto/dto/RawApi.java index bbc8b9488c..b76ecbd93b 100644 --- a/libs/dao/src/main/java/com/akto/dto/RawApi.java +++ b/libs/dao/src/main/java/com/akto/dto/RawApi.java @@ -7,6 +7,8 @@ import java.util.Map; import com.akto.dto.type.RequestTemplate; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; import com.mongodb.BasicDBList; import com.fasterxml.jackson.databind.ObjectMapper; import com.mongodb.BasicDBObject; @@ -55,6 +57,16 @@ public static RawApi buildFromMessage(String message) { return new RawApi(request, response, message); } + public static RawApi buildFromMessageNew(HttpResponseParams responseParam) { + OriginalHttpRequest request = new OriginalHttpRequest(); + request.buildFromSampleMessageNew(responseParam); + + OriginalHttpResponse response = new OriginalHttpResponse(); + response.buildFromSampleMessageNew(responseParam); + + return new RawApi(request, response, ""); + } + public BasicDBObject fetchReqPayload() { OriginalHttpRequest req = this.getRequest(); String reqBody = req.getBody(); diff --git a/libs/dao/src/main/java/com/akto/dto/api_protection_parse_layer/AggregationRules.java b/libs/dao/src/main/java/com/akto/dto/api_protection_parse_layer/AggregationRules.java new file mode 100644 index 0000000000..18a8602009 --- /dev/null +++ b/libs/dao/src/main/java/com/akto/dto/api_protection_parse_layer/AggregationRules.java @@ -0,0 +1,24 @@ +package com.akto.dto.api_protection_parse_layer; + +import java.util.List; + +public class AggregationRules { + + private List rule; + + public AggregationRules() { + } + + public AggregationRules(List rule) { + this.rule = rule; + } + + public List getRule() { + return rule; + } + + public void setRule(List rule) { + this.rule = rule; + } + +} diff --git a/libs/dao/src/main/java/com/akto/dto/api_protection_parse_layer/Condition.java b/libs/dao/src/main/java/com/akto/dto/api_protection_parse_layer/Condition.java new file mode 100644 index 0000000000..bcb7a906e4 --- /dev/null +++ b/libs/dao/src/main/java/com/akto/dto/api_protection_parse_layer/Condition.java @@ -0,0 +1,31 @@ +package com.akto.dto.api_protection_parse_layer; + +public class Condition { + + private int matchCount; + private int windowThreshold; + // private String operation; + // private float value; + + public Condition() { + } + + public Condition(int matchCount, int windowThreshold) { + this.matchCount = matchCount; + this.windowThreshold = windowThreshold; + } + + public int getMatchCount() { + return matchCount; + } + public void setMatchCount(int matchCount) { + this.matchCount = matchCount; + } + public int getWindowThreshold() { + return windowThreshold; + } + public void setWindowThreshold(int windowThreshold) { + this.windowThreshold = windowThreshold; + } + // private List actions; +} diff --git a/libs/dao/src/main/java/com/akto/dto/api_protection_parse_layer/Rule.java b/libs/dao/src/main/java/com/akto/dto/api_protection_parse_layer/Rule.java new file mode 100644 index 0000000000..50fc2422a8 --- /dev/null +++ b/libs/dao/src/main/java/com/akto/dto/api_protection_parse_layer/Rule.java @@ -0,0 +1,31 @@ +package com.akto.dto.api_protection_parse_layer; + +public class Rule { + + String name; + Condition condition; + + public Rule() { + } + + public Rule(String name, Condition condition) { + this.name = name; + this.condition = condition; + } + + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public Condition getCondition() { + return condition; + } + public void setCondition(Condition condition) { + this.condition = condition; + } + + + +} diff --git a/libs/protobuf/.gitignore b/libs/protobuf/.gitignore index 9b21cfdc49..7589473dd1 100644 --- a/libs/protobuf/.gitignore +++ b/libs/protobuf/.gitignore @@ -1,2 +1 @@ src/main/java/com/akto/proto/generated - diff --git a/libs/protobuf/src/main/java/com/akto/proto/http_response_param/v1/HttpResponseParam.java b/libs/protobuf/src/main/java/com/akto/proto/http_response_param/v1/HttpResponseParam.java new file mode 100644 index 0000000000..aa3413cf0b --- /dev/null +++ b/libs/protobuf/src/main/java/com/akto/proto/http_response_param/v1/HttpResponseParam.java @@ -0,0 +1,3198 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// NO CHECKED-IN PROTOBUF GENCODE +// source: threat_detection/message/http_response_param/v1/http_response_param.proto +// Protobuf Java Version: 4.29.2 + +package com.akto.proto.http_response_param.v1; + +/** Protobuf type {@code threat_detection.message.http_response_param.v1.HttpResponseParam} */ +public final class HttpResponseParam extends com.google.protobuf.GeneratedMessage + implements + // @@protoc_insertion_point(message_implements:threat_detection.message.http_response_param.v1.HttpResponseParam) + HttpResponseParamOrBuilder { + private static final long serialVersionUID = 0L; + + static { + com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( + com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, + /* major= */ 4, + /* minor= */ 29, + /* patch= */ 2, + /* suffix= */ "", + HttpResponseParam.class.getName()); + } + + // Use HttpResponseParam.newBuilder() to construct. + private HttpResponseParam(com.google.protobuf.GeneratedMessage.Builder builder) { + super(builder); + } + + private HttpResponseParam() { + method_ = ""; + path_ = ""; + type_ = ""; + requestPayload_ = ""; + status_ = ""; + responsePayload_ = ""; + aktoAccountId_ = ""; + ip_ = ""; + destIp_ = ""; + direction_ = ""; + source_ = ""; + aktoVxlanId_ = ""; + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.akto.proto.http_response_param.v1.HttpResponseParamProto + .internal_static_threat_detection_message_http_response_param_v1_HttpResponseParam_descriptor; + } + + @SuppressWarnings({"rawtypes"}) + @java.lang.Override + protected com.google.protobuf.MapFieldReflectionAccessor internalGetMapFieldReflection( + int number) { + switch (number) { + case 4: + return internalGetRequestHeaders(); + case 9: + return internalGetResponseHeaders(); + default: + throw new RuntimeException("Invalid map field number: " + number); + } + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.akto.proto.http_response_param.v1.HttpResponseParamProto + .internal_static_threat_detection_message_http_response_param_v1_HttpResponseParam_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.akto.proto.http_response_param.v1.HttpResponseParam.class, + com.akto.proto.http_response_param.v1.HttpResponseParam.Builder.class); + } + + public static final int METHOD_FIELD_NUMBER = 1; + + @SuppressWarnings("serial") + private volatile java.lang.Object method_ = ""; + + /** + * string method = 1 [json_name = "method"]; + * + * @return The method. + */ + @java.lang.Override + public java.lang.String getMethod() { + java.lang.Object ref = method_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + method_ = s; + return s; + } + } + + /** + * string method = 1 [json_name = "method"]; + * + * @return The bytes for method. + */ + @java.lang.Override + public com.google.protobuf.ByteString getMethodBytes() { + java.lang.Object ref = method_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + method_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int PATH_FIELD_NUMBER = 2; + + @SuppressWarnings("serial") + private volatile java.lang.Object path_ = ""; + + /** + * string path = 2 [json_name = "path"]; + * + * @return The path. + */ + @java.lang.Override + public java.lang.String getPath() { + java.lang.Object ref = path_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + path_ = s; + return s; + } + } + + /** + * string path = 2 [json_name = "path"]; + * + * @return The bytes for path. + */ + @java.lang.Override + public com.google.protobuf.ByteString getPathBytes() { + java.lang.Object ref = path_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + path_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int TYPE_FIELD_NUMBER = 3; + + @SuppressWarnings("serial") + private volatile java.lang.Object type_ = ""; + + /** + * string type = 3 [json_name = "type"]; + * + * @return The type. + */ + @java.lang.Override + public java.lang.String getType() { + java.lang.Object ref = type_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + type_ = s; + return s; + } + } + + /** + * string type = 3 [json_name = "type"]; + * + * @return The bytes for type. + */ + @java.lang.Override + public com.google.protobuf.ByteString getTypeBytes() { + java.lang.Object ref = type_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + type_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int REQUEST_HEADERS_FIELD_NUMBER = 4; + + private static final class RequestHeadersDefaultEntryHolder { + static final com.google.protobuf.MapEntry< + java.lang.String, com.akto.proto.http_response_param.v1.StringList> + defaultEntry = + com.google.protobuf.MapEntry + . + newDefaultInstance( + com.akto.proto.http_response_param.v1.HttpResponseParamProto + .internal_static_threat_detection_message_http_response_param_v1_HttpResponseParam_RequestHeadersEntry_descriptor, + com.google.protobuf.WireFormat.FieldType.STRING, + "", + com.google.protobuf.WireFormat.FieldType.MESSAGE, + com.akto.proto.http_response_param.v1.StringList.getDefaultInstance()); + } + + @SuppressWarnings("serial") + private com.google.protobuf.MapField< + java.lang.String, com.akto.proto.http_response_param.v1.StringList> + requestHeaders_; + + private com.google.protobuf.MapField< + java.lang.String, com.akto.proto.http_response_param.v1.StringList> + internalGetRequestHeaders() { + if (requestHeaders_ == null) { + return com.google.protobuf.MapField.emptyMapField( + RequestHeadersDefaultEntryHolder.defaultEntry); + } + return requestHeaders_; + } + + public int getRequestHeadersCount() { + return internalGetRequestHeaders().getMap().size(); + } + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> request_headers = 4 [json_name = "requestHeaders"]; + * + */ + @java.lang.Override + public boolean containsRequestHeaders(java.lang.String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + return internalGetRequestHeaders().getMap().containsKey(key); + } + + /** Use {@link #getRequestHeadersMap()} instead. */ + @java.lang.Override + @java.lang.Deprecated + public java.util.Map + getRequestHeaders() { + return getRequestHeadersMap(); + } + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> request_headers = 4 [json_name = "requestHeaders"]; + * + */ + @java.lang.Override + public java.util.Map + getRequestHeadersMap() { + return internalGetRequestHeaders().getMap(); + } + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> request_headers = 4 [json_name = "requestHeaders"]; + * + */ + @java.lang.Override + public /* nullable */ com.akto.proto.http_response_param.v1.StringList getRequestHeadersOrDefault( + java.lang.String key, + /* nullable */ + com.akto.proto.http_response_param.v1.StringList defaultValue) { + if (key == null) { + throw new NullPointerException("map key"); + } + java.util.Map map = + internalGetRequestHeaders().getMap(); + return map.containsKey(key) ? map.get(key) : defaultValue; + } + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> request_headers = 4 [json_name = "requestHeaders"]; + * + */ + @java.lang.Override + public com.akto.proto.http_response_param.v1.StringList getRequestHeadersOrThrow( + java.lang.String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + java.util.Map map = + internalGetRequestHeaders().getMap(); + if (!map.containsKey(key)) { + throw new java.lang.IllegalArgumentException(); + } + return map.get(key); + } + + public static final int REQUEST_PAYLOAD_FIELD_NUMBER = 5; + + @SuppressWarnings("serial") + private volatile java.lang.Object requestPayload_ = ""; + + /** + * string request_payload = 5 [json_name = "requestPayload"]; + * + * @return The requestPayload. + */ + @java.lang.Override + public java.lang.String getRequestPayload() { + java.lang.Object ref = requestPayload_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + requestPayload_ = s; + return s; + } + } + + /** + * string request_payload = 5 [json_name = "requestPayload"]; + * + * @return The bytes for requestPayload. + */ + @java.lang.Override + public com.google.protobuf.ByteString getRequestPayloadBytes() { + java.lang.Object ref = requestPayload_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + requestPayload_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int API_COLLECTION_ID_FIELD_NUMBER = 6; + private int apiCollectionId_ = 0; + + /** + * int32 api_collection_id = 6 [json_name = "apiCollectionId"]; + * + * @return The apiCollectionId. + */ + @java.lang.Override + public int getApiCollectionId() { + return apiCollectionId_; + } + + public static final int STATUS_CODE_FIELD_NUMBER = 7; + private int statusCode_ = 0; + + /** + * int32 status_code = 7 [json_name = "statusCode"]; + * + * @return The statusCode. + */ + @java.lang.Override + public int getStatusCode() { + return statusCode_; + } + + public static final int STATUS_FIELD_NUMBER = 8; + + @SuppressWarnings("serial") + private volatile java.lang.Object status_ = ""; + + /** + * string status = 8 [json_name = "status"]; + * + * @return The status. + */ + @java.lang.Override + public java.lang.String getStatus() { + java.lang.Object ref = status_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + status_ = s; + return s; + } + } + + /** + * string status = 8 [json_name = "status"]; + * + * @return The bytes for status. + */ + @java.lang.Override + public com.google.protobuf.ByteString getStatusBytes() { + java.lang.Object ref = status_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + status_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int RESPONSE_HEADERS_FIELD_NUMBER = 9; + + private static final class ResponseHeadersDefaultEntryHolder { + static final com.google.protobuf.MapEntry< + java.lang.String, com.akto.proto.http_response_param.v1.StringList> + defaultEntry = + com.google.protobuf.MapEntry + . + newDefaultInstance( + com.akto.proto.http_response_param.v1.HttpResponseParamProto + .internal_static_threat_detection_message_http_response_param_v1_HttpResponseParam_ResponseHeadersEntry_descriptor, + com.google.protobuf.WireFormat.FieldType.STRING, + "", + com.google.protobuf.WireFormat.FieldType.MESSAGE, + com.akto.proto.http_response_param.v1.StringList.getDefaultInstance()); + } + + @SuppressWarnings("serial") + private com.google.protobuf.MapField< + java.lang.String, com.akto.proto.http_response_param.v1.StringList> + responseHeaders_; + + private com.google.protobuf.MapField< + java.lang.String, com.akto.proto.http_response_param.v1.StringList> + internalGetResponseHeaders() { + if (responseHeaders_ == null) { + return com.google.protobuf.MapField.emptyMapField( + ResponseHeadersDefaultEntryHolder.defaultEntry); + } + return responseHeaders_; + } + + public int getResponseHeadersCount() { + return internalGetResponseHeaders().getMap().size(); + } + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> response_headers = 9 [json_name = "responseHeaders"]; + * + */ + @java.lang.Override + public boolean containsResponseHeaders(java.lang.String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + return internalGetResponseHeaders().getMap().containsKey(key); + } + + /** Use {@link #getResponseHeadersMap()} instead. */ + @java.lang.Override + @java.lang.Deprecated + public java.util.Map + getResponseHeaders() { + return getResponseHeadersMap(); + } + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> response_headers = 9 [json_name = "responseHeaders"]; + * + */ + @java.lang.Override + public java.util.Map + getResponseHeadersMap() { + return internalGetResponseHeaders().getMap(); + } + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> response_headers = 9 [json_name = "responseHeaders"]; + * + */ + @java.lang.Override + public /* nullable */ com.akto.proto.http_response_param.v1.StringList + getResponseHeadersOrDefault( + java.lang.String key, + /* nullable */ + com.akto.proto.http_response_param.v1.StringList defaultValue) { + if (key == null) { + throw new NullPointerException("map key"); + } + java.util.Map map = + internalGetResponseHeaders().getMap(); + return map.containsKey(key) ? map.get(key) : defaultValue; + } + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> response_headers = 9 [json_name = "responseHeaders"]; + * + */ + @java.lang.Override + public com.akto.proto.http_response_param.v1.StringList getResponseHeadersOrThrow( + java.lang.String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + java.util.Map map = + internalGetResponseHeaders().getMap(); + if (!map.containsKey(key)) { + throw new java.lang.IllegalArgumentException(); + } + return map.get(key); + } + + public static final int RESPONSE_PAYLOAD_FIELD_NUMBER = 10; + + @SuppressWarnings("serial") + private volatile java.lang.Object responsePayload_ = ""; + + /** + * string response_payload = 10 [json_name = "responsePayload"]; + * + * @return The responsePayload. + */ + @java.lang.Override + public java.lang.String getResponsePayload() { + java.lang.Object ref = responsePayload_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + responsePayload_ = s; + return s; + } + } + + /** + * string response_payload = 10 [json_name = "responsePayload"]; + * + * @return The bytes for responsePayload. + */ + @java.lang.Override + public com.google.protobuf.ByteString getResponsePayloadBytes() { + java.lang.Object ref = responsePayload_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + responsePayload_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int TIME_FIELD_NUMBER = 11; + private int time_ = 0; + + /** + * int32 time = 11 [json_name = "time"]; + * + * @return The time. + */ + @java.lang.Override + public int getTime() { + return time_; + } + + public static final int AKTO_ACCOUNT_ID_FIELD_NUMBER = 12; + + @SuppressWarnings("serial") + private volatile java.lang.Object aktoAccountId_ = ""; + + /** + * string akto_account_id = 12 [json_name = "aktoAccountId"]; + * + * @return The aktoAccountId. + */ + @java.lang.Override + public java.lang.String getAktoAccountId() { + java.lang.Object ref = aktoAccountId_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + aktoAccountId_ = s; + return s; + } + } + + /** + * string akto_account_id = 12 [json_name = "aktoAccountId"]; + * + * @return The bytes for aktoAccountId. + */ + @java.lang.Override + public com.google.protobuf.ByteString getAktoAccountIdBytes() { + java.lang.Object ref = aktoAccountId_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + aktoAccountId_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int IP_FIELD_NUMBER = 13; + + @SuppressWarnings("serial") + private volatile java.lang.Object ip_ = ""; + + /** + * string ip = 13 [json_name = "ip"]; + * + * @return The ip. + */ + @java.lang.Override + public java.lang.String getIp() { + java.lang.Object ref = ip_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + ip_ = s; + return s; + } + } + + /** + * string ip = 13 [json_name = "ip"]; + * + * @return The bytes for ip. + */ + @java.lang.Override + public com.google.protobuf.ByteString getIpBytes() { + java.lang.Object ref = ip_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + ip_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int DEST_IP_FIELD_NUMBER = 14; + + @SuppressWarnings("serial") + private volatile java.lang.Object destIp_ = ""; + + /** + * string dest_ip = 14 [json_name = "destIp"]; + * + * @return The destIp. + */ + @java.lang.Override + public java.lang.String getDestIp() { + java.lang.Object ref = destIp_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + destIp_ = s; + return s; + } + } + + /** + * string dest_ip = 14 [json_name = "destIp"]; + * + * @return The bytes for destIp. + */ + @java.lang.Override + public com.google.protobuf.ByteString getDestIpBytes() { + java.lang.Object ref = destIp_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + destIp_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int DIRECTION_FIELD_NUMBER = 15; + + @SuppressWarnings("serial") + private volatile java.lang.Object direction_ = ""; + + /** + * string direction = 15 [json_name = "direction"]; + * + * @return The direction. + */ + @java.lang.Override + public java.lang.String getDirection() { + java.lang.Object ref = direction_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + direction_ = s; + return s; + } + } + + /** + * string direction = 15 [json_name = "direction"]; + * + * @return The bytes for direction. + */ + @java.lang.Override + public com.google.protobuf.ByteString getDirectionBytes() { + java.lang.Object ref = direction_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + direction_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int IS_PENDING_FIELD_NUMBER = 16; + private boolean isPending_ = false; + + /** + * bool is_pending = 16 [json_name = "isPending"]; + * + * @return The isPending. + */ + @java.lang.Override + public boolean getIsPending() { + return isPending_; + } + + public static final int SOURCE_FIELD_NUMBER = 17; + + @SuppressWarnings("serial") + private volatile java.lang.Object source_ = ""; + + /** + * string source = 17 [json_name = "source"]; + * + * @return The source. + */ + @java.lang.Override + public java.lang.String getSource() { + java.lang.Object ref = source_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + source_ = s; + return s; + } + } + + /** + * string source = 17 [json_name = "source"]; + * + * @return The bytes for source. + */ + @java.lang.Override + public com.google.protobuf.ByteString getSourceBytes() { + java.lang.Object ref = source_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + source_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int AKTO_VXLAN_ID_FIELD_NUMBER = 18; + + @SuppressWarnings("serial") + private volatile java.lang.Object aktoVxlanId_ = ""; + + /** + * string akto_vxlan_id = 18 [json_name = "aktoVxlanId"]; + * + * @return The aktoVxlanId. + */ + @java.lang.Override + public java.lang.String getAktoVxlanId() { + java.lang.Object ref = aktoVxlanId_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + aktoVxlanId_ = s; + return s; + } + } + + /** + * string akto_vxlan_id = 18 [json_name = "aktoVxlanId"]; + * + * @return The bytes for aktoVxlanId. + */ + @java.lang.Override + public com.google.protobuf.ByteString getAktoVxlanIdBytes() { + java.lang.Object ref = aktoVxlanId_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + aktoVxlanId_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(method_)) { + com.google.protobuf.GeneratedMessage.writeString(output, 1, method_); + } + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(path_)) { + com.google.protobuf.GeneratedMessage.writeString(output, 2, path_); + } + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(type_)) { + com.google.protobuf.GeneratedMessage.writeString(output, 3, type_); + } + com.google.protobuf.GeneratedMessage.serializeStringMapTo( + output, internalGetRequestHeaders(), RequestHeadersDefaultEntryHolder.defaultEntry, 4); + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(requestPayload_)) { + com.google.protobuf.GeneratedMessage.writeString(output, 5, requestPayload_); + } + if (apiCollectionId_ != 0) { + output.writeInt32(6, apiCollectionId_); + } + if (statusCode_ != 0) { + output.writeInt32(7, statusCode_); + } + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(status_)) { + com.google.protobuf.GeneratedMessage.writeString(output, 8, status_); + } + com.google.protobuf.GeneratedMessage.serializeStringMapTo( + output, internalGetResponseHeaders(), ResponseHeadersDefaultEntryHolder.defaultEntry, 9); + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(responsePayload_)) { + com.google.protobuf.GeneratedMessage.writeString(output, 10, responsePayload_); + } + if (time_ != 0) { + output.writeInt32(11, time_); + } + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(aktoAccountId_)) { + com.google.protobuf.GeneratedMessage.writeString(output, 12, aktoAccountId_); + } + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(ip_)) { + com.google.protobuf.GeneratedMessage.writeString(output, 13, ip_); + } + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(destIp_)) { + com.google.protobuf.GeneratedMessage.writeString(output, 14, destIp_); + } + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(direction_)) { + com.google.protobuf.GeneratedMessage.writeString(output, 15, direction_); + } + if (isPending_ != false) { + output.writeBool(16, isPending_); + } + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(source_)) { + com.google.protobuf.GeneratedMessage.writeString(output, 17, source_); + } + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(aktoVxlanId_)) { + com.google.protobuf.GeneratedMessage.writeString(output, 18, aktoVxlanId_); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(method_)) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(1, method_); + } + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(path_)) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(2, path_); + } + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(type_)) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(3, type_); + } + for (java.util.Map.Entry + entry : internalGetRequestHeaders().getMap().entrySet()) { + com.google.protobuf.MapEntry< + java.lang.String, com.akto.proto.http_response_param.v1.StringList> + requestHeaders__ = + RequestHeadersDefaultEntryHolder.defaultEntry + .newBuilderForType() + .setKey(entry.getKey()) + .setValue(entry.getValue()) + .build(); + size += com.google.protobuf.CodedOutputStream.computeMessageSize(4, requestHeaders__); + } + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(requestPayload_)) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(5, requestPayload_); + } + if (apiCollectionId_ != 0) { + size += com.google.protobuf.CodedOutputStream.computeInt32Size(6, apiCollectionId_); + } + if (statusCode_ != 0) { + size += com.google.protobuf.CodedOutputStream.computeInt32Size(7, statusCode_); + } + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(status_)) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(8, status_); + } + for (java.util.Map.Entry + entry : internalGetResponseHeaders().getMap().entrySet()) { + com.google.protobuf.MapEntry< + java.lang.String, com.akto.proto.http_response_param.v1.StringList> + responseHeaders__ = + ResponseHeadersDefaultEntryHolder.defaultEntry + .newBuilderForType() + .setKey(entry.getKey()) + .setValue(entry.getValue()) + .build(); + size += com.google.protobuf.CodedOutputStream.computeMessageSize(9, responseHeaders__); + } + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(responsePayload_)) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(10, responsePayload_); + } + if (time_ != 0) { + size += com.google.protobuf.CodedOutputStream.computeInt32Size(11, time_); + } + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(aktoAccountId_)) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(12, aktoAccountId_); + } + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(ip_)) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(13, ip_); + } + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(destIp_)) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(14, destIp_); + } + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(direction_)) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(15, direction_); + } + if (isPending_ != false) { + size += com.google.protobuf.CodedOutputStream.computeBoolSize(16, isPending_); + } + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(source_)) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(17, source_); + } + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(aktoVxlanId_)) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(18, aktoVxlanId_); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.akto.proto.http_response_param.v1.HttpResponseParam)) { + return super.equals(obj); + } + com.akto.proto.http_response_param.v1.HttpResponseParam other = + (com.akto.proto.http_response_param.v1.HttpResponseParam) obj; + + if (!getMethod().equals(other.getMethod())) return false; + if (!getPath().equals(other.getPath())) return false; + if (!getType().equals(other.getType())) return false; + if (!internalGetRequestHeaders().equals(other.internalGetRequestHeaders())) return false; + if (!getRequestPayload().equals(other.getRequestPayload())) return false; + if (getApiCollectionId() != other.getApiCollectionId()) return false; + if (getStatusCode() != other.getStatusCode()) return false; + if (!getStatus().equals(other.getStatus())) return false; + if (!internalGetResponseHeaders().equals(other.internalGetResponseHeaders())) return false; + if (!getResponsePayload().equals(other.getResponsePayload())) return false; + if (getTime() != other.getTime()) return false; + if (!getAktoAccountId().equals(other.getAktoAccountId())) return false; + if (!getIp().equals(other.getIp())) return false; + if (!getDestIp().equals(other.getDestIp())) return false; + if (!getDirection().equals(other.getDirection())) return false; + if (getIsPending() != other.getIsPending()) return false; + if (!getSource().equals(other.getSource())) return false; + if (!getAktoVxlanId().equals(other.getAktoVxlanId())) return false; + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + METHOD_FIELD_NUMBER; + hash = (53 * hash) + getMethod().hashCode(); + hash = (37 * hash) + PATH_FIELD_NUMBER; + hash = (53 * hash) + getPath().hashCode(); + hash = (37 * hash) + TYPE_FIELD_NUMBER; + hash = (53 * hash) + getType().hashCode(); + if (!internalGetRequestHeaders().getMap().isEmpty()) { + hash = (37 * hash) + REQUEST_HEADERS_FIELD_NUMBER; + hash = (53 * hash) + internalGetRequestHeaders().hashCode(); + } + hash = (37 * hash) + REQUEST_PAYLOAD_FIELD_NUMBER; + hash = (53 * hash) + getRequestPayload().hashCode(); + hash = (37 * hash) + API_COLLECTION_ID_FIELD_NUMBER; + hash = (53 * hash) + getApiCollectionId(); + hash = (37 * hash) + STATUS_CODE_FIELD_NUMBER; + hash = (53 * hash) + getStatusCode(); + hash = (37 * hash) + STATUS_FIELD_NUMBER; + hash = (53 * hash) + getStatus().hashCode(); + if (!internalGetResponseHeaders().getMap().isEmpty()) { + hash = (37 * hash) + RESPONSE_HEADERS_FIELD_NUMBER; + hash = (53 * hash) + internalGetResponseHeaders().hashCode(); + } + hash = (37 * hash) + RESPONSE_PAYLOAD_FIELD_NUMBER; + hash = (53 * hash) + getResponsePayload().hashCode(); + hash = (37 * hash) + TIME_FIELD_NUMBER; + hash = (53 * hash) + getTime(); + hash = (37 * hash) + AKTO_ACCOUNT_ID_FIELD_NUMBER; + hash = (53 * hash) + getAktoAccountId().hashCode(); + hash = (37 * hash) + IP_FIELD_NUMBER; + hash = (53 * hash) + getIp().hashCode(); + hash = (37 * hash) + DEST_IP_FIELD_NUMBER; + hash = (53 * hash) + getDestIp().hashCode(); + hash = (37 * hash) + DIRECTION_FIELD_NUMBER; + hash = (53 * hash) + getDirection().hashCode(); + hash = (37 * hash) + IS_PENDING_FIELD_NUMBER; + hash = (53 * hash) + com.google.protobuf.Internal.hashBoolean(getIsPending()); + hash = (37 * hash) + SOURCE_FIELD_NUMBER; + hash = (53 * hash) + getSource().hashCode(); + hash = (37 * hash) + AKTO_VXLAN_ID_FIELD_NUMBER; + hash = (53 * hash) + getAktoVxlanId().hashCode(); + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.akto.proto.http_response_param.v1.HttpResponseParam parseFrom( + java.nio.ByteBuffer data) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.akto.proto.http_response_param.v1.HttpResponseParam parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.akto.proto.http_response_param.v1.HttpResponseParam parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.akto.proto.http_response_param.v1.HttpResponseParam parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.akto.proto.http_response_param.v1.HttpResponseParam parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.akto.proto.http_response_param.v1.HttpResponseParam parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.akto.proto.http_response_param.v1.HttpResponseParam parseFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessage.parseWithIOException(PARSER, input); + } + + public static com.akto.proto.http_response_param.v1.HttpResponseParam parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.akto.proto.http_response_param.v1.HttpResponseParam parseDelimitedFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessage.parseDelimitedWithIOException(PARSER, input); + } + + public static com.akto.proto.http_response_param.v1.HttpResponseParam parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.akto.proto.http_response_param.v1.HttpResponseParam parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessage.parseWithIOException(PARSER, input); + } + + public static com.akto.proto.http_response_param.v1.HttpResponseParam parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder( + com.akto.proto.http_response_param.v1.HttpResponseParam prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + + /** Protobuf type {@code threat_detection.message.http_response_param.v1.HttpResponseParam} */ + public static final class Builder extends com.google.protobuf.GeneratedMessage.Builder + implements + // @@protoc_insertion_point(builder_implements:threat_detection.message.http_response_param.v1.HttpResponseParam) + com.akto.proto.http_response_param.v1.HttpResponseParamOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.akto.proto.http_response_param.v1.HttpResponseParamProto + .internal_static_threat_detection_message_http_response_param_v1_HttpResponseParam_descriptor; + } + + @SuppressWarnings({"rawtypes"}) + protected com.google.protobuf.MapFieldReflectionAccessor internalGetMapFieldReflection( + int number) { + switch (number) { + case 4: + return internalGetRequestHeaders(); + case 9: + return internalGetResponseHeaders(); + default: + throw new RuntimeException("Invalid map field number: " + number); + } + } + + @SuppressWarnings({"rawtypes"}) + protected com.google.protobuf.MapFieldReflectionAccessor internalGetMutableMapFieldReflection( + int number) { + switch (number) { + case 4: + return internalGetMutableRequestHeaders(); + case 9: + return internalGetMutableResponseHeaders(); + default: + throw new RuntimeException("Invalid map field number: " + number); + } + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.akto.proto.http_response_param.v1.HttpResponseParamProto + .internal_static_threat_detection_message_http_response_param_v1_HttpResponseParam_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.akto.proto.http_response_param.v1.HttpResponseParam.class, + com.akto.proto.http_response_param.v1.HttpResponseParam.Builder.class); + } + + // Construct using + // com.akto.proto.generated.threat_detection.message.http_response_param.v1.HttpResponseParam.newBuilder() + private Builder() {} + + private Builder(com.google.protobuf.GeneratedMessage.BuilderParent parent) { + super(parent); + } + + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + method_ = ""; + path_ = ""; + type_ = ""; + internalGetMutableRequestHeaders().clear(); + requestPayload_ = ""; + apiCollectionId_ = 0; + statusCode_ = 0; + status_ = ""; + internalGetMutableResponseHeaders().clear(); + responsePayload_ = ""; + time_ = 0; + aktoAccountId_ = ""; + ip_ = ""; + destIp_ = ""; + direction_ = ""; + isPending_ = false; + source_ = ""; + aktoVxlanId_ = ""; + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.akto.proto.http_response_param.v1.HttpResponseParamProto + .internal_static_threat_detection_message_http_response_param_v1_HttpResponseParam_descriptor; + } + + @java.lang.Override + public com.akto.proto.http_response_param.v1.HttpResponseParam getDefaultInstanceForType() { + return com.akto.proto.http_response_param.v1.HttpResponseParam.getDefaultInstance(); + } + + @java.lang.Override + public com.akto.proto.http_response_param.v1.HttpResponseParam build() { + com.akto.proto.http_response_param.v1.HttpResponseParam result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.akto.proto.http_response_param.v1.HttpResponseParam buildPartial() { + com.akto.proto.http_response_param.v1.HttpResponseParam result = + new com.akto.proto.http_response_param.v1.HttpResponseParam(this); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartial0(com.akto.proto.http_response_param.v1.HttpResponseParam result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.method_ = method_; + } + if (((from_bitField0_ & 0x00000002) != 0)) { + result.path_ = path_; + } + if (((from_bitField0_ & 0x00000004) != 0)) { + result.type_ = type_; + } + if (((from_bitField0_ & 0x00000008) != 0)) { + result.requestHeaders_ = + internalGetRequestHeaders().build(RequestHeadersDefaultEntryHolder.defaultEntry); + } + if (((from_bitField0_ & 0x00000010) != 0)) { + result.requestPayload_ = requestPayload_; + } + if (((from_bitField0_ & 0x00000020) != 0)) { + result.apiCollectionId_ = apiCollectionId_; + } + if (((from_bitField0_ & 0x00000040) != 0)) { + result.statusCode_ = statusCode_; + } + if (((from_bitField0_ & 0x00000080) != 0)) { + result.status_ = status_; + } + if (((from_bitField0_ & 0x00000100) != 0)) { + result.responseHeaders_ = + internalGetResponseHeaders().build(ResponseHeadersDefaultEntryHolder.defaultEntry); + } + if (((from_bitField0_ & 0x00000200) != 0)) { + result.responsePayload_ = responsePayload_; + } + if (((from_bitField0_ & 0x00000400) != 0)) { + result.time_ = time_; + } + if (((from_bitField0_ & 0x00000800) != 0)) { + result.aktoAccountId_ = aktoAccountId_; + } + if (((from_bitField0_ & 0x00001000) != 0)) { + result.ip_ = ip_; + } + if (((from_bitField0_ & 0x00002000) != 0)) { + result.destIp_ = destIp_; + } + if (((from_bitField0_ & 0x00004000) != 0)) { + result.direction_ = direction_; + } + if (((from_bitField0_ & 0x00008000) != 0)) { + result.isPending_ = isPending_; + } + if (((from_bitField0_ & 0x00010000) != 0)) { + result.source_ = source_; + } + if (((from_bitField0_ & 0x00020000) != 0)) { + result.aktoVxlanId_ = aktoVxlanId_; + } + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.akto.proto.http_response_param.v1.HttpResponseParam) { + return mergeFrom((com.akto.proto.http_response_param.v1.HttpResponseParam) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.akto.proto.http_response_param.v1.HttpResponseParam other) { + if (other == com.akto.proto.http_response_param.v1.HttpResponseParam.getDefaultInstance()) + return this; + if (!other.getMethod().isEmpty()) { + method_ = other.method_; + bitField0_ |= 0x00000001; + onChanged(); + } + if (!other.getPath().isEmpty()) { + path_ = other.path_; + bitField0_ |= 0x00000002; + onChanged(); + } + if (!other.getType().isEmpty()) { + type_ = other.type_; + bitField0_ |= 0x00000004; + onChanged(); + } + internalGetMutableRequestHeaders().mergeFrom(other.internalGetRequestHeaders()); + bitField0_ |= 0x00000008; + if (!other.getRequestPayload().isEmpty()) { + requestPayload_ = other.requestPayload_; + bitField0_ |= 0x00000010; + onChanged(); + } + if (other.getApiCollectionId() != 0) { + setApiCollectionId(other.getApiCollectionId()); + } + if (other.getStatusCode() != 0) { + setStatusCode(other.getStatusCode()); + } + if (!other.getStatus().isEmpty()) { + status_ = other.status_; + bitField0_ |= 0x00000080; + onChanged(); + } + internalGetMutableResponseHeaders().mergeFrom(other.internalGetResponseHeaders()); + bitField0_ |= 0x00000100; + if (!other.getResponsePayload().isEmpty()) { + responsePayload_ = other.responsePayload_; + bitField0_ |= 0x00000200; + onChanged(); + } + if (other.getTime() != 0) { + setTime(other.getTime()); + } + if (!other.getAktoAccountId().isEmpty()) { + aktoAccountId_ = other.aktoAccountId_; + bitField0_ |= 0x00000800; + onChanged(); + } + if (!other.getIp().isEmpty()) { + ip_ = other.ip_; + bitField0_ |= 0x00001000; + onChanged(); + } + if (!other.getDestIp().isEmpty()) { + destIp_ = other.destIp_; + bitField0_ |= 0x00002000; + onChanged(); + } + if (!other.getDirection().isEmpty()) { + direction_ = other.direction_; + bitField0_ |= 0x00004000; + onChanged(); + } + if (other.getIsPending() != false) { + setIsPending(other.getIsPending()); + } + if (!other.getSource().isEmpty()) { + source_ = other.source_; + bitField0_ |= 0x00010000; + onChanged(); + } + if (!other.getAktoVxlanId().isEmpty()) { + aktoVxlanId_ = other.aktoVxlanId_; + bitField0_ |= 0x00020000; + onChanged(); + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: + { + method_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000001; + break; + } // case 10 + case 18: + { + path_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000002; + break; + } // case 18 + case 26: + { + type_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000004; + break; + } // case 26 + case 34: + { + com.google.protobuf.MapEntry< + java.lang.String, com.akto.proto.http_response_param.v1.StringList> + requestHeaders__ = + input.readMessage( + RequestHeadersDefaultEntryHolder.defaultEntry.getParserForType(), + extensionRegistry); + internalGetMutableRequestHeaders() + .ensureBuilderMap() + .put(requestHeaders__.getKey(), requestHeaders__.getValue()); + bitField0_ |= 0x00000008; + break; + } // case 34 + case 42: + { + requestPayload_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000010; + break; + } // case 42 + case 48: + { + apiCollectionId_ = input.readInt32(); + bitField0_ |= 0x00000020; + break; + } // case 48 + case 56: + { + statusCode_ = input.readInt32(); + bitField0_ |= 0x00000040; + break; + } // case 56 + case 66: + { + status_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000080; + break; + } // case 66 + case 74: + { + com.google.protobuf.MapEntry< + java.lang.String, com.akto.proto.http_response_param.v1.StringList> + responseHeaders__ = + input.readMessage( + ResponseHeadersDefaultEntryHolder.defaultEntry.getParserForType(), + extensionRegistry); + internalGetMutableResponseHeaders() + .ensureBuilderMap() + .put(responseHeaders__.getKey(), responseHeaders__.getValue()); + bitField0_ |= 0x00000100; + break; + } // case 74 + case 82: + { + responsePayload_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000200; + break; + } // case 82 + case 88: + { + time_ = input.readInt32(); + bitField0_ |= 0x00000400; + break; + } // case 88 + case 98: + { + aktoAccountId_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000800; + break; + } // case 98 + case 106: + { + ip_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00001000; + break; + } // case 106 + case 114: + { + destIp_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00002000; + break; + } // case 114 + case 122: + { + direction_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00004000; + break; + } // case 122 + case 128: + { + isPending_ = input.readBool(); + bitField0_ |= 0x00008000; + break; + } // case 128 + case 138: + { + source_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00010000; + break; + } // case 138 + case 146: + { + aktoVxlanId_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00020000; + break; + } // case 146 + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private java.lang.Object method_ = ""; + + /** + * string method = 1 [json_name = "method"]; + * + * @return The method. + */ + public java.lang.String getMethod() { + java.lang.Object ref = method_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + method_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + + /** + * string method = 1 [json_name = "method"]; + * + * @return The bytes for method. + */ + public com.google.protobuf.ByteString getMethodBytes() { + java.lang.Object ref = method_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + method_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + /** + * string method = 1 [json_name = "method"]; + * + * @param value The method to set. + * @return This builder for chaining. + */ + public Builder setMethod(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + method_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + + /** + * string method = 1 [json_name = "method"]; + * + * @return This builder for chaining. + */ + public Builder clearMethod() { + method_ = getDefaultInstance().getMethod(); + bitField0_ = (bitField0_ & ~0x00000001); + onChanged(); + return this; + } + + /** + * string method = 1 [json_name = "method"]; + * + * @param value The bytes for method to set. + * @return This builder for chaining. + */ + public Builder setMethodBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + method_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + + private java.lang.Object path_ = ""; + + /** + * string path = 2 [json_name = "path"]; + * + * @return The path. + */ + public java.lang.String getPath() { + java.lang.Object ref = path_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + path_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + + /** + * string path = 2 [json_name = "path"]; + * + * @return The bytes for path. + */ + public com.google.protobuf.ByteString getPathBytes() { + java.lang.Object ref = path_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + path_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + /** + * string path = 2 [json_name = "path"]; + * + * @param value The path to set. + * @return This builder for chaining. + */ + public Builder setPath(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + path_ = value; + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + + /** + * string path = 2 [json_name = "path"]; + * + * @return This builder for chaining. + */ + public Builder clearPath() { + path_ = getDefaultInstance().getPath(); + bitField0_ = (bitField0_ & ~0x00000002); + onChanged(); + return this; + } + + /** + * string path = 2 [json_name = "path"]; + * + * @param value The bytes for path to set. + * @return This builder for chaining. + */ + public Builder setPathBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + path_ = value; + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + + private java.lang.Object type_ = ""; + + /** + * string type = 3 [json_name = "type"]; + * + * @return The type. + */ + public java.lang.String getType() { + java.lang.Object ref = type_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + type_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + + /** + * string type = 3 [json_name = "type"]; + * + * @return The bytes for type. + */ + public com.google.protobuf.ByteString getTypeBytes() { + java.lang.Object ref = type_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + type_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + /** + * string type = 3 [json_name = "type"]; + * + * @param value The type to set. + * @return This builder for chaining. + */ + public Builder setType(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + type_ = value; + bitField0_ |= 0x00000004; + onChanged(); + return this; + } + + /** + * string type = 3 [json_name = "type"]; + * + * @return This builder for chaining. + */ + public Builder clearType() { + type_ = getDefaultInstance().getType(); + bitField0_ = (bitField0_ & ~0x00000004); + onChanged(); + return this; + } + + /** + * string type = 3 [json_name = "type"]; + * + * @param value The bytes for type to set. + * @return This builder for chaining. + */ + public Builder setTypeBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + type_ = value; + bitField0_ |= 0x00000004; + onChanged(); + return this; + } + + private static final class RequestHeadersConverter + implements com.google.protobuf.MapFieldBuilder.Converter< + java.lang.String, + com.akto.proto.http_response_param.v1.StringListOrBuilder, + com.akto.proto.http_response_param.v1.StringList> { + @java.lang.Override + public com.akto.proto.http_response_param.v1.StringList build( + com.akto.proto.http_response_param.v1.StringListOrBuilder val) { + if (val instanceof com.akto.proto.http_response_param.v1.StringList) { + return (com.akto.proto.http_response_param.v1.StringList) val; + } + return ((com.akto.proto.http_response_param.v1.StringList.Builder) val).build(); + } + + @java.lang.Override + public com.google.protobuf.MapEntry< + java.lang.String, com.akto.proto.http_response_param.v1.StringList> + defaultEntry() { + return RequestHeadersDefaultEntryHolder.defaultEntry; + } + } + ; + + private static final RequestHeadersConverter requestHeadersConverter = + new RequestHeadersConverter(); + + private com.google.protobuf.MapFieldBuilder< + java.lang.String, + com.akto.proto.http_response_param.v1.StringListOrBuilder, + com.akto.proto.http_response_param.v1.StringList, + com.akto.proto.http_response_param.v1.StringList.Builder> + requestHeaders_; + + private com.google.protobuf.MapFieldBuilder< + java.lang.String, + com.akto.proto.http_response_param.v1.StringListOrBuilder, + com.akto.proto.http_response_param.v1.StringList, + com.akto.proto.http_response_param.v1.StringList.Builder> + internalGetRequestHeaders() { + if (requestHeaders_ == null) { + return new com.google.protobuf.MapFieldBuilder<>(requestHeadersConverter); + } + return requestHeaders_; + } + + private com.google.protobuf.MapFieldBuilder< + java.lang.String, + com.akto.proto.http_response_param.v1.StringListOrBuilder, + com.akto.proto.http_response_param.v1.StringList, + com.akto.proto.http_response_param.v1.StringList.Builder> + internalGetMutableRequestHeaders() { + if (requestHeaders_ == null) { + requestHeaders_ = new com.google.protobuf.MapFieldBuilder<>(requestHeadersConverter); + } + bitField0_ |= 0x00000008; + onChanged(); + return requestHeaders_; + } + + public int getRequestHeadersCount() { + return internalGetRequestHeaders().ensureBuilderMap().size(); + } + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> request_headers = 4 [json_name = "requestHeaders"]; + * + */ + @java.lang.Override + public boolean containsRequestHeaders(java.lang.String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + return internalGetRequestHeaders().ensureBuilderMap().containsKey(key); + } + + /** Use {@link #getRequestHeadersMap()} instead. */ + @java.lang.Override + @java.lang.Deprecated + public java.util.Map + getRequestHeaders() { + return getRequestHeadersMap(); + } + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> request_headers = 4 [json_name = "requestHeaders"]; + * + */ + @java.lang.Override + public java.util.Map + getRequestHeadersMap() { + return internalGetRequestHeaders().getImmutableMap(); + } + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> request_headers = 4 [json_name = "requestHeaders"]; + * + */ + @java.lang.Override + public /* nullable */ com.akto.proto.http_response_param.v1.StringList + getRequestHeadersOrDefault( + java.lang.String key, + /* nullable */ + com.akto.proto.http_response_param.v1.StringList defaultValue) { + if (key == null) { + throw new NullPointerException("map key"); + } + java.util.Map + map = internalGetMutableRequestHeaders().ensureBuilderMap(); + return map.containsKey(key) ? requestHeadersConverter.build(map.get(key)) : defaultValue; + } + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> request_headers = 4 [json_name = "requestHeaders"]; + * + */ + @java.lang.Override + public com.akto.proto.http_response_param.v1.StringList getRequestHeadersOrThrow( + java.lang.String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + java.util.Map + map = internalGetMutableRequestHeaders().ensureBuilderMap(); + if (!map.containsKey(key)) { + throw new java.lang.IllegalArgumentException(); + } + return requestHeadersConverter.build(map.get(key)); + } + + public Builder clearRequestHeaders() { + bitField0_ = (bitField0_ & ~0x00000008); + internalGetMutableRequestHeaders().clear(); + return this; + } + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> request_headers = 4 [json_name = "requestHeaders"]; + * + */ + public Builder removeRequestHeaders(java.lang.String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + internalGetMutableRequestHeaders().ensureBuilderMap().remove(key); + return this; + } + + /** Use alternate mutation accessors instead. */ + @java.lang.Deprecated + public java.util.Map + getMutableRequestHeaders() { + bitField0_ |= 0x00000008; + return internalGetMutableRequestHeaders().ensureMessageMap(); + } + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> request_headers = 4 [json_name = "requestHeaders"]; + * + */ + public Builder putRequestHeaders( + java.lang.String key, com.akto.proto.http_response_param.v1.StringList value) { + if (key == null) { + throw new NullPointerException("map key"); + } + if (value == null) { + throw new NullPointerException("map value"); + } + internalGetMutableRequestHeaders().ensureBuilderMap().put(key, value); + bitField0_ |= 0x00000008; + return this; + } + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> request_headers = 4 [json_name = "requestHeaders"]; + * + */ + public Builder putAllRequestHeaders( + java.util.Map values) { + for (java.util.Map.Entry + e : values.entrySet()) { + if (e.getKey() == null || e.getValue() == null) { + throw new NullPointerException(); + } + } + internalGetMutableRequestHeaders().ensureBuilderMap().putAll(values); + bitField0_ |= 0x00000008; + return this; + } + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> request_headers = 4 [json_name = "requestHeaders"]; + * + */ + public com.akto.proto.http_response_param.v1.StringList.Builder + putRequestHeadersBuilderIfAbsent(java.lang.String key) { + java.util.Map + builderMap = internalGetMutableRequestHeaders().ensureBuilderMap(); + com.akto.proto.http_response_param.v1.StringListOrBuilder entry = builderMap.get(key); + if (entry == null) { + entry = com.akto.proto.http_response_param.v1.StringList.newBuilder(); + builderMap.put(key, entry); + } + if (entry instanceof com.akto.proto.http_response_param.v1.StringList) { + entry = ((com.akto.proto.http_response_param.v1.StringList) entry).toBuilder(); + builderMap.put(key, entry); + } + return (com.akto.proto.http_response_param.v1.StringList.Builder) entry; + } + + private java.lang.Object requestPayload_ = ""; + + /** + * string request_payload = 5 [json_name = "requestPayload"]; + * + * @return The requestPayload. + */ + public java.lang.String getRequestPayload() { + java.lang.Object ref = requestPayload_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + requestPayload_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + + /** + * string request_payload = 5 [json_name = "requestPayload"]; + * + * @return The bytes for requestPayload. + */ + public com.google.protobuf.ByteString getRequestPayloadBytes() { + java.lang.Object ref = requestPayload_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + requestPayload_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + /** + * string request_payload = 5 [json_name = "requestPayload"]; + * + * @param value The requestPayload to set. + * @return This builder for chaining. + */ + public Builder setRequestPayload(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + requestPayload_ = value; + bitField0_ |= 0x00000010; + onChanged(); + return this; + } + + /** + * string request_payload = 5 [json_name = "requestPayload"]; + * + * @return This builder for chaining. + */ + public Builder clearRequestPayload() { + requestPayload_ = getDefaultInstance().getRequestPayload(); + bitField0_ = (bitField0_ & ~0x00000010); + onChanged(); + return this; + } + + /** + * string request_payload = 5 [json_name = "requestPayload"]; + * + * @param value The bytes for requestPayload to set. + * @return This builder for chaining. + */ + public Builder setRequestPayloadBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + requestPayload_ = value; + bitField0_ |= 0x00000010; + onChanged(); + return this; + } + + private int apiCollectionId_; + + /** + * int32 api_collection_id = 6 [json_name = "apiCollectionId"]; + * + * @return The apiCollectionId. + */ + @java.lang.Override + public int getApiCollectionId() { + return apiCollectionId_; + } + + /** + * int32 api_collection_id = 6 [json_name = "apiCollectionId"]; + * + * @param value The apiCollectionId to set. + * @return This builder for chaining. + */ + public Builder setApiCollectionId(int value) { + + apiCollectionId_ = value; + bitField0_ |= 0x00000020; + onChanged(); + return this; + } + + /** + * int32 api_collection_id = 6 [json_name = "apiCollectionId"]; + * + * @return This builder for chaining. + */ + public Builder clearApiCollectionId() { + bitField0_ = (bitField0_ & ~0x00000020); + apiCollectionId_ = 0; + onChanged(); + return this; + } + + private int statusCode_; + + /** + * int32 status_code = 7 [json_name = "statusCode"]; + * + * @return The statusCode. + */ + @java.lang.Override + public int getStatusCode() { + return statusCode_; + } + + /** + * int32 status_code = 7 [json_name = "statusCode"]; + * + * @param value The statusCode to set. + * @return This builder for chaining. + */ + public Builder setStatusCode(int value) { + + statusCode_ = value; + bitField0_ |= 0x00000040; + onChanged(); + return this; + } + + /** + * int32 status_code = 7 [json_name = "statusCode"]; + * + * @return This builder for chaining. + */ + public Builder clearStatusCode() { + bitField0_ = (bitField0_ & ~0x00000040); + statusCode_ = 0; + onChanged(); + return this; + } + + private java.lang.Object status_ = ""; + + /** + * string status = 8 [json_name = "status"]; + * + * @return The status. + */ + public java.lang.String getStatus() { + java.lang.Object ref = status_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + status_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + + /** + * string status = 8 [json_name = "status"]; + * + * @return The bytes for status. + */ + public com.google.protobuf.ByteString getStatusBytes() { + java.lang.Object ref = status_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + status_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + /** + * string status = 8 [json_name = "status"]; + * + * @param value The status to set. + * @return This builder for chaining. + */ + public Builder setStatus(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + status_ = value; + bitField0_ |= 0x00000080; + onChanged(); + return this; + } + + /** + * string status = 8 [json_name = "status"]; + * + * @return This builder for chaining. + */ + public Builder clearStatus() { + status_ = getDefaultInstance().getStatus(); + bitField0_ = (bitField0_ & ~0x00000080); + onChanged(); + return this; + } + + /** + * string status = 8 [json_name = "status"]; + * + * @param value The bytes for status to set. + * @return This builder for chaining. + */ + public Builder setStatusBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + status_ = value; + bitField0_ |= 0x00000080; + onChanged(); + return this; + } + + private static final class ResponseHeadersConverter + implements com.google.protobuf.MapFieldBuilder.Converter< + java.lang.String, + com.akto.proto.http_response_param.v1.StringListOrBuilder, + com.akto.proto.http_response_param.v1.StringList> { + @java.lang.Override + public com.akto.proto.http_response_param.v1.StringList build( + com.akto.proto.http_response_param.v1.StringListOrBuilder val) { + if (val instanceof com.akto.proto.http_response_param.v1.StringList) { + return (com.akto.proto.http_response_param.v1.StringList) val; + } + return ((com.akto.proto.http_response_param.v1.StringList.Builder) val).build(); + } + + @java.lang.Override + public com.google.protobuf.MapEntry< + java.lang.String, com.akto.proto.http_response_param.v1.StringList> + defaultEntry() { + return ResponseHeadersDefaultEntryHolder.defaultEntry; + } + } + ; + + private static final ResponseHeadersConverter responseHeadersConverter = + new ResponseHeadersConverter(); + + private com.google.protobuf.MapFieldBuilder< + java.lang.String, + com.akto.proto.http_response_param.v1.StringListOrBuilder, + com.akto.proto.http_response_param.v1.StringList, + com.akto.proto.http_response_param.v1.StringList.Builder> + responseHeaders_; + + private com.google.protobuf.MapFieldBuilder< + java.lang.String, + com.akto.proto.http_response_param.v1.StringListOrBuilder, + com.akto.proto.http_response_param.v1.StringList, + com.akto.proto.http_response_param.v1.StringList.Builder> + internalGetResponseHeaders() { + if (responseHeaders_ == null) { + return new com.google.protobuf.MapFieldBuilder<>(responseHeadersConverter); + } + return responseHeaders_; + } + + private com.google.protobuf.MapFieldBuilder< + java.lang.String, + com.akto.proto.http_response_param.v1.StringListOrBuilder, + com.akto.proto.http_response_param.v1.StringList, + com.akto.proto.http_response_param.v1.StringList.Builder> + internalGetMutableResponseHeaders() { + if (responseHeaders_ == null) { + responseHeaders_ = new com.google.protobuf.MapFieldBuilder<>(responseHeadersConverter); + } + bitField0_ |= 0x00000100; + onChanged(); + return responseHeaders_; + } + + public int getResponseHeadersCount() { + return internalGetResponseHeaders().ensureBuilderMap().size(); + } + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> response_headers = 9 [json_name = "responseHeaders"]; + * + */ + @java.lang.Override + public boolean containsResponseHeaders(java.lang.String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + return internalGetResponseHeaders().ensureBuilderMap().containsKey(key); + } + + /** Use {@link #getResponseHeadersMap()} instead. */ + @java.lang.Override + @java.lang.Deprecated + public java.util.Map + getResponseHeaders() { + return getResponseHeadersMap(); + } + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> response_headers = 9 [json_name = "responseHeaders"]; + * + */ + @java.lang.Override + public java.util.Map + getResponseHeadersMap() { + return internalGetResponseHeaders().getImmutableMap(); + } + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> response_headers = 9 [json_name = "responseHeaders"]; + * + */ + @java.lang.Override + public /* nullable */ com.akto.proto.http_response_param.v1.StringList + getResponseHeadersOrDefault( + java.lang.String key, + /* nullable */ + com.akto.proto.http_response_param.v1.StringList defaultValue) { + if (key == null) { + throw new NullPointerException("map key"); + } + java.util.Map + map = internalGetMutableResponseHeaders().ensureBuilderMap(); + return map.containsKey(key) ? responseHeadersConverter.build(map.get(key)) : defaultValue; + } + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> response_headers = 9 [json_name = "responseHeaders"]; + * + */ + @java.lang.Override + public com.akto.proto.http_response_param.v1.StringList getResponseHeadersOrThrow( + java.lang.String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + java.util.Map + map = internalGetMutableResponseHeaders().ensureBuilderMap(); + if (!map.containsKey(key)) { + throw new java.lang.IllegalArgumentException(); + } + return responseHeadersConverter.build(map.get(key)); + } + + public Builder clearResponseHeaders() { + bitField0_ = (bitField0_ & ~0x00000100); + internalGetMutableResponseHeaders().clear(); + return this; + } + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> response_headers = 9 [json_name = "responseHeaders"]; + * + */ + public Builder removeResponseHeaders(java.lang.String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + internalGetMutableResponseHeaders().ensureBuilderMap().remove(key); + return this; + } + + /** Use alternate mutation accessors instead. */ + @java.lang.Deprecated + public java.util.Map + getMutableResponseHeaders() { + bitField0_ |= 0x00000100; + return internalGetMutableResponseHeaders().ensureMessageMap(); + } + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> response_headers = 9 [json_name = "responseHeaders"]; + * + */ + public Builder putResponseHeaders( + java.lang.String key, com.akto.proto.http_response_param.v1.StringList value) { + if (key == null) { + throw new NullPointerException("map key"); + } + if (value == null) { + throw new NullPointerException("map value"); + } + internalGetMutableResponseHeaders().ensureBuilderMap().put(key, value); + bitField0_ |= 0x00000100; + return this; + } + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> response_headers = 9 [json_name = "responseHeaders"]; + * + */ + public Builder putAllResponseHeaders( + java.util.Map values) { + for (java.util.Map.Entry + e : values.entrySet()) { + if (e.getKey() == null || e.getValue() == null) { + throw new NullPointerException(); + } + } + internalGetMutableResponseHeaders().ensureBuilderMap().putAll(values); + bitField0_ |= 0x00000100; + return this; + } + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> response_headers = 9 [json_name = "responseHeaders"]; + * + */ + public com.akto.proto.http_response_param.v1.StringList.Builder + putResponseHeadersBuilderIfAbsent(java.lang.String key) { + java.util.Map + builderMap = internalGetMutableResponseHeaders().ensureBuilderMap(); + com.akto.proto.http_response_param.v1.StringListOrBuilder entry = builderMap.get(key); + if (entry == null) { + entry = com.akto.proto.http_response_param.v1.StringList.newBuilder(); + builderMap.put(key, entry); + } + if (entry instanceof com.akto.proto.http_response_param.v1.StringList) { + entry = ((com.akto.proto.http_response_param.v1.StringList) entry).toBuilder(); + builderMap.put(key, entry); + } + return (com.akto.proto.http_response_param.v1.StringList.Builder) entry; + } + + private java.lang.Object responsePayload_ = ""; + + /** + * string response_payload = 10 [json_name = "responsePayload"]; + * + * @return The responsePayload. + */ + public java.lang.String getResponsePayload() { + java.lang.Object ref = responsePayload_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + responsePayload_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + + /** + * string response_payload = 10 [json_name = "responsePayload"]; + * + * @return The bytes for responsePayload. + */ + public com.google.protobuf.ByteString getResponsePayloadBytes() { + java.lang.Object ref = responsePayload_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + responsePayload_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + /** + * string response_payload = 10 [json_name = "responsePayload"]; + * + * @param value The responsePayload to set. + * @return This builder for chaining. + */ + public Builder setResponsePayload(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + responsePayload_ = value; + bitField0_ |= 0x00000200; + onChanged(); + return this; + } + + /** + * string response_payload = 10 [json_name = "responsePayload"]; + * + * @return This builder for chaining. + */ + public Builder clearResponsePayload() { + responsePayload_ = getDefaultInstance().getResponsePayload(); + bitField0_ = (bitField0_ & ~0x00000200); + onChanged(); + return this; + } + + /** + * string response_payload = 10 [json_name = "responsePayload"]; + * + * @param value The bytes for responsePayload to set. + * @return This builder for chaining. + */ + public Builder setResponsePayloadBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + responsePayload_ = value; + bitField0_ |= 0x00000200; + onChanged(); + return this; + } + + private int time_; + + /** + * int32 time = 11 [json_name = "time"]; + * + * @return The time. + */ + @java.lang.Override + public int getTime() { + return time_; + } + + /** + * int32 time = 11 [json_name = "time"]; + * + * @param value The time to set. + * @return This builder for chaining. + */ + public Builder setTime(int value) { + + time_ = value; + bitField0_ |= 0x00000400; + onChanged(); + return this; + } + + /** + * int32 time = 11 [json_name = "time"]; + * + * @return This builder for chaining. + */ + public Builder clearTime() { + bitField0_ = (bitField0_ & ~0x00000400); + time_ = 0; + onChanged(); + return this; + } + + private java.lang.Object aktoAccountId_ = ""; + + /** + * string akto_account_id = 12 [json_name = "aktoAccountId"]; + * + * @return The aktoAccountId. + */ + public java.lang.String getAktoAccountId() { + java.lang.Object ref = aktoAccountId_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + aktoAccountId_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + + /** + * string akto_account_id = 12 [json_name = "aktoAccountId"]; + * + * @return The bytes for aktoAccountId. + */ + public com.google.protobuf.ByteString getAktoAccountIdBytes() { + java.lang.Object ref = aktoAccountId_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + aktoAccountId_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + /** + * string akto_account_id = 12 [json_name = "aktoAccountId"]; + * + * @param value The aktoAccountId to set. + * @return This builder for chaining. + */ + public Builder setAktoAccountId(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + aktoAccountId_ = value; + bitField0_ |= 0x00000800; + onChanged(); + return this; + } + + /** + * string akto_account_id = 12 [json_name = "aktoAccountId"]; + * + * @return This builder for chaining. + */ + public Builder clearAktoAccountId() { + aktoAccountId_ = getDefaultInstance().getAktoAccountId(); + bitField0_ = (bitField0_ & ~0x00000800); + onChanged(); + return this; + } + + /** + * string akto_account_id = 12 [json_name = "aktoAccountId"]; + * + * @param value The bytes for aktoAccountId to set. + * @return This builder for chaining. + */ + public Builder setAktoAccountIdBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + aktoAccountId_ = value; + bitField0_ |= 0x00000800; + onChanged(); + return this; + } + + private java.lang.Object ip_ = ""; + + /** + * string ip = 13 [json_name = "ip"]; + * + * @return The ip. + */ + public java.lang.String getIp() { + java.lang.Object ref = ip_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + ip_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + + /** + * string ip = 13 [json_name = "ip"]; + * + * @return The bytes for ip. + */ + public com.google.protobuf.ByteString getIpBytes() { + java.lang.Object ref = ip_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + ip_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + /** + * string ip = 13 [json_name = "ip"]; + * + * @param value The ip to set. + * @return This builder for chaining. + */ + public Builder setIp(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + ip_ = value; + bitField0_ |= 0x00001000; + onChanged(); + return this; + } + + /** + * string ip = 13 [json_name = "ip"]; + * + * @return This builder for chaining. + */ + public Builder clearIp() { + ip_ = getDefaultInstance().getIp(); + bitField0_ = (bitField0_ & ~0x00001000); + onChanged(); + return this; + } + + /** + * string ip = 13 [json_name = "ip"]; + * + * @param value The bytes for ip to set. + * @return This builder for chaining. + */ + public Builder setIpBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + ip_ = value; + bitField0_ |= 0x00001000; + onChanged(); + return this; + } + + private java.lang.Object destIp_ = ""; + + /** + * string dest_ip = 14 [json_name = "destIp"]; + * + * @return The destIp. + */ + public java.lang.String getDestIp() { + java.lang.Object ref = destIp_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + destIp_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + + /** + * string dest_ip = 14 [json_name = "destIp"]; + * + * @return The bytes for destIp. + */ + public com.google.protobuf.ByteString getDestIpBytes() { + java.lang.Object ref = destIp_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + destIp_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + /** + * string dest_ip = 14 [json_name = "destIp"]; + * + * @param value The destIp to set. + * @return This builder for chaining. + */ + public Builder setDestIp(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + destIp_ = value; + bitField0_ |= 0x00002000; + onChanged(); + return this; + } + + /** + * string dest_ip = 14 [json_name = "destIp"]; + * + * @return This builder for chaining. + */ + public Builder clearDestIp() { + destIp_ = getDefaultInstance().getDestIp(); + bitField0_ = (bitField0_ & ~0x00002000); + onChanged(); + return this; + } + + /** + * string dest_ip = 14 [json_name = "destIp"]; + * + * @param value The bytes for destIp to set. + * @return This builder for chaining. + */ + public Builder setDestIpBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + destIp_ = value; + bitField0_ |= 0x00002000; + onChanged(); + return this; + } + + private java.lang.Object direction_ = ""; + + /** + * string direction = 15 [json_name = "direction"]; + * + * @return The direction. + */ + public java.lang.String getDirection() { + java.lang.Object ref = direction_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + direction_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + + /** + * string direction = 15 [json_name = "direction"]; + * + * @return The bytes for direction. + */ + public com.google.protobuf.ByteString getDirectionBytes() { + java.lang.Object ref = direction_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + direction_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + /** + * string direction = 15 [json_name = "direction"]; + * + * @param value The direction to set. + * @return This builder for chaining. + */ + public Builder setDirection(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + direction_ = value; + bitField0_ |= 0x00004000; + onChanged(); + return this; + } + + /** + * string direction = 15 [json_name = "direction"]; + * + * @return This builder for chaining. + */ + public Builder clearDirection() { + direction_ = getDefaultInstance().getDirection(); + bitField0_ = (bitField0_ & ~0x00004000); + onChanged(); + return this; + } + + /** + * string direction = 15 [json_name = "direction"]; + * + * @param value The bytes for direction to set. + * @return This builder for chaining. + */ + public Builder setDirectionBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + direction_ = value; + bitField0_ |= 0x00004000; + onChanged(); + return this; + } + + private boolean isPending_; + + /** + * bool is_pending = 16 [json_name = "isPending"]; + * + * @return The isPending. + */ + @java.lang.Override + public boolean getIsPending() { + return isPending_; + } + + /** + * bool is_pending = 16 [json_name = "isPending"]; + * + * @param value The isPending to set. + * @return This builder for chaining. + */ + public Builder setIsPending(boolean value) { + + isPending_ = value; + bitField0_ |= 0x00008000; + onChanged(); + return this; + } + + /** + * bool is_pending = 16 [json_name = "isPending"]; + * + * @return This builder for chaining. + */ + public Builder clearIsPending() { + bitField0_ = (bitField0_ & ~0x00008000); + isPending_ = false; + onChanged(); + return this; + } + + private java.lang.Object source_ = ""; + + /** + * string source = 17 [json_name = "source"]; + * + * @return The source. + */ + public java.lang.String getSource() { + java.lang.Object ref = source_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + source_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + + /** + * string source = 17 [json_name = "source"]; + * + * @return The bytes for source. + */ + public com.google.protobuf.ByteString getSourceBytes() { + java.lang.Object ref = source_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + source_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + /** + * string source = 17 [json_name = "source"]; + * + * @param value The source to set. + * @return This builder for chaining. + */ + public Builder setSource(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + source_ = value; + bitField0_ |= 0x00010000; + onChanged(); + return this; + } + + /** + * string source = 17 [json_name = "source"]; + * + * @return This builder for chaining. + */ + public Builder clearSource() { + source_ = getDefaultInstance().getSource(); + bitField0_ = (bitField0_ & ~0x00010000); + onChanged(); + return this; + } + + /** + * string source = 17 [json_name = "source"]; + * + * @param value The bytes for source to set. + * @return This builder for chaining. + */ + public Builder setSourceBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + source_ = value; + bitField0_ |= 0x00010000; + onChanged(); + return this; + } + + private java.lang.Object aktoVxlanId_ = ""; + + /** + * string akto_vxlan_id = 18 [json_name = "aktoVxlanId"]; + * + * @return The aktoVxlanId. + */ + public java.lang.String getAktoVxlanId() { + java.lang.Object ref = aktoVxlanId_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + aktoVxlanId_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + + /** + * string akto_vxlan_id = 18 [json_name = "aktoVxlanId"]; + * + * @return The bytes for aktoVxlanId. + */ + public com.google.protobuf.ByteString getAktoVxlanIdBytes() { + java.lang.Object ref = aktoVxlanId_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + aktoVxlanId_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + /** + * string akto_vxlan_id = 18 [json_name = "aktoVxlanId"]; + * + * @param value The aktoVxlanId to set. + * @return This builder for chaining. + */ + public Builder setAktoVxlanId(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + aktoVxlanId_ = value; + bitField0_ |= 0x00020000; + onChanged(); + return this; + } + + /** + * string akto_vxlan_id = 18 [json_name = "aktoVxlanId"]; + * + * @return This builder for chaining. + */ + public Builder clearAktoVxlanId() { + aktoVxlanId_ = getDefaultInstance().getAktoVxlanId(); + bitField0_ = (bitField0_ & ~0x00020000); + onChanged(); + return this; + } + + /** + * string akto_vxlan_id = 18 [json_name = "aktoVxlanId"]; + * + * @param value The bytes for aktoVxlanId to set. + * @return This builder for chaining. + */ + public Builder setAktoVxlanIdBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + aktoVxlanId_ = value; + bitField0_ |= 0x00020000; + onChanged(); + return this; + } + + // @@protoc_insertion_point(builder_scope:threat_detection.message.http_response_param.v1.HttpResponseParam) + } + + // @@protoc_insertion_point(class_scope:threat_detection.message.http_response_param.v1.HttpResponseParam) + private static final com.akto.proto.http_response_param.v1.HttpResponseParam DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.akto.proto.http_response_param.v1.HttpResponseParam(); + } + + public static com.akto.proto.http_response_param.v1.HttpResponseParam getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public HttpResponseParam parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.akto.proto.http_response_param.v1.HttpResponseParam getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } +} diff --git a/libs/protobuf/src/main/java/com/akto/proto/http_response_param/v1/HttpResponseParamOrBuilder.java b/libs/protobuf/src/main/java/com/akto/proto/http_response_param/v1/HttpResponseParamOrBuilder.java new file mode 100644 index 0000000000..a8a0247e17 --- /dev/null +++ b/libs/protobuf/src/main/java/com/akto/proto/http_response_param/v1/HttpResponseParamOrBuilder.java @@ -0,0 +1,298 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// NO CHECKED-IN PROTOBUF GENCODE +// source: threat_detection/message/http_response_param/v1/http_response_param.proto +// Protobuf Java Version: 4.29.2 + +package com.akto.proto.http_response_param.v1; + +public interface HttpResponseParamOrBuilder + extends + // @@protoc_insertion_point(interface_extends:threat_detection.message.http_response_param.v1.HttpResponseParam) + com.google.protobuf.MessageOrBuilder { + + /** + * string method = 1 [json_name = "method"]; + * + * @return The method. + */ + java.lang.String getMethod(); + + /** + * string method = 1 [json_name = "method"]; + * + * @return The bytes for method. + */ + com.google.protobuf.ByteString getMethodBytes(); + + /** + * string path = 2 [json_name = "path"]; + * + * @return The path. + */ + java.lang.String getPath(); + + /** + * string path = 2 [json_name = "path"]; + * + * @return The bytes for path. + */ + com.google.protobuf.ByteString getPathBytes(); + + /** + * string type = 3 [json_name = "type"]; + * + * @return The type. + */ + java.lang.String getType(); + + /** + * string type = 3 [json_name = "type"]; + * + * @return The bytes for type. + */ + com.google.protobuf.ByteString getTypeBytes(); + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> request_headers = 4 [json_name = "requestHeaders"]; + * + */ + int getRequestHeadersCount(); + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> request_headers = 4 [json_name = "requestHeaders"]; + * + */ + boolean containsRequestHeaders(java.lang.String key); + + /** Use {@link #getRequestHeadersMap()} instead. */ + @java.lang.Deprecated + java.util.Map + getRequestHeaders(); + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> request_headers = 4 [json_name = "requestHeaders"]; + * + */ + java.util.Map + getRequestHeadersMap(); + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> request_headers = 4 [json_name = "requestHeaders"]; + * + */ + /* nullable */ + com.akto.proto.http_response_param.v1.StringList getRequestHeadersOrDefault( + java.lang.String key, + /* nullable */ + com.akto.proto.http_response_param.v1.StringList defaultValue); + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> request_headers = 4 [json_name = "requestHeaders"]; + * + */ + com.akto.proto.http_response_param.v1.StringList getRequestHeadersOrThrow(java.lang.String key); + + /** + * string request_payload = 5 [json_name = "requestPayload"]; + * + * @return The requestPayload. + */ + java.lang.String getRequestPayload(); + + /** + * string request_payload = 5 [json_name = "requestPayload"]; + * + * @return The bytes for requestPayload. + */ + com.google.protobuf.ByteString getRequestPayloadBytes(); + + /** + * int32 api_collection_id = 6 [json_name = "apiCollectionId"]; + * + * @return The apiCollectionId. + */ + int getApiCollectionId(); + + /** + * int32 status_code = 7 [json_name = "statusCode"]; + * + * @return The statusCode. + */ + int getStatusCode(); + + /** + * string status = 8 [json_name = "status"]; + * + * @return The status. + */ + java.lang.String getStatus(); + + /** + * string status = 8 [json_name = "status"]; + * + * @return The bytes for status. + */ + com.google.protobuf.ByteString getStatusBytes(); + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> response_headers = 9 [json_name = "responseHeaders"]; + * + */ + int getResponseHeadersCount(); + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> response_headers = 9 [json_name = "responseHeaders"]; + * + */ + boolean containsResponseHeaders(java.lang.String key); + + /** Use {@link #getResponseHeadersMap()} instead. */ + @java.lang.Deprecated + java.util.Map + getResponseHeaders(); + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> response_headers = 9 [json_name = "responseHeaders"]; + * + */ + java.util.Map + getResponseHeadersMap(); + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> response_headers = 9 [json_name = "responseHeaders"]; + * + */ + /* nullable */ + com.akto.proto.http_response_param.v1.StringList getResponseHeadersOrDefault( + java.lang.String key, + /* nullable */ + com.akto.proto.http_response_param.v1.StringList defaultValue); + + /** + * + * map<string, .threat_detection.message.http_response_param.v1.StringList> response_headers = 9 [json_name = "responseHeaders"]; + * + */ + com.akto.proto.http_response_param.v1.StringList getResponseHeadersOrThrow(java.lang.String key); + + /** + * string response_payload = 10 [json_name = "responsePayload"]; + * + * @return The responsePayload. + */ + java.lang.String getResponsePayload(); + + /** + * string response_payload = 10 [json_name = "responsePayload"]; + * + * @return The bytes for responsePayload. + */ + com.google.protobuf.ByteString getResponsePayloadBytes(); + + /** + * int32 time = 11 [json_name = "time"]; + * + * @return The time. + */ + int getTime(); + + /** + * string akto_account_id = 12 [json_name = "aktoAccountId"]; + * + * @return The aktoAccountId. + */ + java.lang.String getAktoAccountId(); + + /** + * string akto_account_id = 12 [json_name = "aktoAccountId"]; + * + * @return The bytes for aktoAccountId. + */ + com.google.protobuf.ByteString getAktoAccountIdBytes(); + + /** + * string ip = 13 [json_name = "ip"]; + * + * @return The ip. + */ + java.lang.String getIp(); + + /** + * string ip = 13 [json_name = "ip"]; + * + * @return The bytes for ip. + */ + com.google.protobuf.ByteString getIpBytes(); + + /** + * string dest_ip = 14 [json_name = "destIp"]; + * + * @return The destIp. + */ + java.lang.String getDestIp(); + + /** + * string dest_ip = 14 [json_name = "destIp"]; + * + * @return The bytes for destIp. + */ + com.google.protobuf.ByteString getDestIpBytes(); + + /** + * string direction = 15 [json_name = "direction"]; + * + * @return The direction. + */ + java.lang.String getDirection(); + + /** + * string direction = 15 [json_name = "direction"]; + * + * @return The bytes for direction. + */ + com.google.protobuf.ByteString getDirectionBytes(); + + /** + * bool is_pending = 16 [json_name = "isPending"]; + * + * @return The isPending. + */ + boolean getIsPending(); + + /** + * string source = 17 [json_name = "source"]; + * + * @return The source. + */ + java.lang.String getSource(); + + /** + * string source = 17 [json_name = "source"]; + * + * @return The bytes for source. + */ + com.google.protobuf.ByteString getSourceBytes(); + + /** + * string akto_vxlan_id = 18 [json_name = "aktoVxlanId"]; + * + * @return The aktoVxlanId. + */ + java.lang.String getAktoVxlanId(); + + /** + * string akto_vxlan_id = 18 [json_name = "aktoVxlanId"]; + * + * @return The bytes for aktoVxlanId. + */ + com.google.protobuf.ByteString getAktoVxlanIdBytes(); +} diff --git a/libs/protobuf/src/main/java/com/akto/proto/http_response_param/v1/HttpResponseParamProto.java b/libs/protobuf/src/main/java/com/akto/proto/http_response_param/v1/HttpResponseParamProto.java new file mode 100644 index 0000000000..19f17c40b7 --- /dev/null +++ b/libs/protobuf/src/main/java/com/akto/proto/http_response_param/v1/HttpResponseParamProto.java @@ -0,0 +1,152 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// NO CHECKED-IN PROTOBUF GENCODE +// source: threat_detection/message/http_response_param/v1/http_response_param.proto +// Protobuf Java Version: 4.29.2 + +package com.akto.proto.http_response_param.v1; + +public final class HttpResponseParamProto { + private HttpResponseParamProto() {} + + static { + com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( + com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, + /* major= */ 4, + /* minor= */ 29, + /* patch= */ 2, + /* suffix= */ "", + HttpResponseParamProto.class.getName()); + } + + public static void registerAllExtensions(com.google.protobuf.ExtensionRegistryLite registry) {} + + public static void registerAllExtensions(com.google.protobuf.ExtensionRegistry registry) { + registerAllExtensions((com.google.protobuf.ExtensionRegistryLite) registry); + } + + static final com.google.protobuf.Descriptors.Descriptor + internal_static_threat_detection_message_http_response_param_v1_StringList_descriptor; + static final com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_threat_detection_message_http_response_param_v1_StringList_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_threat_detection_message_http_response_param_v1_HttpResponseParam_descriptor; + static final com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_threat_detection_message_http_response_param_v1_HttpResponseParam_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_threat_detection_message_http_response_param_v1_HttpResponseParam_RequestHeadersEntry_descriptor; + static final com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_threat_detection_message_http_response_param_v1_HttpResponseParam_RequestHeadersEntry_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_threat_detection_message_http_response_param_v1_HttpResponseParam_ResponseHeadersEntry_descriptor; + static final com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_threat_detection_message_http_response_param_v1_HttpResponseParam_ResponseHeadersEntry_fieldAccessorTable; + + public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { + return descriptor; + } + + private static com.google.protobuf.Descriptors.FileDescriptor descriptor; + + static { + java.lang.String[] descriptorData = { + "\nIthreat_detection/message/http_response" + + "_param/v1/http_response_param.proto\022/thr" + + "eat_detection.message.http_response_para" + + "m.v1\"$\n\nStringList\022\026\n\006values\030\001 \003(\tR\006valu" + + "es\"\361\007\n\021HttpResponseParam\022\026\n\006method\030\001 \001(\t" + + "R\006method\022\022\n\004path\030\002 \001(\tR\004path\022\022\n\004type\030\003 \001" + + "(\tR\004type\022\177\n\017request_headers\030\004 \003(\0132V.thre" + + "at_detection.message.http_response_param" + + ".v1.HttpResponseParam.RequestHeadersEntr" + + "yR\016requestHeaders\022\'\n\017request_payload\030\005 \001" + + "(\tR\016requestPayload\022*\n\021api_collection_id\030" + + "\006 \001(\005R\017apiCollectionId\022\037\n\013status_code\030\007 " + + "\001(\005R\nstatusCode\022\026\n\006status\030\010 \001(\tR\006status\022" + + "\202\001\n\020response_headers\030\t \003(\0132W.threat_dete" + + "ction.message.http_response_param.v1.Htt" + + "pResponseParam.ResponseHeadersEntryR\017res" + + "ponseHeaders\022)\n\020response_payload\030\n \001(\tR\017" + + "responsePayload\022\022\n\004time\030\013 \001(\005R\004time\022&\n\017a" + + "kto_account_id\030\014 \001(\tR\raktoAccountId\022\016\n\002i" + + "p\030\r \001(\tR\002ip\022\027\n\007dest_ip\030\016 \001(\tR\006destIp\022\034\n\t" + + "direction\030\017 \001(\tR\tdirection\022\035\n\nis_pending" + + "\030\020 \001(\010R\tisPending\022\026\n\006source\030\021 \001(\tR\006sourc" + + "e\022\"\n\rakto_vxlan_id\030\022 \001(\tR\013aktoVxlanId\032~\n" + + "\023RequestHeadersEntry\022\020\n\003key\030\001 \001(\tR\003key\022Q" + + "\n\005value\030\002 \001(\0132;.threat_detection.message" + + ".http_response_param.v1.StringListR\005valu" + + "e:\0028\001\032\177\n\024ResponseHeadersEntry\022\020\n\003key\030\001 \001" + + "(\tR\003key\022Q\n\005value\030\002 \001(\0132;.threat_detectio" + + "n.message.http_response_param.v1.StringL" + + "istR\005value:\0028\001B\331\002\nHcom.akto.proto.genera" + + "ted.threat_detection.message.http_respon" + + "se_param.v1B\026HttpResponseParamProtoP\001Z\"p" + + "rotobuf/traffic_payload;trafficpb\242\002\003TMH\252" + + "\002,ThreatDetection.Message.HttpResponsePa" + + "ram.V1\312\002,ThreatDetection\\Message\\HttpRes" + + "ponseParam\\V1\342\0028ThreatDetection\\Message\\" + + "HttpResponseParam\\V1\\GPBMetadata\352\002/Threa" + + "tDetection::Message::HttpResponseParam::" + + "V1b\006proto3" + }; + descriptor = + com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom( + descriptorData, new com.google.protobuf.Descriptors.FileDescriptor[] {}); + internal_static_threat_detection_message_http_response_param_v1_StringList_descriptor = + getDescriptor().getMessageTypes().get(0); + internal_static_threat_detection_message_http_response_param_v1_StringList_fieldAccessorTable = + new com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_threat_detection_message_http_response_param_v1_StringList_descriptor, + new java.lang.String[] { + "Values", + }); + internal_static_threat_detection_message_http_response_param_v1_HttpResponseParam_descriptor = + getDescriptor().getMessageTypes().get(1); + internal_static_threat_detection_message_http_response_param_v1_HttpResponseParam_fieldAccessorTable = + new com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_threat_detection_message_http_response_param_v1_HttpResponseParam_descriptor, + new java.lang.String[] { + "Method", + "Path", + "Type", + "RequestHeaders", + "RequestPayload", + "ApiCollectionId", + "StatusCode", + "Status", + "ResponseHeaders", + "ResponsePayload", + "Time", + "AktoAccountId", + "Ip", + "DestIp", + "Direction", + "IsPending", + "Source", + "AktoVxlanId", + }); + internal_static_threat_detection_message_http_response_param_v1_HttpResponseParam_RequestHeadersEntry_descriptor = + internal_static_threat_detection_message_http_response_param_v1_HttpResponseParam_descriptor + .getNestedTypes() + .get(0); + internal_static_threat_detection_message_http_response_param_v1_HttpResponseParam_RequestHeadersEntry_fieldAccessorTable = + new com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_threat_detection_message_http_response_param_v1_HttpResponseParam_RequestHeadersEntry_descriptor, + new java.lang.String[] { + "Key", "Value", + }); + internal_static_threat_detection_message_http_response_param_v1_HttpResponseParam_ResponseHeadersEntry_descriptor = + internal_static_threat_detection_message_http_response_param_v1_HttpResponseParam_descriptor + .getNestedTypes() + .get(1); + internal_static_threat_detection_message_http_response_param_v1_HttpResponseParam_ResponseHeadersEntry_fieldAccessorTable = + new com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_threat_detection_message_http_response_param_v1_HttpResponseParam_ResponseHeadersEntry_descriptor, + new java.lang.String[] { + "Key", "Value", + }); + descriptor.resolveAllFeaturesImmutable(); + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/libs/protobuf/src/main/java/com/akto/proto/http_response_param/v1/StringList.java b/libs/protobuf/src/main/java/com/akto/proto/http_response_param/v1/StringList.java new file mode 100644 index 0000000000..54f54656d0 --- /dev/null +++ b/libs/protobuf/src/main/java/com/akto/proto/http_response_param/v1/StringList.java @@ -0,0 +1,709 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// NO CHECKED-IN PROTOBUF GENCODE +// source: threat_detection/message/http_response_param/v1/http_response_param.proto +// Protobuf Java Version: 4.29.2 + +package com.akto.proto.http_response_param.v1; + +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; + +/** Protobuf type {@code threat_detection.message.http_response_param.v1.StringList} */ +public final class StringList extends com.google.protobuf.GeneratedMessage + implements + // @@protoc_insertion_point(message_implements:threat_detection.message.http_response_param.v1.StringList) + StringListOrBuilder, + List { + private static final long serialVersionUID = 0L; + + static { + com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( + com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, + /* major= */ 4, + /* minor= */ 29, + /* patch= */ 2, + /* suffix= */ "", + StringList.class.getName()); + } + + // Use StringList.newBuilder() to construct. + private StringList(com.google.protobuf.GeneratedMessage.Builder builder) { + super(builder); + } + + private StringList() { + values_ = com.google.protobuf.LazyStringArrayList.emptyList(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.akto.proto.http_response_param.v1.HttpResponseParamProto + .internal_static_threat_detection_message_http_response_param_v1_StringList_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.akto.proto.http_response_param.v1.HttpResponseParamProto + .internal_static_threat_detection_message_http_response_param_v1_StringList_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.akto.proto.http_response_param.v1.StringList.class, + com.akto.proto.http_response_param.v1.StringList.Builder.class); + } + + public static final int VALUES_FIELD_NUMBER = 1; + + @SuppressWarnings("serial") + private com.google.protobuf.LazyStringArrayList values_ = + com.google.protobuf.LazyStringArrayList.emptyList(); + + /** + * repeated string values = 1 [json_name = "values"]; + * + * @return A list containing the values. + */ + public com.google.protobuf.ProtocolStringList getValuesList() { + return values_; + } + + /** + * repeated string values = 1 [json_name = "values"]; + * + * @return The count of values. + */ + public int getValuesCount() { + return values_.size(); + } + + /** + * repeated string values = 1 [json_name = "values"]; + * + * @param index The index of the element to return. + * @return The values at the given index. + */ + public java.lang.String getValues(int index) { + return values_.get(index); + } + + /** + * repeated string values = 1 [json_name = "values"]; + * + * @param index The index of the value to return. + * @return The bytes of the values at the given index. + */ + public com.google.protobuf.ByteString getValuesBytes(int index) { + return values_.getByteString(index); + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + for (int i = 0; i < values_.size(); i++) { + com.google.protobuf.GeneratedMessage.writeString(output, 1, values_.getRaw(i)); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + { + int dataSize = 0; + for (int i = 0; i < values_.size(); i++) { + dataSize += computeStringSizeNoTag(values_.getRaw(i)); + } + size += dataSize; + size += 1 * getValuesList().size(); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.akto.proto.http_response_param.v1.StringList)) { + return super.equals(obj); + } + com.akto.proto.http_response_param.v1.StringList other = + (com.akto.proto.http_response_param.v1.StringList) obj; + + if (!getValuesList().equals(other.getValuesList())) return false; + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + if (getValuesCount() > 0) { + hash = (37 * hash) + VALUES_FIELD_NUMBER; + hash = (53 * hash) + getValuesList().hashCode(); + } + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.akto.proto.http_response_param.v1.StringList parseFrom(java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.akto.proto.http_response_param.v1.StringList parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.akto.proto.http_response_param.v1.StringList parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.akto.proto.http_response_param.v1.StringList parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.akto.proto.http_response_param.v1.StringList parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.akto.proto.http_response_param.v1.StringList parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.akto.proto.http_response_param.v1.StringList parseFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessage.parseWithIOException(PARSER, input); + } + + public static com.akto.proto.http_response_param.v1.StringList parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.akto.proto.http_response_param.v1.StringList parseDelimitedFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessage.parseDelimitedWithIOException(PARSER, input); + } + + public static com.akto.proto.http_response_param.v1.StringList parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.akto.proto.http_response_param.v1.StringList parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessage.parseWithIOException(PARSER, input); + } + + public static com.akto.proto.http_response_param.v1.StringList parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(com.akto.proto.http_response_param.v1.StringList prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + + /** Protobuf type {@code threat_detection.message.http_response_param.v1.StringList} */ + public static final class Builder extends com.google.protobuf.GeneratedMessage.Builder + implements + // @@protoc_insertion_point(builder_implements:threat_detection.message.http_response_param.v1.StringList) + com.akto.proto.http_response_param.v1.StringListOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.akto.proto.http_response_param.v1.HttpResponseParamProto + .internal_static_threat_detection_message_http_response_param_v1_StringList_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.akto.proto.http_response_param.v1.HttpResponseParamProto + .internal_static_threat_detection_message_http_response_param_v1_StringList_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.akto.proto.http_response_param.v1.StringList.class, + com.akto.proto.http_response_param.v1.StringList.Builder.class); + } + + // Construct using + // com.akto.proto.generated.threat_detection.message.http_response_param.v1.StringList.newBuilder() + private Builder() {} + + private Builder(com.google.protobuf.GeneratedMessage.BuilderParent parent) { + super(parent); + } + + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + values_ = com.google.protobuf.LazyStringArrayList.emptyList(); + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.akto.proto.http_response_param.v1.HttpResponseParamProto + .internal_static_threat_detection_message_http_response_param_v1_StringList_descriptor; + } + + @java.lang.Override + public com.akto.proto.http_response_param.v1.StringList getDefaultInstanceForType() { + return com.akto.proto.http_response_param.v1.StringList.getDefaultInstance(); + } + + @java.lang.Override + public com.akto.proto.http_response_param.v1.StringList build() { + com.akto.proto.http_response_param.v1.StringList result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.akto.proto.http_response_param.v1.StringList buildPartial() { + com.akto.proto.http_response_param.v1.StringList result = + new com.akto.proto.http_response_param.v1.StringList(this); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartial0(com.akto.proto.http_response_param.v1.StringList result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + values_.makeImmutable(); + result.values_ = values_; + } + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.akto.proto.http_response_param.v1.StringList) { + return mergeFrom((com.akto.proto.http_response_param.v1.StringList) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.akto.proto.http_response_param.v1.StringList other) { + if (other == com.akto.proto.http_response_param.v1.StringList.getDefaultInstance()) + return this; + if (!other.values_.isEmpty()) { + if (values_.isEmpty()) { + values_ = other.values_; + bitField0_ |= 0x00000001; + } else { + ensureValuesIsMutable(); + values_.addAll(other.values_); + } + onChanged(); + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: + { + java.lang.String s = input.readStringRequireUtf8(); + ensureValuesIsMutable(); + values_.add(s); + break; + } // case 10 + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private com.google.protobuf.LazyStringArrayList values_ = + com.google.protobuf.LazyStringArrayList.emptyList(); + + private void ensureValuesIsMutable() { + if (!values_.isModifiable()) { + values_ = new com.google.protobuf.LazyStringArrayList(values_); + } + bitField0_ |= 0x00000001; + } + + /** + * repeated string values = 1 [json_name = "values"]; + * + * @return A list containing the values. + */ + public com.google.protobuf.ProtocolStringList getValuesList() { + values_.makeImmutable(); + return values_; + } + + /** + * repeated string values = 1 [json_name = "values"]; + * + * @return The count of values. + */ + public int getValuesCount() { + return values_.size(); + } + + /** + * repeated string values = 1 [json_name = "values"]; + * + * @param index The index of the element to return. + * @return The values at the given index. + */ + public java.lang.String getValues(int index) { + return values_.get(index); + } + + /** + * repeated string values = 1 [json_name = "values"]; + * + * @param index The index of the value to return. + * @return The bytes of the values at the given index. + */ + public com.google.protobuf.ByteString getValuesBytes(int index) { + return values_.getByteString(index); + } + + /** + * repeated string values = 1 [json_name = "values"]; + * + * @param index The index to set the value at. + * @param value The values to set. + * @return This builder for chaining. + */ + public Builder setValues(int index, java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + ensureValuesIsMutable(); + values_.set(index, value); + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + + /** + * repeated string values = 1 [json_name = "values"]; + * + * @param value The values to add. + * @return This builder for chaining. + */ + public Builder addValues(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + ensureValuesIsMutable(); + values_.add(value); + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + + /** + * repeated string values = 1 [json_name = "values"]; + * + * @param values The values to add. + * @return This builder for chaining. + */ + public Builder addAllValues(java.lang.Iterable values) { + ensureValuesIsMutable(); + com.google.protobuf.AbstractMessageLite.Builder.addAll(values, values_); + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + + /** + * repeated string values = 1 [json_name = "values"]; + * + * @return This builder for chaining. + */ + public Builder clearValues() { + values_ = com.google.protobuf.LazyStringArrayList.emptyList(); + bitField0_ = (bitField0_ & ~0x00000001); + ; + onChanged(); + return this; + } + + /** + * repeated string values = 1 [json_name = "values"]; + * + * @param value The bytes of the values to add. + * @return This builder for chaining. + */ + public Builder addValuesBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + ensureValuesIsMutable(); + values_.add(value); + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + + // @@protoc_insertion_point(builder_scope:threat_detection.message.http_response_param.v1.StringList) + } + + // @@protoc_insertion_point(class_scope:threat_detection.message.http_response_param.v1.StringList) + private static final com.akto.proto.http_response_param.v1.StringList DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.akto.proto.http_response_param.v1.StringList(); + } + + public static com.akto.proto.http_response_param.v1.StringList getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public StringList parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.akto.proto.http_response_param.v1.StringList getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + + @Override + public int size() { + return values_.size(); + } + + @Override + public boolean isEmpty() { + return values_.isEmpty(); + } + + @Override + public boolean contains(Object o) { + return values_.contains(o); + } + + @Override + public Iterator iterator() { + return values_.iterator(); + } + + @Override + public Object[] toArray() { + return values_.toArray(); + } + + @Override + public T[] toArray(T[] a) { + return values_.toArray(a); + } + + @Override + public boolean add(String e) { + return values_.add(e); + } + + @Override + public boolean remove(Object o) { + return values_.remove(o); + } + + @Override + public boolean containsAll(Collection c) { + return values_.containsAll(c); + } + + @Override + public boolean addAll(Collection c) { + return values_.addAll(c); + } + + @Override + public boolean addAll(int index, Collection c) { + return values_.addAll(index, c); + } + + @Override + public boolean removeAll(Collection c) { + return values_.removeAll(c); + } + + @Override + public boolean retainAll(Collection c) { + return values_.retainAll(c); + } + + @Override + public void clear() { + values_.clear(); + } + + @Override + public String get(int index) { + return values_.get(index); + } + + @Override + public String set(int index, String element) { + return values_.set(index, element); + } + + @Override + public void add(int index, String element) { + values_.add(index, element); + } + + @Override + public String remove(int index) { + return values_.remove(index); + } + + @Override + public int indexOf(Object o) { + return values_.indexOf(o); + } + + @Override + public int lastIndexOf(Object o) { + return values_.lastIndexOf(o); + } + + @Override + public ListIterator listIterator() { + return values_.listIterator(); + } + + @Override + public ListIterator listIterator(int index) { + return values_.listIterator(index); + } + + @Override + public List subList(int fromIndex, int toIndex) { + return values_.subList(fromIndex, toIndex); + } +} diff --git a/libs/protobuf/src/main/java/com/akto/proto/http_response_param/v1/StringListOrBuilder.java b/libs/protobuf/src/main/java/com/akto/proto/http_response_param/v1/StringListOrBuilder.java new file mode 100644 index 0000000000..e778a60b09 --- /dev/null +++ b/libs/protobuf/src/main/java/com/akto/proto/http_response_param/v1/StringListOrBuilder.java @@ -0,0 +1,42 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// NO CHECKED-IN PROTOBUF GENCODE +// source: threat_detection/message/http_response_param/v1/http_response_param.proto +// Protobuf Java Version: 4.29.2 + +package com.akto.proto.http_response_param.v1; + +public interface StringListOrBuilder + extends + // @@protoc_insertion_point(interface_extends:threat_detection.message.http_response_param.v1.StringList) + com.google.protobuf.MessageOrBuilder { + + /** + * repeated string values = 1 [json_name = "values"]; + * + * @return A list containing the values. + */ + java.util.List getValuesList(); + + /** + * repeated string values = 1 [json_name = "values"]; + * + * @return The count of values. + */ + int getValuesCount(); + + /** + * repeated string values = 1 [json_name = "values"]; + * + * @param index The index of the element to return. + * @return The values at the given index. + */ + java.lang.String getValues(int index); + + /** + * repeated string values = 1 [json_name = "values"]; + * + * @param index The index of the value to return. + * @return The bytes of the values at the given index. + */ + com.google.protobuf.ByteString getValuesBytes(int index); +} diff --git a/protobuf/threat_detection/message/http_response_param/v1/http_response_param.proto b/protobuf/threat_detection/message/http_response_param/v1/http_response_param.proto new file mode 100644 index 0000000000..fb2ee19225 --- /dev/null +++ b/protobuf/threat_detection/message/http_response_param/v1/http_response_param.proto @@ -0,0 +1,33 @@ +syntax = "proto3"; + +package threat_detection.message.http_response_param.v1; + +option java_outer_classname = "HttpResponseParamProto"; + +option go_package = "protobuf/traffic_payload;trafficpb"; + +message StringList { + repeated string values = 1; +} + +message HttpResponseParam { + string method = 1; + string path = 2; + string type = 3; + map request_headers = 4 [json_name = "requestHeaders"]; + string request_payload = 5 [json_name = "requestPayload"]; + int32 api_collection_id = 6 [json_name = "apiCollectionId"]; + int32 status_code = 7 [json_name = "statusCode"]; + string status = 8; + map response_headers = 9 [json_name = "responseHeaders"]; + string response_payload = 10 [json_name = "responsePayload"]; + int32 time = 11; + string akto_account_id = 12; + string ip = 13; + string dest_ip = 14 [json_name = "destIp"]; + string direction = 15; + bool is_pending = 16; + string source = 17; + string akto_vxlan_id = 18; +} + \ No newline at end of file diff --git a/scripts/proto-gen.sh b/scripts/proto-gen.sh index 2e43623718..80c3d05b84 100644 --- a/scripts/proto-gen.sh +++ b/scripts/proto-gen.sh @@ -16,4 +16,4 @@ buf lint protobuf rm -rf libs/protobuf/src/main/java/com/akto/proto/generated/ -buf generate protobuf --template "$BUF_TEMPLATE" \ No newline at end of file +buf generate protobuf --template "$BUF_TEMPLATE"