generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PI-2548 Add endpoints to add/remove IMS roles
- Loading branch information
1 parent
2aaca2d
commit 595e223
Showing
10 changed files
with
96 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 30 additions & 8 deletions
38
...ims-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,52 @@ | ||
package uk.gov.justice.digital.hmpps | ||
|
||
import org.junit.jupiter.api.Test | ||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.hamcrest.Matchers.equalTo | ||
import org.junit.jupiter.api.* | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT | ||
import org.springframework.boot.test.mock.mockito.MockBean | ||
import org.springframework.ldap.NameNotFoundException | ||
import org.springframework.ldap.core.LdapTemplate | ||
import org.springframework.ldap.support.LdapNameBuilder | ||
import org.springframework.test.web.servlet.MockMvc | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status | ||
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken | ||
import uk.gov.justice.digital.hmpps.telemetry.TelemetryService | ||
|
||
@AutoConfigureMockMvc | ||
@SpringBootTest(webEnvironment = RANDOM_PORT) | ||
@TestMethodOrder(MethodOrderer.OrderAnnotation::class) | ||
internal class IntegrationTest { | ||
@Autowired | ||
lateinit var mockMvc: MockMvc | ||
|
||
@MockBean | ||
lateinit var telemetryService: TelemetryService | ||
@Autowired | ||
lateinit var ldapTemplate: LdapTemplate | ||
|
||
@Test | ||
fun `API call retuns a success response`() { | ||
@Order(1) | ||
fun `can add role`() { | ||
mockMvc | ||
.perform(get("/example/123").withToken()) | ||
.perform(put("/user/test.user/role").withToken()) | ||
.andExpect(status().is2xxSuccessful) | ||
|
||
val role = ldapTemplate.lookupContext(LdapNameBuilder.newInstance("cn=IMSBT001,cn=test.user").build()) | ||
|
||
assertThat(role.dn.toString(), equalTo("cn=IMSBT001,cn=test.user")) | ||
} | ||
|
||
@Test | ||
@Order(2) | ||
fun `can remove role`() { | ||
mockMvc | ||
.perform(delete("/user/test.user/role").withToken()) | ||
.andExpect(status().is2xxSuccessful) | ||
|
||
assertThrows<NameNotFoundException> { | ||
ldapTemplate.lookupContext(LdapNameBuilder.newInstance("cn=IMSBT001,cn=test.user").build()) | ||
} | ||
} | ||
} |
17 changes: 0 additions & 17 deletions
17
...s/ims-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/controller/ApiController.kt
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
.../ims-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/controller/UserController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package uk.gov.justice.digital.hmpps.controller | ||
|
||
import org.springframework.ldap.core.LdapTemplate | ||
import org.springframework.security.access.prepost.PreAuthorize | ||
import org.springframework.web.bind.annotation.DeleteMapping | ||
import org.springframework.web.bind.annotation.PathVariable | ||
import org.springframework.web.bind.annotation.PutMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
import uk.gov.justice.digital.hmpps.ldap.DeliusRole | ||
import uk.gov.justice.digital.hmpps.ldap.addRole | ||
import uk.gov.justice.digital.hmpps.ldap.removeRole | ||
|
||
@RestController | ||
class UserController(private val ldapTemplate: LdapTemplate) { | ||
@PutMapping(value = ["/user/{username}/role"]) | ||
@PreAuthorize("hasRole('PROBATION_API__PATHFINDER__USER_ROLES__RW')") | ||
fun addRole(@PathVariable username: String) = ldapTemplate.addRole(username, Role.IMSBT001) | ||
|
||
@DeleteMapping(value = ["/user/{username}/role"]) | ||
@PreAuthorize("hasRole('PROBATION_API__PATHFINDER__USER_ROLES__RW')") | ||
fun removeRole(@PathVariable username: String) = ldapTemplate.removeRole(username, Role.IMSBT001) | ||
} | ||
|
||
enum class Role( | ||
override val description: String, | ||
override val mappedRole: String | ||
) : DeliusRole { | ||
IMSBT001("IMS User", "IMSBT001") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
dn: ou=Users,dc=moj,dc=com | ||
objectclass: top | ||
objectclass: organizationalUnit | ||
ou: Users | ||
|
||
dn: cn=test.user,ou=Users,dc=moj,dc=com | ||
cn: test.user | ||
objectclass: NDUser | ||
objectclass: inetOrgPerson | ||
objectclass: top | ||
givenName: Test | ||
sn: User | ||
mail: [email protected] | ||
|
||
dn: cn=ndRoleCatalogue,ou=Users,dc=moj,dc=com | ||
description: Role Catalogue | ||
objectclass: top | ||
cn: ndRoleCatalogue | ||
|
||
dn: cn=IMSBT001,cn=ndRoleCatalogue,ou=Users,dc=moj,dc=com | ||
description: Navigate to Intelligence Management System | ||
objectClass: NDRole | ||
objectClass: top | ||
cn: IMSBT001 |