Skip to content

Commit d13942e

Browse files
Merge remote-tracking branch 'origin/master' into release/current
2 parents 2df4f24 + a2c4c6d commit d13942e

37 files changed

+388
-45
lines changed

.drone.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ steps:
1616
MINIO_PORT: 9000
1717
ENGINE_URL: http://elastic:9200
1818
commands:
19+
- mvn spotless:check
1920
- sleep 60
2021
- mvn clean install -q -DskipTests
21-
- mvn spotless:check
2222
- cd openaev-api
2323
- mvn test
2424
- cd ../openaev-framework
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: "Validate PR Title"
2+
3+
on:
4+
pull_request:
5+
types: [ opened, edited, reopened, ready_for_review, synchronize ]
6+
7+
jobs:
8+
validate-pr-title:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
pull-requests: write
13+
14+
steps:
15+
- name: Check PR title format
16+
shell: bash
17+
run: |
18+
TITLE="${{ github.event.pull_request.title }}"
19+
echo "PR title: $TITLE"
20+
21+
# Regex for:
22+
# [category/subcategory] type(scope?): description (#123?)
23+
PATTERN='^\[([a-z]+(/[a-z]+)*)\] (feat|fix|chore|docs|style|refactor|perf|test|build|ci|revert)(\([a-z]+\))?: [a-z].*( \(#[0-9]+\))$'
24+
25+
if [[ ! "$TITLE" =~ $PATTERN ]]; then
26+
echo "❌ Invalid PR title."
27+
echo "Required format:"
28+
echo "[category] type(scope?): description (#123)"
29+
exit 1
30+
fi
31+
32+
echo "✅ PR title is valid."

openaev-api/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.openaev</groupId>
88
<artifactId>openaev-platform</artifactId>
9-
<version>2.0.2</version>
9+
<version>2.0.3</version>
1010
</parent>
1111

