Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@ on [Keep a CHANGELOG](http://keepachangelog.com/). This project adheres to
[Semantic Versioning](http://semver.org/).

## [Unreleased]

# [17.103.10] - 2026-03-31
## Changed
- framework-stream-rest-resources dependency is added to expose `/internal` endpoints

# [17.103.9] - 2026-03-24
## Changed
- event-store bumped to 17.103.8-M2 to
- Notification-based event linking and publishing via CDI events, enabled via JNDI:
- pre.publish.worker.notified (linking)
- event.publishing.worker.notified (publishing)

# [17.103.8] - 2025-12-09
### Changed
- Used JsonFactory instead of Json.create methods
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,51 @@
package uk.gov.moj.cpp.accesscontrol.sjp.providers;

import java.util.List;

import org.apache.commons.lang3.StringUtils;

public class ProsecutingAuthorityAccess {

public static final String ALL_PROSECUTING_AUTHORITIES = "ALL";

public final static ProsecutingAuthorityAccess NONE = new ProsecutingAuthorityAccess(null);
public final static ProsecutingAuthorityAccess NONE = new ProsecutingAuthorityAccess(null, null);
public final static ProsecutingAuthorityAccess ALL = new ProsecutingAuthorityAccess(ALL_PROSECUTING_AUTHORITIES);

private String prosecutingAuthority;

private List<String> agentProsecutorAuthorityAccess;

private ProsecutingAuthorityAccess(final String prosecutingAuthority) {
this.prosecutingAuthority = prosecutingAuthority;
}

public static ProsecutingAuthorityAccess of(final String prosecutingAuthority) {
private ProsecutingAuthorityAccess(final String prosecutingAuthority, final List<String> agentProsecutorAuthorityAccess) {
this.prosecutingAuthority = prosecutingAuthority;
this.agentProsecutorAuthorityAccess = agentProsecutorAuthorityAccess;
}

if (StringUtils.isEmpty(prosecutingAuthority)) {
public static ProsecutingAuthorityAccess of(final String prosecutingAuthority, final List<String> agentProsecutorAuthorityAccess) {
if (StringUtils.isEmpty(prosecutingAuthority) && (agentProsecutorAuthorityAccess == null || agentProsecutorAuthorityAccess.isEmpty())) {
return NONE;
} else if (prosecutingAuthority.equals(ALL.getProsecutingAuthority())) {
return ALL;
}

return new ProsecutingAuthorityAccess(prosecutingAuthority);
return new ProsecutingAuthorityAccess(prosecutingAuthority, agentProsecutorAuthorityAccess);
}

public String getProsecutingAuthority() {
return prosecutingAuthority;
}

public List<String> getAgentProsecutorAuthorityAccess() {
return agentProsecutorAuthorityAccess;
}

public boolean hasAccess(final String prosecutingAuthority) {
return ALL.getProsecutingAuthority().equals(this.getProsecutingAuthority()) ||
(this.getProsecutingAuthority() != null &&
this.getProsecutingAuthority().equals(prosecutingAuthority));
this.getProsecutingAuthority().equals(prosecutingAuthority)) ||
(agentProsecutorAuthorityAccess != null && agentProsecutorAuthorityAccess.contains(prosecutingAuthority));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@
import javax.inject.Inject;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;
import javax.json.JsonString;
import javax.json.JsonValue;

import static java.lang.Boolean.valueOf;
import static uk.gov.moj.cpp.accesscontrol.drools.constants.AccessControlFrameworkComponent.ACCESS_CONTROL;
import static uk.gov.moj.cpp.accesscontrol.sjp.providers.SjpProvider.jsonBuilderFactory;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Provider
@ApplicationScoped
public class ProsecutingAuthorityProvider {
Expand Down Expand Up @@ -62,7 +68,15 @@ public ProsecutingAuthorityAccess getCurrentUsersProsecutingAuthorityAccess(fina

private ProsecutingAuthorityAccess buildFromResponseJson(final JsonObject responsePayload) {

return ProsecutingAuthorityAccess.of(responsePayload.getString("prosecutingAuthorityAccess", null));
List<String> agentProsecutors = Optional
.ofNullable(responsePayload.getJsonArray("agentProsecutorAuthorityAccess"))
.map(arr -> arr.getValuesAs(JsonString.class)
.stream()
.map(JsonString::getString)
.collect(Collectors.toList()))
.orElse(Collections.emptyList());

return ProsecutingAuthorityAccess.of(responsePayload.getString("prosecutingAuthorityAccess", null), agentProsecutors);
}

private JsonValue buildRequestPayload(final JsonEnvelope envelope) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;

import java.util.ArrayList;

import org.junit.jupiter.api.Test;

public class ProsecutingAuthorityAccessTest {
Expand All @@ -24,7 +26,7 @@ public void shouldBuildNoProsecutingAuthorityAccess() {
@Test
public void shouldBuildSingleProsecutingAuthorityAccess() {

ProsecutingAuthorityAccess prosecutingAuthorityAccess = ProsecutingAuthorityAccess.of(PROSECUTOR);
ProsecutingAuthorityAccess prosecutingAuthorityAccess = ProsecutingAuthorityAccess.of(PROSECUTOR, new ArrayList<>());

assertThat(prosecutingAuthorityAccess.getProsecutingAuthority(), is(PROSECUTOR));
assertThat(prosecutingAuthorityAccess.hasAccess(PROSECUTOR), is(true));
Expand All @@ -35,7 +37,7 @@ public void shouldBuildSingleProsecutingAuthorityAccess() {
@Test
public void shouldReturnFalseForInvalidProsecutingAuthorityAccess() {

ProsecutingAuthorityAccess prosecutingAuthorityAccess = ProsecutingAuthorityAccess.of("OTHER_PROSECUTOR");
ProsecutingAuthorityAccess prosecutingAuthorityAccess = ProsecutingAuthorityAccess.of("OTHER_PROSECUTOR", new ArrayList<>());

assertThat(prosecutingAuthorityAccess.getProsecutingAuthority(), is("OTHER_PROSECUTOR"));
assertThat(prosecutingAuthorityAccess.hasAccess(PROSECUTOR), is(false));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package uk.gov.moj.cpp.accesscontrol.sjp.providers;

import static java.util.UUID.randomUUID;
import static javax.json.Json.createArrayBuilder;
import static javax.json.Json.createObjectBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
Expand All @@ -16,13 +19,21 @@
import uk.gov.justice.services.core.enveloper.Enveloper;
import uk.gov.justice.services.core.requester.Requester;
import uk.gov.justice.services.messaging.JsonEnvelope;
import uk.gov.justice.services.messaging.JsonObjects;
import uk.gov.justice.services.messaging.spi.DefaultJsonMetadata;
import uk.gov.justice.services.test.utils.core.enveloper.EnveloperFactory;
import uk.gov.justice.services.test.utils.core.messaging.JsonEnvelopeBuilder;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;

import java.util.List;
import java.util.Optional;

import javax.json.JsonArrayBuilder;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;

import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
Expand Down Expand Up @@ -128,6 +139,17 @@ public void shouldReturnFalseIfUserHasSingleProsecutingAuthorityAccessForOther()
assertLogStatement();
}

@Test
public void shouldReturnTrueIfUserHasSingleProsecutingAuthorityAccessForOtherButAgentHasAccess() {

givenUserHasAgentProsecutingAuthorityAccess("ANOTHER_TEST");

assertThat(prosecutingAuthorityProvider.userHasProsecutingAuthorityAccess(
callingEnvelope, PROSECUTING_AUTHORITY), is(true));

assertLogStatement();
}

@Test
public void shouldReturnFalseIfUserHasNoProsecutingAuthorityAccess() {

Expand Down Expand Up @@ -177,6 +199,27 @@ private JsonEnvelope userDetailsResponse(final String prosecutingAuthorityAccess
return envelope().withPayloadOf(prosecutingAuthorityAccess, "prosecutingAuthorityAccess").build();
}

private void givenUserHasAgentProsecutingAuthorityAccess(final String prosecutingAuthorityAccess) {
doReturn(userDetailsResponse(prosecutingAuthorityAccess, List.of(PROSECUTING_AUTHORITY)))
.when(requester)
.requestAsAdmin(any());
}

private JsonEnvelope userDetailsResponse(final String prosecutingAuthorityAccess, final List<String> agentProsecutorAuthorityAccess) {
final JsonObjectBuilder userObjectBuilder = createObjectBuilder();
Optional.of(prosecutingAuthorityAccess).ifPresent(s -> userObjectBuilder.add("prosecutingAuthorityAccess", s));

final JsonArrayBuilder arrayBuilder = createArrayBuilder();

agentProsecutorAuthorityAccess.forEach(arrayBuilder::add);

userObjectBuilder.add("agentProsecutorAuthorityAccess", arrayBuilder);

final JsonObject jsonObject = userObjectBuilder.build();

return envelope().withPayloadFrom(jsonObject).build();
}

private void assertLogStatement() {
verify(logger).trace("Performing prosecuting authority access control for action: {}", ACTION_NAME);
}
Expand Down
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@
<file-service.version>17.103.2</file-service.version>
<framework-libraries.version>17.103.1</framework-libraries.version>
<framework.version>17.103.2</framework.version>
<event-store.version>17.103.7</event-store.version>
<event-store.version>17.103.8</event-store.version>
<cpp.common-bom.version>17.103.3-M2</cpp.common-bom.version>

<cpp.framework.version>${framework.version}</cpp.framework.version>

<assignment.version>8.0.5</assignment.version>
<usersgroups.version>17.0.37</usersgroups.version>
<progression.version>17.0.219</progression.version>
<hearing.version>17.0.144</hearing.version>
<sjp.version>17.0.129</sjp.version>
<referencedata.version>17.103.124</referencedata.version>
<usersgroups.version>17.104.50</usersgroups.version>
<progression.version>17.0.269</progression.version>
<hearing.version>17.104.173</hearing.version>
<sjp.version>17.104.180</sjp.version>
<referencedata.version>17.104.136</referencedata.version>
<jaxb-api.version>2.3.1</jaxb-api.version>
<azure-storage-version>8.4.0</azure-storage-version>
<versions-manven-plugin.version>2.15.0</versions-manven-plugin.version>
Expand Down
4 changes: 4 additions & 0 deletions service-components/event/event-indexer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
<groupId>uk.gov.justice.event-store</groupId>
<artifactId>subscription-event-interceptors</artifactId>
</dependency>
<dependency>
<groupId>uk.gov.justice.event-store</groupId>
<artifactId>framework-stream-rest-resources</artifactId>
</dependency>
<dependency>
<groupId>uk.gov.justice.event-store</groupId>
<artifactId>subscription-manager</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions service-components/event/event-listener/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
<groupId>uk.gov.justice.framework-api</groupId>
<artifactId>framework-api-event-listener-interceptors</artifactId>
</dependency>
<dependency>
<groupId>uk.gov.justice.event-store</groupId>
<artifactId>framework-stream-rest-resources</artifactId>
</dependency>
<dependency>
<groupId>uk.gov.justice.event-store</groupId>
<artifactId>subscription-manager</artifactId>
Expand Down
Loading