@Test public void testRemoveUsersWhenKerberosConfigAlreadyDeleted() throws FreeIpaClientException { Set<String> usersNames = Set.of( "ldapbind-test-wl-1", "kerberosbind-test-wl-1"); Set<User> ipaUsers = Set.of( createUser("ldapbind-test-wl-1"), createUser("ldapbind-test-wl-2"), createUser("kerberosbind-test-wl-1"), createUser("kerberosbind-test-wl-2"), createUser("mockuser0"), createUser("csso_khorvath") ); FreeIpaClient freeIpaClient = mock(FreeIpaClient.class); when(freeIpaClientFactory.getFreeIpaClientForStackId(STACK_ID)).thenReturn(freeIpaClient); when(freeIpaClient.userFindAll()).thenReturn(ipaUsers); when(stackService.getStackById(anyLong())).thenReturn(createStack()); doThrow(new NotFoundException("Kerberos config not found")).when(kerberosConfigService).delete("envCrn", "accountId", "test-wl-1"); Pair<Set<String>, Map<String, String>> result = cleanupService.removeUsers(STACK_ID, usersNames, "test-wl-1", ENV_CRN); verify(freeIpaClient, times(1)).deleteUser("ldapbind-test-wl-1"); verify(freeIpaClient, times(1)).deleteUser("kerberosbind-test-wl-1"); verifyUserDeleteNotInvoked(freeIpaClient, "ldapbind-test-wl-2", "kerberosbind-test-wl-2", "mockuser0", "csso_khorvath"); assertEquals(2, result.getFirst().size()); assertTrue(result.getFirst().stream().anyMatch("ldapbind-test-wl-1"::equals)); assertTrue(result.getFirst().stream().anyMatch("kerberosbind-test-wl-1"::equals)); verify(kerberosConfigService, times(1)).delete("envCrn", "accountId", "test-wl-1"); verify(ldapConfigService, times(1)).delete("envCrn", "accountId", "test-wl-1"); }
public Pair<Set<String>, Map<String, String>> removeUsers(Long stackId, Set<String> users, String clusterName, String environmentCrn) throws FreeIpaClientException { FreeIpaClient client = getFreeIpaClient(stackId); Set<String> userCleanupSuccess = new HashSet<>(); Map<String, String> userCleanupFailed = new HashMap<>(); Set<String> usersUid = client.userFindAll().stream().map(User::getUid).collect(Collectors.toSet()); users.stream().filter(usersUid::contains).forEach(userUid -> { try { LOGGER.debug("Delete user: {}", userUid); client.deleteUser(userUid); userCleanupSuccess.add(userUid); } catch (FreeIpaClientException e) { if (FreeIpaClientExceptionUtil.isNotFoundException(e)) { userCleanupSuccess.add(userUid); } else { LOGGER.info("User delete failed for user: {}", userUid, e); userCleanupFailed.put(userUid, e.getMessage()); } } }); if (StringUtils.isNotBlank(clusterName)) { Stack stack = stackService.getStackById(stackId); if (StringUtils.isEmpty(environmentCrn)) { environmentCrn = stack.getEnvironmentCrn(); } String accountId = stack.getAccountId(); try { kerberosConfigService.delete(environmentCrn, accountId, clusterName); } catch (NotFoundException e) { LOGGER.warn("No kerberos config found for cluster [{}] to delete", clusterName); } try { ldapConfigService.delete(environmentCrn, accountId, clusterName); } catch (NotFoundException e) { LOGGER.warn("No ldap config found for cluster [{}] to delete", clusterName); } } return Pair.of(userCleanupSuccess, userCleanupFailed); }
CleanupService { public Pair<Set<String>, Map<String, String>> removeUsers(Long stackId, Set<String> users, String clusterName, String environmentCrn) throws FreeIpaClientException { FreeIpaClient client = getFreeIpaClient(stackId); Set<String> userCleanupSuccess = new HashSet<>(); Map<String, String> userCleanupFailed = new HashMap<>(); Set<String> usersUid = client.userFindAll().stream().map(User::getUid).collect(Collectors.toSet()); users.stream().filter(usersUid::contains).forEach(userUid -> { try { LOGGER.debug("Delete user: {}", userUid); client.deleteUser(userUid); userCleanupSuccess.add(userUid); } catch (FreeIpaClientException e) { if (FreeIpaClientExceptionUtil.isNotFoundException(e)) { userCleanupSuccess.add(userUid); } else { LOGGER.info("User delete failed for user: {}", userUid, e); userCleanupFailed.put(userUid, e.getMessage()); } } }); if (StringUtils.isNotBlank(clusterName)) { Stack stack = stackService.getStackById(stackId); if (StringUtils.isEmpty(environmentCrn)) { environmentCrn = stack.getEnvironmentCrn(); } String accountId = stack.getAccountId(); try { kerberosConfigService.delete(environmentCrn, accountId, clusterName); } catch (NotFoundException e) { LOGGER.warn("No kerberos config found for cluster [{}] to delete", clusterName); } try { ldapConfigService.delete(environmentCrn, accountId, clusterName); } catch (NotFoundException e) { LOGGER.warn("No ldap config found for cluster [{}] to delete", clusterName); } } return Pair.of(userCleanupSuccess, userCleanupFailed); } }
CleanupService { public Pair<Set<String>, Map<String, String>> removeUsers(Long stackId, Set<String> users, String clusterName, String environmentCrn) throws FreeIpaClientException { FreeIpaClient client = getFreeIpaClient(stackId); Set<String> userCleanupSuccess = new HashSet<>(); Map<String, String> userCleanupFailed = new HashMap<>(); Set<String> usersUid = client.userFindAll().stream().map(User::getUid).collect(Collectors.toSet()); users.stream().filter(usersUid::contains).forEach(userUid -> { try { LOGGER.debug("Delete user: {}", userUid); client.deleteUser(userUid); userCleanupSuccess.add(userUid); } catch (FreeIpaClientException e) { if (FreeIpaClientExceptionUtil.isNotFoundException(e)) { userCleanupSuccess.add(userUid); } else { LOGGER.info("User delete failed for user: {}", userUid, e); userCleanupFailed.put(userUid, e.getMessage()); } } }); if (StringUtils.isNotBlank(clusterName)) { Stack stack = stackService.getStackById(stackId); if (StringUtils.isEmpty(environmentCrn)) { environmentCrn = stack.getEnvironmentCrn(); } String accountId = stack.getAccountId(); try { kerberosConfigService.delete(environmentCrn, accountId, clusterName); } catch (NotFoundException e) { LOGGER.warn("No kerberos config found for cluster [{}] to delete", clusterName); } try { ldapConfigService.delete(environmentCrn, accountId, clusterName); } catch (NotFoundException e) { LOGGER.warn("No ldap config found for cluster [{}] to delete", clusterName); } } return Pair.of(userCleanupSuccess, userCleanupFailed); }  }
CleanupService { public Pair<Set<String>, Map<String, String>> removeUsers(Long stackId, Set<String> users, String clusterName, String environmentCrn) throws FreeIpaClientException { FreeIpaClient client = getFreeIpaClient(stackId); Set<String> userCleanupSuccess = new HashSet<>(); Map<String, String> userCleanupFailed = new HashMap<>(); Set<String> usersUid = client.userFindAll().stream().map(User::getUid).collect(Collectors.toSet()); users.stream().filter(usersUid::contains).forEach(userUid -> { try { LOGGER.debug("Delete user: {}", userUid); client.deleteUser(userUid); userCleanupSuccess.add(userUid); } catch (FreeIpaClientException e) { if (FreeIpaClientExceptionUtil.isNotFoundException(e)) { userCleanupSuccess.add(userUid); } else { LOGGER.info("User delete failed for user: {}", userUid, e); userCleanupFailed.put(userUid, e.getMessage()); } } }); if (StringUtils.isNotBlank(clusterName)) { Stack stack = stackService.getStackById(stackId); if (StringUtils.isEmpty(environmentCrn)) { environmentCrn = stack.getEnvironmentCrn(); } String accountId = stack.getAccountId(); try { kerberosConfigService.delete(environmentCrn, accountId, clusterName); } catch (NotFoundException e) { LOGGER.warn("No kerberos config found for cluster [{}] to delete", clusterName); } try { ldapConfigService.delete(environmentCrn, accountId, clusterName); } catch (NotFoundException e) { LOGGER.warn("No ldap config found for cluster [{}] to delete", clusterName); } } return Pair.of(userCleanupSuccess, userCleanupFailed); }  OperationStatus cleanup(String accountId, CleanupRequest request); Pair<Set<String>, Map<String, String>> revokeCerts(Long stackId, Set<String> hosts); Pair<Set<String>, Map<String, String>> removeDnsEntries(Long stackId, Set<String> hosts, Set<String> ips, String domain); Pair<Set<String>, Map<String, String>> removeHosts(Long stackId, Set<String> hosts); Pair<Set<String>, Map<String, String>> removeServers(Long stackId, Set<String> hosts); Pair<Set<String>, Map<String, String>> removeUsers(Long stackId, Set<String> users, String clusterName, String environmentCrn); Pair<Set<String>, Map<String, String>> removeRoles(Long stackId, Set<String> roles); Pair<Set<String>, Map<String, String>> removeVaultEntries(Long stackId, Set<String> hosts); }
CleanupService { public Pair<Set<String>, Map<String, String>> removeUsers(Long stackId, Set<String> users, String clusterName, String environmentCrn) throws FreeIpaClientException { FreeIpaClient client = getFreeIpaClient(stackId); Set<String> userCleanupSuccess = new HashSet<>(); Map<String, String> userCleanupFailed = new HashMap<>(); Set<String> usersUid = client.userFindAll().stream().map(User::getUid).collect(Collectors.toSet()); users.stream().filter(usersUid::contains).forEach(userUid -> { try { LOGGER.debug("Delete user: {}", userUid); client.deleteUser(userUid); userCleanupSuccess.add(userUid); } catch (FreeIpaClientException e) { if (FreeIpaClientExceptionUtil.isNotFoundException(e)) { userCleanupSuccess.add(userUid); } else { LOGGER.info("User delete failed for user: {}", userUid, e); userCleanupFailed.put(userUid, e.getMessage()); } } }); if (StringUtils.isNotBlank(clusterName)) { Stack stack = stackService.getStackById(stackId); if (StringUtils.isEmpty(environmentCrn)) { environmentCrn = stack.getEnvironmentCrn(); } String accountId = stack.getAccountId(); try { kerberosConfigService.delete(environmentCrn, accountId, clusterName); } catch (NotFoundException e) { LOGGER.warn("No kerberos config found for cluster [{}] to delete", clusterName); } try { ldapConfigService.delete(environmentCrn, accountId, clusterName); } catch (NotFoundException e) { LOGGER.warn("No ldap config found for cluster [{}] to delete", clusterName); } } return Pair.of(userCleanupSuccess, userCleanupFailed); }  OperationStatus cleanup(String accountId, CleanupRequest request); Pair<Set<String>, Map<String, String>> revokeCerts(Long stackId, Set<String> hosts); Pair<Set<String>, Map<String, String>> removeDnsEntries(Long stackId, Set<String> hosts, Set<String> ips, String domain); Pair<Set<String>, Map<String, String>> removeHosts(Long stackId, Set<String> hosts); Pair<Set<String>, Map<String, String>> removeServers(Long stackId, Set<String> hosts); Pair<Set<String>, Map<String, String>> removeUsers(Long stackId, Set<String> users, String clusterName, String environmentCrn); Pair<Set<String>, Map<String, String>> removeRoles(Long stackId, Set<String> roles); Pair<Set<String>, Map<String, String>> removeVaultEntries(Long stackId, Set<String> hosts);  }