Skip to content

Commit

Permalink
Merge pull request #1990 from akto-api-security/threat-detection-dash…
Browse files Browse the repository at this point in the history
…board-fixes

threat detection dashboard fixes
  • Loading branch information
Ark2307 authored Jan 16, 2025
2 parents 92472b6 + 560fe8e commit 97a68a8
Show file tree
Hide file tree
Showing 13 changed files with 880 additions and 666 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> 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<String, Integer> 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<String, Object> body = new HashMap<String, Object>() {
{
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.<ListMaliciousRequestsResponse>toProtoMessage(
ListMaliciousRequestsResponse.class, responseBody)
.ifPresent(
Expand All @@ -83,6 +100,7 @@ public String fetchSampleData() {
smr.getCountry(),
smr.getDetectedAt()))
.collect(Collectors.toList());
this.total = m.getTotal();
});
} catch (Exception e) {
e.printStackTrace();
Expand All @@ -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.<FetchAlertFiltersResponse>toProtoMessage(
FetchAlertFiltersResponse.class, responseBody)
.ifPresent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.<ThreatActorByCountryResponse>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();
Expand All @@ -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<String, Object> body = new HashMap<String, Object>() {
{
put("skip", skip);
put("limit", LIMIT);
}
};
Map<String, Object> body =
new HashMap<String, Object>() {
{
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.<ListThreatActorResponse>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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.<ThreatCategoryWiseCountResponse>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();
Expand All @@ -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<String, Object> body = new HashMap<String, Object>() {
{
put("skip", skip);
put("limit", LIMIT);
}
};
Map<String, Object> body =
new HashMap<String, Object>() {
{
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.<ListThreatApiResponse>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();
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/src/main/resources/struts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7926,4 +7926,4 @@

</package>

</struts>
</struts>
Loading

0 comments on commit 97a68a8

Please sign in to comment.