Skip to content

Commit

Permalink
Merge pull request #30 from FINTLabs/add-menuitem-me-endpoint
Browse files Browse the repository at this point in the history
FKS-951: Add menuitems to /me endpoint
  • Loading branch information
sourcecodeas authored Dec 18, 2024
2 parents 7fb3aae + 67e0d09 commit fe38022
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/no/fintlabs/user/LoggedOnUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -18,4 +19,5 @@ public class LoggedOnUser {
String organisationId;
String mail;
List<AuthRole> roles;
List<MenuItem> menuItems;
}
5 changes: 4 additions & 1 deletion src/main/java/no/fintlabs/user/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -75,13 +76,15 @@ public ResponseEntity<LoggedOnUser> getLoggedOnUser(@AuthenticationPrincipal Jwt
FintJwtEndUserPrincipal principal = FintJwtEndUserPrincipal.from(jwt);

List<AuthRole> userRoles = authorizationClient.getUserRoles();
List<MenuItem> menuItems = authorizationClient.getMenuItems();

LoggedOnUser loggedOnUser = new LoggedOnUser(
principal.getGivenName(),
principal.getSurname(),
principal.getOrgId(),
principal.getMail(),
userRoles
userRoles,
menuItems
);

return new ResponseEntity<>(loggedOnUser, HttpStatus.OK);
Expand Down
7 changes: 6 additions & 1 deletion src/test/java/no/fintlabs/user/UserControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand All @@ -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
Expand Down

0 comments on commit fe38022

Please sign in to comment.