From 641065c0be2ad25377f1ef709f64b23d0eeeffbe Mon Sep 17 00:00:00 2001 From: Craig Yu Date: Mon, 26 Aug 2024 15:42:54 -0700 Subject: [PATCH 1/2] fix: add client id to concrete roles --- .../java/ca/bc/gov/backendstartapi/config/Constants.java | 1 + .../bc/gov/backendstartapi/security/JwtSecurityUtil.java | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/config/Constants.java b/backend/src/main/java/ca/bc/gov/backendstartapi/config/Constants.java index d5c458468..aa1c6250e 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/config/Constants.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/config/Constants.java @@ -8,4 +8,5 @@ public final class Constants { public static final String INCOMPLETE_SEEDLOT_STATUS = "INC"; public static final String PENDING_SEEDLOT_STATUS = "PND"; public static final String SUBMITTED_SEEDLOT_STATUS = "SUB"; + public static final String MINITRY_OF_FORESTS_ID = "00012797"; } diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/security/JwtSecurityUtil.java b/backend/src/main/java/ca/bc/gov/backendstartapi/security/JwtSecurityUtil.java index 150a657b9..07ecbd126 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/security/JwtSecurityUtil.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/security/JwtSecurityUtil.java @@ -1,5 +1,6 @@ package ca.bc.gov.backendstartapi.security; +import ca.bc.gov.backendstartapi.config.Constants; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -9,6 +10,8 @@ /** This class contains methods for handling JWT requests. */ public final class JwtSecurityUtil { + private final static List concreteRoles = List.of("SPAR_MINISTRY_ORCHARD", "SPAR_TSC_ADMIN"); + /** * Gets user roles from user JWT token. * @@ -48,6 +51,11 @@ public static List getClientIdsFromJwt(Jwt jwtPrincipal) { clientIds.add(clientNumber); } } + // Handling concrete roles with no client id affixed + if (concreteRoles.contains(role) + && !clientIds.contains(Constants.MINITRY_OF_FORESTS_ID)) { + clientIds.add(Constants.MINITRY_OF_FORESTS_ID); + } }); return clientIds; } From 9e133c0fb7494d4ab13f303a015cdfdcefe7a2b4 Mon Sep 17 00:00:00 2001 From: Craig Yu Date: Thu, 29 Aug 2024 13:55:32 -0700 Subject: [PATCH 2/2] fix: style --- .../ca/bc/gov/backendstartapi/security/JwtSecurityUtil.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/security/JwtSecurityUtil.java b/backend/src/main/java/ca/bc/gov/backendstartapi/security/JwtSecurityUtil.java index 07ecbd126..8986d14b6 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/security/JwtSecurityUtil.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/security/JwtSecurityUtil.java @@ -10,7 +10,8 @@ /** This class contains methods for handling JWT requests. */ public final class JwtSecurityUtil { - private final static List concreteRoles = List.of("SPAR_MINISTRY_ORCHARD", "SPAR_TSC_ADMIN"); + private static final List concreteRoles = + List.of("SPAR_MINISTRY_ORCHARD", "SPAR_TSC_ADMIN"); /** * Gets user roles from user JWT token.