From dd317881af9b255ba86ce718290329840ebbcc30 Mon Sep 17 00:00:00 2001 From: Morten Solberg Date: Sun, 3 Dec 2023 10:42:48 +0100 Subject: [PATCH] FKS-364: Upgrade to latest authorization library to support multiple roles on a user. --- build.gradle | 2 +- src/main/java/no/fintlabs/user/User.java | 14 ++++++++++++-- src/main/java/no/fintlabs/user/UserService.java | 2 +- .../java/no/fintlabs/user/UserServiceTest.java | 16 +++++----------- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/build.gradle b/build.gradle index 33a83e7..a501bca 100644 --- a/build.gradle +++ b/build.gradle @@ -44,7 +44,7 @@ dependencies { implementation 'no.fintlabs:fint-kafka:3.0.0-rc-1' implementation 'no.fintlabs:fint-antlr:1.1.1' implementation 'no.fintlabs:fint-resource-server-security:1.1.0' - implementation 'no.fintlabs:fint-kontroll-authorization:1.1.3' + implementation 'no.fintlabs:fint-kontroll-authorization:1.1.6' 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/User.java b/src/main/java/no/fintlabs/user/User.java index 8806d35..1057184 100644 --- a/src/main/java/no/fintlabs/user/User.java +++ b/src/main/java/no/fintlabs/user/User.java @@ -1,9 +1,19 @@ package no.fintlabs.user; -import lombok.*; +import jakarta.persistence.Column; +import jakarta.persistence.ElementCollection; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; import lombok.extern.slf4j.Slf4j; -import jakarta.persistence.*; import java.util.ArrayList; import java.util.List; import java.util.UUID; diff --git a/src/main/java/no/fintlabs/user/UserService.java b/src/main/java/no/fintlabs/user/UserService.java index 9644ebb..a69ffd9 100644 --- a/src/main/java/no/fintlabs/user/UserService.java +++ b/src/main/java/no/fintlabs/user/UserService.java @@ -129,7 +129,7 @@ public List getSimpleUsers( public List getAllAutorizedOrgUnitIDs() { - List scope = authorizationClient.getUserScopes(); + List scope = authorizationClient.getUserScopesList(); List authorizedOrgIDs = scope.stream() .filter(s -> s.getObjectType().equals("user")) .map(Scope::getOrgUnits) diff --git a/src/test/java/no/fintlabs/user/UserServiceTest.java b/src/test/java/no/fintlabs/user/UserServiceTest.java index 9d47995..2b886e6 100644 --- a/src/test/java/no/fintlabs/user/UserServiceTest.java +++ b/src/test/java/no/fintlabs/user/UserServiceTest.java @@ -29,44 +29,40 @@ public void init(){ @Test public void testGetAllAutorizedOrgUnitIDs() { Scope scope1 = Scope.builder() - .id("1") .objectType("user") .orgUnits(List.of("198","2","3")) .build(); Scope scope2 = Scope.builder() - .id("2") .objectType("role") .orgUnits(List.of("198","2","3")) .build(); List scopes= List.of(scope1,scope2); List authorizedOrgIDs = List.of("198","2","3"); - when(authorizationClient.getUserScopes()).thenReturn(scopes); + when(authorizationClient.getUserScopesList()).thenReturn(scopes); List foundOrgIDs= userService.getAllAutorizedOrgUnitIDs(); assertEquals(authorizedOrgIDs,foundOrgIDs); - verify(authorizationClient, times(1)).getUserScopes(); + verify(authorizationClient, times(1)).getUserScopesList(); } @Test void testCompareRequestedOrgUnitIDsWithOPA() { Scope scope1 = Scope.builder() - .id("1") .objectType("user") .orgUnits(List.of("198","2","3")) .build(); Scope scope2 = Scope.builder() - .id("2") .objectType("role") .orgUnits(List.of("198","2","3")) .build(); List scopes= List.of(scope1,scope2); List requestedOrgIDs = List.of("198","2","5"); List authorizedOrgIDsForRequest = List.of("198","2"); - when(authorizationClient.getUserScopes()).thenReturn(scopes); + when(authorizationClient.getUserScopesList()).thenReturn(scopes); List foundOrgIDs = userService.compareRequestedOrgUnitIDsWithOPA(requestedOrgIDs); @@ -76,12 +72,10 @@ void testCompareRequestedOrgUnitIDsWithOPA() { @Test void testGetDetailedUserById_shouldPermitAccess(){ Scope scope1 = Scope.builder() - .id("1") .objectType("user") .orgUnits(List.of("198","2","3")) .build(); Scope scope2 = Scope.builder() - .id("2") .objectType("role") .orgUnits(List.of("198","2","3")) .build(); @@ -102,7 +96,7 @@ void testGetDetailedUserById_shouldPermitAccess(){ FintJwtEndUserPrincipal fintJwtEndUserPrincipal = new FintJwtEndUserPrincipal(); fintJwtEndUserPrincipal.setMail("titten@tei.no"); - when(authorizationClient.getUserScopes()).thenReturn(scopes); + when(authorizationClient.getUserScopesList()).thenReturn(scopes); when(userRepository.findById(1L)).thenReturn(Optional.of(requestedUser)); DetailedUser requestedDetailedUser = requestedUser.toDetailedUser(); @@ -113,4 +107,4 @@ void testGetDetailedUserById_shouldPermitAccess(){ } -} \ No newline at end of file +}