From 703162bc457120ef46eef6f7758d6ab2b022c385 Mon Sep 17 00:00:00 2001 From: tkuzynow Date: Wed, 11 Oct 2023 12:04:22 +0200 Subject: [PATCH] fix: previous migration to add role names --- .../KeycloakAddRolesToUsersWithRoleTask.java | 3 ++- .../vi/migrationtool/keycloak/KeycloakService.java | 12 +++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/vi/migrationtool/keycloak/KeycloakAddRolesToUsersWithRoleTask.java b/src/main/java/com/vi/migrationtool/keycloak/KeycloakAddRolesToUsersWithRoleTask.java index 41fd08f..ab9730c 100644 --- a/src/main/java/com/vi/migrationtool/keycloak/KeycloakAddRolesToUsersWithRoleTask.java +++ b/src/main/java/com/vi/migrationtool/keycloak/KeycloakAddRolesToUsersWithRoleTask.java @@ -16,7 +16,8 @@ public class KeycloakAddRolesToUsersWithRoleTask extends MigrationTasks { public void execute(Database database) { if (roleNames != null) { KeycloakService keycloakService = BeanAwareSpringLiquibase.getBean(KeycloakService.class); - keycloakService.addRolesToUsersWithRoleName(roleNameToSearchForUsers, List.of(roleNames.split(SPLIT_CHAR))); + keycloakService.addRolesToUsersWithRoleName( + roleNameToSearchForUsers, List.of(roleNames.split(SPLIT_CHAR))); } } } diff --git a/src/main/java/com/vi/migrationtool/keycloak/KeycloakService.java b/src/main/java/com/vi/migrationtool/keycloak/KeycloakService.java index 1f99052..0bdf529 100644 --- a/src/main/java/com/vi/migrationtool/keycloak/KeycloakService.java +++ b/src/main/java/com/vi/migrationtool/keycloak/KeycloakService.java @@ -39,7 +39,8 @@ public class KeycloakService { private static final String SEARCH_PARAM = "search"; private static final String MAX_USERS_TO_MIGRATE = "500"; private static final String ADMIN_REALMS = "/admin/realms/"; - private static final String PROVIDED_ROLE_DOESNT_EXISTS_IN_KEYCLOAK_MSG = "The provided role {} doesn't exists in keycloak, please create it first"; + private static final String PROVIDED_ROLE_DOESNT_EXISTS_IN_KEYCLOAK_MSG = + "The provided role {} doesn't exists in keycloak, please create it first"; private final KeycloakConfig keycloakConfig; public void createRole(String roleName) { @@ -77,8 +78,7 @@ public void addRoleToUsers(final List usernames, final String roleName) Optional role = getRoleBy(roleName, httpHeaders); if (role.isEmpty()) { - log.error( - PROVIDED_ROLE_DOESNT_EXISTS_IN_KEYCLOAK_MSG, roleName); + log.error(PROVIDED_ROLE_DOESNT_EXISTS_IN_KEYCLOAK_MSG, roleName); } var restTemplate = new RestTemplate(); @@ -113,8 +113,7 @@ private void tryToAddRoleToKeycloakUser( RestTemplate restTemplate) { Optional role = getRoleBy(roleNameDoAdd, httpHeaders); if (role.isEmpty()) { - log.error( - PROVIDED_ROLE_DOESNT_EXISTS_IN_KEYCLOAK_MSG, roleNameDoAdd); + log.error(PROVIDED_ROLE_DOESNT_EXISTS_IN_KEYCLOAK_MSG, roleNameDoAdd); } keycloakUsers.forEach( user -> callKeycloakToAddRoleToUser(role.get(), httpHeaders, restTemplate, user)); @@ -314,8 +313,7 @@ private UsersWithRole addCustomAttributeToUsersWithRole( Optional role = getRoleBy(roleName, httpHeaders); if (role.isEmpty()) { - log.error( - PROVIDED_ROLE_DOESNT_EXISTS_IN_KEYCLOAK_MSG, roleName); + log.error(PROVIDED_ROLE_DOESNT_EXISTS_IN_KEYCLOAK_MSG, roleName); } var restTemplate = new RestTemplate();