diff --git a/build.gradle b/build.gradle index b109c3d..084a4a6 100644 --- a/build.gradle +++ b/build.gradle @@ -45,8 +45,8 @@ dependencies { implementation 'org.springframework.kafka:spring-kafka' implementation 'no.fintlabs:fint-kafka:3.0.0-rc-1' implementation 'no.fintlabs:fint-resource-server-security:1.1.0' - implementation 'no.fintlabs:fint-kontroll-auth:1.3.0' - // implementation files('/Users/mortensolberg/Development/vigoikt/fint-kontroll-authorization/build/libs/fint-kontroll-auth-0-SNAPSHOT-plain.jar') + implementation 'no.fintlabs:fint-kontroll-auth:1.3.2' +// implementation files('/Users/mortensolberg/Development/vigoikt/fint-kontroll-authorization/build/libs/fint-kontroll-auth-0-SNAPSHOT-plain.jar') implementation 'no.fint:fint-model-resource:0.4.1' implementation 'io.projectreactor:reactor-core' implementation 'org.apache.commons:commons-collections4:4.4' diff --git a/src/main/java/no/fintlabs/user/LoggedOnUser.java b/src/main/java/no/fintlabs/user/LoggedOnUser.java index df39165..1715c23 100644 --- a/src/main/java/no/fintlabs/user/LoggedOnUser.java +++ b/src/main/java/no/fintlabs/user/LoggedOnUser.java @@ -5,6 +5,7 @@ import lombok.Getter; import lombok.Setter; import no.fintlabs.opa.model.AuthRole; +import no.fintlabs.opa.model.MenuItem; import java.util.List; @@ -18,4 +19,5 @@ public class LoggedOnUser { String organisationId; String mail; List roles; + List menuItems; } diff --git a/src/main/java/no/fintlabs/user/UserController.java b/src/main/java/no/fintlabs/user/UserController.java index 8e86a34..dc9007f 100644 --- a/src/main/java/no/fintlabs/user/UserController.java +++ b/src/main/java/no/fintlabs/user/UserController.java @@ -3,6 +3,7 @@ import lombok.extern.slf4j.Slf4j; import no.fintlabs.opa.AuthorizationClient; import no.fintlabs.opa.model.AuthRole; +import no.fintlabs.opa.model.MenuItem; import no.vigoiks.resourceserver.security.FintJwtEndUserPrincipal; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -75,13 +76,15 @@ public ResponseEntity getLoggedOnUser(@AuthenticationPrincipal Jwt FintJwtEndUserPrincipal principal = FintJwtEndUserPrincipal.from(jwt); List userRoles = authorizationClient.getUserRoles(); + List menuItems = authorizationClient.getMenuItems(); LoggedOnUser loggedOnUser = new LoggedOnUser( principal.getGivenName(), principal.getSurname(), principal.getOrgId(), principal.getMail(), - userRoles + userRoles, + menuItems ); return new ResponseEntity<>(loggedOnUser, HttpStatus.OK); diff --git a/src/test/java/no/fintlabs/user/UserControllerTest.java b/src/test/java/no/fintlabs/user/UserControllerTest.java index 4b63ef5..a4d5231 100644 --- a/src/test/java/no/fintlabs/user/UserControllerTest.java +++ b/src/test/java/no/fintlabs/user/UserControllerTest.java @@ -4,6 +4,7 @@ import jakarta.servlet.ServletException; import no.fintlabs.opa.AuthorizationClient; import no.fintlabs.opa.model.AuthRole; +import no.fintlabs.opa.model.MenuItem; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -72,6 +73,7 @@ public void shouldGetLoggedOnUserInformation() throws Exception { createSecurityContext(jwt, role); when(authorizationClient.getUserRoles()).thenReturn(List.of(new AuthRole("sa", "Systemadministrator"))); + when(authorizationClient.getMenuItems()).thenReturn(List.of(new MenuItem("/test/url", "Test menuitem"))); mockMvc.perform(get("/api/users/me")) .andExpect(status().isOk()) @@ -81,9 +83,12 @@ public void shouldGetLoggedOnUserInformation() throws Exception { .andExpect(jsonPath("$.organisationId").value("89898989")) .andExpect(jsonPath("$.roles").isArray()) .andExpect(jsonPath("$.roles[0].id").value("sa")) - .andExpect(jsonPath("$.roles[0].name").value("Systemadministrator")); + .andExpect(jsonPath("$.roles[0].name").value("Systemadministrator")) + .andExpect(jsonPath("$.menuItems[0].text").value("Test menuitem")) + .andExpect(jsonPath("$.menuItems[0].url").value("/test/url")); verify(authorizationClient, times(1)).getUserRoles(); + verify(authorizationClient, times(1)).getMenuItems(); } @Test