Skip to content

Commit 781bb9c

Browse files
Rename role endpoints to include
1 parent cebbd0c commit 781bb9c

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/extensions/AuthorisationFilter.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,19 @@ class AuthorisationFilter
5252
}
5353

5454
val consumersRoles = consumerConfig?.roles
55-
val roleEndpoints =
55+
val roleIncludes =
5656
buildList {
5757
for (consumerRole in consumersRoles.orEmpty()) {
5858
for (role in rolesConfig.roles) {
5959
if (role.name == consumerRole) {
60-
addAll(role.endpoints)
60+
addAll(role.includes)
6161
}
6262
}
6363
}
6464
}
6565

6666
val roleResult =
67-
authoriseConsumerService.doesConsumerHaveRoleAccess(roleEndpoints, requestedPath)
67+
authoriseConsumerService.doesConsumerHaveRoleAccess(roleIncludes, requestedPath)
6868
if (!roleResult) {
6969
res.sendError(HttpServletResponse.SC_FORBIDDEN, "Unable to authorise $requestedPath for $subjectDistinguishedName")
7070
return

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/roleconfig/Role.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.roleconfig
22

33
data class Role(
44
val name: String,
5-
val endpoints: List<String>,
5+
val includes: List<String>,
66
)

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/services/internal/AuthoriseConsumerService.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ class AuthoriseConsumerService {
2020
}
2121

2222
fun doesConsumerHaveRoleAccess(
23-
consumerRolesConfigPaths: List<String>?,
23+
consumerRolesInclude: List<String>,
2424
requestPath: String,
2525
): Boolean {
26-
consumerRolesConfigPaths?.forEach {
26+
consumerRolesInclude.forEach {
2727
if (Regex(it).matches(requestPath)) {
2828
return true
2929
}

src/main/resources/roles.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
data:
22
roles:
33
- name: "private-prison"
4-
endpoints:
4+
includes:
55
- "/v1/persons/[^/]*$"

src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/services/internal/AuthoriseConsumerServiceTest.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ internal class AuthoriseConsumerServiceTest(
4242
}
4343

4444
describe("doesConsumerHaveRoleAccess") {
45-
val consumerRolesConfigPaths = listOf("/persons/.*")
45+
val consumerRolesInclude = listOf("/persons/.*")
4646

4747
it("access is allowed when the path is listed in the role included paths") {
4848
val authResult =
4949
authoriseConsumerService.doesConsumerHaveRoleAccess(
50-
consumerRolesConfigPaths,
50+
consumerRolesInclude,
5151
requestedPath,
5252
)
5353
authResult.shouldBeTrue()
@@ -60,7 +60,7 @@ internal class AuthoriseConsumerServiceTest(
6060

6161
it("when the path isn't listed as allowed on the consumer") {
6262
val invalidPath = "/some-other-path/123"
63-
val result = authoriseConsumerService.doesConsumerHaveRoleAccess(consumerRolesConfigPaths, invalidPath)
63+
val result = authoriseConsumerService.doesConsumerHaveRoleAccess(consumerRolesInclude, invalidPath)
6464
result.shouldBeFalse()
6565
}
6666
}

0 commit comments

Comments
 (0)