@Test void setWorkloadCredential() throws Exception { FreeIpaClient freeIpaClient = mock(FreeIpaClient.class); String username = "username"; WorkloadCredential workloadCredential = new WorkloadCredential("hashedpassword", List.of(), Optional.of(Instant.now()), List.of(UserManagementProto.SshPublicKey.newBuilder().setPublicKey("fakepublickey").build(), UserManagementProto.SshPublicKey.newBuilder().setPublicKey("anotherfakepublickey").build())); underTest.setWorkloadCredential(freeIpaClient, username, workloadCredential); ArgumentCaptor<List<String>> captor = ArgumentCaptor.forClass(List.class); verify(freeIpaClient).userSetWorkloadCredentials( eq(username), eq(workloadCredential.getHashedPassword()), eq(KrbKeySetEncoder.getASNEncodedKrbPrincipalKey(workloadCredential.getKeys())), eq(workloadCredential.getExpirationDate()), captor.capture()); assertTrue(captor.getValue().containsAll(List.of("fakepublickey", "anotherfakepublickey"))); }
public void setWorkloadCredential(FreeIpaClient freeIpaClient, String username, WorkloadCredential workloadCredential) throws IOException, FreeIpaClientException { LOGGER.debug("Setting workload credentials for user '{}'", username); try { String ansEncodedKrbPrincipalKey = KrbKeySetEncoder.getASNEncodedKrbPrincipalKey(workloadCredential.getKeys()); freeIpaClient.userSetWorkloadCredentials(username, workloadCredential.getHashedPassword(), ansEncodedKrbPrincipalKey, workloadCredential.getExpirationDate(), workloadCredential.getSshPublicKeys().stream().map(UserManagementProto.SshPublicKey::getPublicKey).collect(Collectors.toList())); } catch (FreeIpaClientException e) { if (FreeIpaClientExceptionUtil.isEmptyModlistException(e)) { LOGGER.debug("Workload credentials for user '{}' already set.", username); } else { throw e; } } }
WorkloadCredentialService { public void setWorkloadCredential(FreeIpaClient freeIpaClient, String username, WorkloadCredential workloadCredential) throws IOException, FreeIpaClientException { LOGGER.debug("Setting workload credentials for user '{}'", username); try { String ansEncodedKrbPrincipalKey = KrbKeySetEncoder.getASNEncodedKrbPrincipalKey(workloadCredential.getKeys()); freeIpaClient.userSetWorkloadCredentials(username, workloadCredential.getHashedPassword(), ansEncodedKrbPrincipalKey, workloadCredential.getExpirationDate(), workloadCredential.getSshPublicKeys().stream().map(UserManagementProto.SshPublicKey::getPublicKey).collect(Collectors.toList())); } catch (FreeIpaClientException e) { if (FreeIpaClientExceptionUtil.isEmptyModlistException(e)) { LOGGER.debug("Workload credentials for user '{}' already set.", username); } else { throw e; } } } }
WorkloadCredentialService { public void setWorkloadCredential(FreeIpaClient freeIpaClient, String username, WorkloadCredential workloadCredential) throws IOException, FreeIpaClientException { LOGGER.debug("Setting workload credentials for user '{}'", username); try { String ansEncodedKrbPrincipalKey = KrbKeySetEncoder.getASNEncodedKrbPrincipalKey(workloadCredential.getKeys()); freeIpaClient.userSetWorkloadCredentials(username, workloadCredential.getHashedPassword(), ansEncodedKrbPrincipalKey, workloadCredential.getExpirationDate(), workloadCredential.getSshPublicKeys().stream().map(UserManagementProto.SshPublicKey::getPublicKey).collect(Collectors.toList())); } catch (FreeIpaClientException e) { if (FreeIpaClientExceptionUtil.isEmptyModlistException(e)) { LOGGER.debug("Workload credentials for user '{}' already set.", username); } else { throw e; } } }  }
WorkloadCredentialService { public void setWorkloadCredential(FreeIpaClient freeIpaClient, String username, WorkloadCredential workloadCredential) throws IOException, FreeIpaClientException { LOGGER.debug("Setting workload credentials for user '{}'", username); try { String ansEncodedKrbPrincipalKey = KrbKeySetEncoder.getASNEncodedKrbPrincipalKey(workloadCredential.getKeys()); freeIpaClient.userSetWorkloadCredentials(username, workloadCredential.getHashedPassword(), ansEncodedKrbPrincipalKey, workloadCredential.getExpirationDate(), workloadCredential.getSshPublicKeys().stream().map(UserManagementProto.SshPublicKey::getPublicKey).collect(Collectors.toList())); } catch (FreeIpaClientException e) { if (FreeIpaClientExceptionUtil.isEmptyModlistException(e)) { LOGGER.debug("Workload credentials for user '{}' already set.", username); } else { throw e; } } }  void setWorkloadCredential(FreeIpaClient freeIpaClient, String username, WorkloadCredential workloadCredential); void setWorkloadCredentials(FreeIpaClient freeIpaClient, Map<String, WorkloadCredential> workloadCredentials,
            BiConsumer<String, String> warnings); }
WorkloadCredentialService { public void setWorkloadCredential(FreeIpaClient freeIpaClient, String username, WorkloadCredential workloadCredential) throws IOException, FreeIpaClientException { LOGGER.debug("Setting workload credentials for user '{}'", username); try { String ansEncodedKrbPrincipalKey = KrbKeySetEncoder.getASNEncodedKrbPrincipalKey(workloadCredential.getKeys()); freeIpaClient.userSetWorkloadCredentials(username, workloadCredential.getHashedPassword(), ansEncodedKrbPrincipalKey, workloadCredential.getExpirationDate(), workloadCredential.getSshPublicKeys().stream().map(UserManagementProto.SshPublicKey::getPublicKey).collect(Collectors.toList())); } catch (FreeIpaClientException e) { if (FreeIpaClientExceptionUtil.isEmptyModlistException(e)) { LOGGER.debug("Workload credentials for user '{}' already set.", username); } else { throw e; } } }  void setWorkloadCredential(FreeIpaClient freeIpaClient, String username, WorkloadCredential workloadCredential); void setWorkloadCredentials(FreeIpaClient freeIpaClient, Map<String, WorkloadCredential> workloadCredentials,
            BiConsumer<String, String> warnings);  }