From 6242258e09b104124ff91ea18086eca48afce1bd Mon Sep 17 00:00:00 2001 From: Ali Oezyetimoglu Date: Wed, 6 Dec 2023 11:40:43 +0100 Subject: [PATCH] RED-8008: Ensure that new roles are added to existing tenants during upgrade --- .../initializer/MigrateOnlyHook.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/com/knecon/fforesight/tenantusermanagement/initializer/MigrateOnlyHook.java b/src/main/java/com/knecon/fforesight/tenantusermanagement/initializer/MigrateOnlyHook.java index 342dd2d..b3f2199 100644 --- a/src/main/java/com/knecon/fforesight/tenantusermanagement/initializer/MigrateOnlyHook.java +++ b/src/main/java/com/knecon/fforesight/tenantusermanagement/initializer/MigrateOnlyHook.java @@ -1,5 +1,6 @@ package com.knecon.fforesight.tenantusermanagement.initializer; +import com.knecon.fforesight.tenantusermanagement.service.TenantManagementService; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.SpringApplication; @@ -24,10 +25,19 @@ public class MigrateOnlyHook { private final ApplicationContext ctx; + private final TenantManagementService tenantManagementService; + + private final KeyCloakRoleManagerService keyCloakRoleManagerService; + @SuppressWarnings("PMD.DoNotTerminateVM") @EventListener(ApplicationReadyEvent.class) public void migrate() { + + tenantManagementService.getTenants().forEach(tenant -> { + keyCloakRoleManagerService.updateRoles(tenant.getTenantId()); + }); + // This should only run in post upgrade hook if (isMigrateOnly) { System.exit(SpringApplication.exit(ctx, () -> 0));