Adding and removing users from Keycloak groups on role assignment

This commit is contained in:
Thomas Georgios Giannos 2023-12-11 10:56:40 +02:00
parent 880e8c5aa8
commit e70db447c8
1 changed files with 2 additions and 2 deletions

View File

@ -217,7 +217,7 @@ public class UserServiceImpl implements UserService {
item.setRole(roleName);
item.setCreatedAt(Instant.now());
this.entityManager.persist(item);
this.keycloakService.assignClientRoleToUser(data.getId(), null, KeycloakRole.valueOf(roleName));
this.keycloakService.addUserToGroup(data.getId(), KeycloakRole.valueOf(roleName));
}
foundIds.add(item.getId());
}
@ -225,7 +225,7 @@ public class UserServiceImpl implements UserService {
this.entityManager.flush();
List<UserRoleEntity> toDelete = existingItems.stream().filter(x-> foundIds.stream().noneMatch(y-> y.equals(x.getId()))).collect(Collectors.toList());
toDelete.forEach(x -> this.keycloakService.removeClientRoleFromUser(data.getId(), null, KeycloakRole.valueOf(x.getRole())));
toDelete.forEach(x -> this.keycloakService.removeUserFromGroup(data.getId(), KeycloakRole.valueOf(x.getRole())));
this.deleterFactory.deleter(UserRoleDeleter.class).deleteAndSave(toDelete);
this.entityManager.flush();