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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import jakarta.inject.Inject;
import jakarta.json.JsonObject;
import jakarta.json.JsonObjectBuilder;
import jakarta.json.JsonString;
import jakarta.json.JsonValue;

import java.util.Collections;
Expand Down Expand Up @@ -69,9 +70,9 @@ private ProsecutingAuthorityAccess buildFromResponseJson(final JsonObject respon

final List<String> agentProsecutors = Optional
.ofNullable(responsePayload.getJsonArray("agentProsecutorAuthorityAccess"))
.map(agentAccess -> agentAccess.getValuesAs(JsonObject.class)
.map(agentAccess -> agentAccess.getValuesAs(JsonString.class)
.stream()
.map(agent -> agent.getString("prosecutingAuthority"))
.map(JsonString::getString)
.collect(Collectors.toList()))
.orElse(Collections.emptyList());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.gov.moj.cpp.accesscontrol.sjp.providers;

import static java.util.Arrays.asList;
import static java.util.UUID.randomUUID;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -162,6 +163,41 @@ public void shouldIgnoreAccessControlIfTheAccessControlDisabledPropertyIsTrueFor
verify(logger).trace("Skipping prosecuting authority access control due to configuration");
}

@Test
public void shouldParseAgentProsecutorAuthorityAccessAsListOfStrings() {

when(requester.requestAsAdmin(any()))
.thenReturn(userDetailsResponseWithAgentAccess(PROSECUTING_AUTHORITY, "TFL", "TVL"));

final ProsecutingAuthorityAccess access =
prosecutingAuthorityProvider.getCurrentUsersProsecutingAuthorityAccess(callingEnvelope);

assertThat(access.getProsecutingAuthority(), is(PROSECUTING_AUTHORITY));
assertThat(access.getAgentProsecutorAuthorityAccess(), is(asList("TFL", "TVL")));

assertLogStatement();
}

@Test
public void shouldGrantAccessViaAgentProsecutorAuthority() {

when(requester.requestAsAdmin(any()))
.thenReturn(userDetailsResponseWithAgentAccess(PROSECUTING_AUTHORITY, "TFL", "TVL"));

assertThat(prosecutingAuthorityProvider.userHasProsecutingAuthorityAccess(
callingEnvelope, "TVL"), is(true));

assertLogStatement();
}

private JsonEnvelope userDetailsResponseWithAgentAccess(final String prosecutingAuthorityAccess,
final String... agentProsecutorAuthorities) {
return envelope()
.withPayloadOf(prosecutingAuthorityAccess, "prosecutingAuthorityAccess")
.withPayloadOf(agentProsecutorAuthorities, "agentProsecutorAuthorityAccess")
.build();
}

private void givenUserHasNoProsecutingAuthorityAccess() {
final JsonEnvelope build = JsonEnvelopeBuilder.envelope()
.withPayloadOf("Fred Bloggs", "name")
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<assignment.version>8.0.5</assignment.version>
<usersgroups.version>17.104.48</usersgroups.version>
<progression.version>17.0.262</progression.version>
<hearing.version>17.104.168</hearing.version>
<hearing.version>17.104.176</hearing.version>
<sjp.version>17.103.169</sjp.version>
<referencedata.version>17.103.133</referencedata.version>
<versions-manven-plugin.version>2.15.0</versions-manven-plugin.version>
Expand Down
Loading