1212
<artifactId>openaev-api</artifactId>
@@ -49,7 +49,7 @@
4949
<dependency>
5050
<groupId>io.openaev</groupId>
5151
<artifactId>openaev-framework</artifactId>
52-
<version>2.0.2</version>
52+
<version>2.0.3</version>
5353
</dependency>
5454
<dependency>
5555
<groupId>co.elastic.clients</groupId>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package io.openaev.migration;
2+
3+
import java.sql.Statement;
4+
import org.flywaydb.core.api.migration.BaseJavaMigration;
5+
import org.flywaydb.core.api.migration.Context;
6+
import org.springframework.stereotype.Component;
7+
8+
@Component
9+
public class V4_46__Rename_platform_title_openaev extends BaseJavaMigration {
10+
11+
@Override
12+
public void migrate(Context context) throws Exception {
13+
try (Statement statement = context.getConnection().createStatement()) {
14+
String[][] patterns = {
15+
{"OPENBAS", "OPENAEV"},
16+
{"OpenBAS", "OpenAEV"},
17+
{"openbas", "openaev"},
18+
{"Openbas", "Openaev"},
19+
{"Breach & Attack Simulation", "Adversarial Exposure Validation"}
20+
};
21+
22+
// Build nested REGEXP_REPLACE calls
23+
StringBuilder sql = new StringBuilder("UPDATE parameters SET parameter_value = ");
24+
25+
// Start with the innermost value
26+
String current = "parameter_value";
27+
28+
// Wrap each pattern in a REGEXP_REPLACE
29+
for (String[] pattern : patterns) {
30+
current =
31+
String.format("REGEXP_REPLACE(%s, '%s', '%s', 'g')", current, pattern[0], pattern[1]);
32+
}
33+
34+
sql.append(current);
35+
sql.append(" WHERE parameter_key = 'platform_name' AND parameter_value ~* 'openbas'");
36+
37+
statement.executeUpdate(sql.toString());
38+
}
39+
}
40+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package io.openaev.migration;
2+
3+
import java.sql.Statement;
4+
import org.flywaydb.core.api.migration.BaseJavaMigration;
5+
import org.flywaydb.core.api.migration.Context;
6+
import org.springframework.stereotype.Component;
7+
8+
@Component
9+
public class V4_47__Force_es_reindex_all extends BaseJavaMigration {
10+
11+
@Override
12+
public void migrate(Context context) throws Exception {
13+
try (Statement statement = context.getConnection().createStatement()) {
14+
statement.execute(
15+
"""
16+
DELETE FROM indexing_status;
17+
""");
18+
}
19+
}
20+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.springframework.stereotype.Component;
77

88
@Component
9-
public class V4_46__Create_Dependencies_instead_of_fromStarterPack_Column
9+
public class V4_48__Create_Dependencies_instead_of_fromStarterPack_Column
1010
extends BaseJavaMigration {
1111

1212
@Override

openaev-api/src/main/java/io/openaev/migration/V4_47__Add_catalog_connector.java renamed to openaev-api/src/main/java/io/openaev/migration/V4_49__Add_catalog_connector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.springframework.stereotype.Component;
77

88
@Component
9-
public class V4_47__Add_catalog_connector extends BaseJavaMigration {
9+
public class V4_49__Add_catalog_connector extends BaseJavaMigration {
1010

1111
@Override
1212
public void migrate(Context context) throws Exception {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.springframework.stereotype.Component;
77

88
@Component
9-
public class V4_48__Update_catalog_connector_configuration extends BaseJavaMigration {
9+
public class V4_50__Update_catalog_connector_configuration extends BaseJavaMigration {
1010
@Override
1111
public void migrate(Context context) throws Exception {
1212
try (Statement select = context.getConnection().createStatement()) {

openaev-api/src/main/java/io/openaev/rest/scenario/ScenarioApi.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import io.openaev.aop.RBAC;
1313
import io.openaev.database.model.*;
1414
import io.openaev.database.raw.RawPaginationScenario;
15+
import io.openaev.database.raw.RawPlayer;
1516
import io.openaev.database.repository.*;
1617
import io.openaev.healthcheck.dto.HealthCheck;
1718
import io.openaev.rest.asset.endpoint.form.EndpointOutput;
@@ -251,6 +252,15 @@ public List<TeamOutput> replaceScenarioTeams(
251252
return this.scenarioService.replaceTeams(scenarioId, input.getTeamIds());
252253
}
253254

255+
@GetMapping(SCENARIO_URI + "/{scenarioId}/players")
256+
@RBAC(
257+
resourceId = "#scenarioId",
258+
actionPerformed = Action.READ,
259+
resourceType = ResourceType.SCENARIO)
260+
public Iterable<RawPlayer> getPlayersByScenario(@PathVariable String scenarioId) {
261+
return userRepository.rawPlayersByScenarioId(scenarioId);
262+
}
263+
254264
@Transactional(rollbackOn = Exception.class)
255265
@PutMapping(SCENARIO_URI + "/{scenarioId}/teams/{teamId}/players/enable")
256266
@RBAC(

openaev-api/src/main/java/io/openaev/service/PermissionService.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import io.openaev.aop.RBACAspect;
44
import io.openaev.database.model.*;
5+
import io.openaev.database.repository.EvaluationRepository;
6+
import io.openaev.database.repository.ObjectiveRepository;
57
import io.openaev.rest.exception.ElementNotFoundException;
68
import io.openaev.rest.inject.service.InjectService;
79
import io.openaev.rest.injector_contract.InjectorContractService;
@@ -46,12 +48,18 @@ public class PermissionService {
4648

4749
private static final EnumSet<ResourceType> RESOURCES_USING_PARENT_PERMISSION =
4850
EnumSet.of(
49-
ResourceType.INJECT, ResourceType.NOTIFICATION_RULE, ResourceType.INJECTOR_CONTRACT);
51+
ResourceType.INJECT,
52+
ResourceType.NOTIFICATION_RULE,
53+
ResourceType.INJECTOR_CONTRACT,
54+
ResourceType.OBJECTIVE,
55+
ResourceType.EVALUATION);
5056

5157
private final GrantService grantService;
5258
private final InjectService injectService;
5359
private final NotificationRuleService notificationRuleService;
5460
private final InjectorContractService injectorContractService;
61+
private final ObjectiveRepository objectiveRepository;
62+
private final EvaluationRepository evaluationRepository;
5563

5664
@Transactional
5765
public boolean hasPermission(
@@ -190,6 +198,27 @@ private Target resolveTarget(
190198
return new Target(ic.getPayload().getId(), ResourceType.PAYLOAD, action);
191199
}
192200
return new Target(ic.getId(), ResourceType.INJECTOR_CONTRACT, action);
201+
} else if (resourceType == ResourceType.OBJECTIVE) {
202+
Objective objective =
203+
objectiveRepository
204+
.findById(resourceId)
205+
.orElseThrow(
206+
() -> new ElementNotFoundException("Objective not found with id: " + resourceId));
207+
// parent action rule: anything non-READ becomes WRITE on the parent
208+
Action parentAction = (action == Action.READ) ? Action.READ : Action.WRITE;
209+
return new Target(
210+
objective.getParentResourceId(), objective.getParentResourceType(), parentAction);
211+
} else if (resourceType == ResourceType.EVALUATION) {
212+
Evaluation evaluation =
213+
evaluationRepository
214+
.findById(resourceId)
215+
.orElseThrow(
216+
() ->
217+
new ElementNotFoundException("Evaluation not found with id: " + resourceId));
218+
// parent action rule: anything non-READ becomes WRITE on the parent
219+
Action parentAction = (action == Action.READ) ? Action.READ : Action.WRITE;
220+
return new Target(
221+
evaluation.getParentResourceId(), evaluation.getParentResourceType(), parentAction);
193222
}
194223
return new Target(resourceId, resourceType, action);
195224
}

0 commit comments

Comments
 (0)