use of com.sequenceiq.freeipa.client.FreeIpaClient in project cloudbreak by hortonworks.
the class SudoRuleAddOperationTest method testInvokeWithAllHostCategory.
@Test
public void testInvokeWithAllHostCategory() throws FreeIpaClientException {
RPCResponse<Object> rpcResponse = new RPCResponse<>();
rpcResponse.setResult(new SudoRule());
when(freeIpaClient.invoke(any(), anyList(), any(), any())).thenReturn(rpcResponse);
SudoRuleAddOperation.create(NAME, true, null).invoke(freeIpaClient);
verify(freeIpaClient).invoke(eq("sudorule_add"), argThat(argument -> argument.contains(NAME) && argument.size() == 1), argThat(argument -> "all".equals(argument.get("hostcategory")) && argument.size() == 1), eq(SudoRule.class));
}
use of com.sequenceiq.freeipa.client.FreeIpaClient in project cloudbreak by hortonworks.
the class SudoRuleAddOperationTest method testInvoke.
@Test
public void testInvoke() throws FreeIpaClientException {
RPCResponse<Object> rpcResponse = new RPCResponse<>();
rpcResponse.setResult(new SudoRule());
when(freeIpaClient.invoke(any(), anyList(), any(), any())).thenReturn(rpcResponse);
SudoRuleAddOperation.create(NAME, false, null).invoke(freeIpaClient);
verify(freeIpaClient).invoke(eq("sudorule_add"), argThat(argument -> argument.contains(NAME) && argument.size() == 1), argThat(argument -> argument.isEmpty()), eq(SudoRule.class));
}
use of com.sequenceiq.freeipa.client.FreeIpaClient in project cloudbreak by hortonworks.
the class SudoRuleShowOperationTest method testInvokeShouldFreeIpaClientException.
@Test
public void testInvokeShouldFreeIpaClientException() throws FreeIpaClientException {
when(freeIpaClient.invoke(any(), anyList(), any(), any())).thenThrow(new FreeIpaClientException(null));
assertThrows(FreeIpaClientException.class, () -> SudoRuleShowOperation.create(NAME).invoke(freeIpaClient));
verify(freeIpaClient).invoke(eq("sudorule_show"), argThat(argument -> argument.contains(NAME) && argument.size() == 1), argThat(argument -> argument.isEmpty()), eq(SudoRule.class));
}
use of com.sequenceiq.freeipa.client.FreeIpaClient in project cloudbreak by hortonworks.
the class SudoRuleShowOperationTest method testInvokeShouldReturnEmptyInCaseOfNotFoundException.
@Test
public void testInvokeShouldReturnEmptyInCaseOfNotFoundException() throws FreeIpaClientException {
when(freeIpaClient.invoke(any(), anyList(), any(), any())).thenThrow(new FreeIpaClientException("", new JsonRpcClientException(FreeIpaErrorCodes.NOT_FOUND.getValue(), null, null)));
Optional<SudoRule> result = SudoRuleShowOperation.create(NAME).invoke(freeIpaClient);
assertEquals(Optional.empty(), result);
verify(freeIpaClient).invoke(eq("sudorule_show"), argThat(argument -> argument.contains(NAME) && argument.size() == 1), argThat(argument -> argument.isEmpty()), eq(SudoRule.class));
}
use of com.sequenceiq.freeipa.client.FreeIpaClient in project cloudbreak by hortonworks.
the class KeytabCleanupService method deleteServicePrincipal.
public void deleteServicePrincipal(ServicePrincipalRequest request, String accountId) throws FreeIpaClientException, DeleteException {
LOGGER.debug("Request to delete service principal for account {}: {}", accountId, request);
Stack freeIpaStack = keytabCommonService.getFreeIpaStackWithMdcContext(request.getEnvironmentCrn(), accountId);
String realm = keytabCommonService.getRealm(freeIpaStack);
String canonicalPrincipal = keytabCommonService.constructPrincipal(request.getServiceName(), request.getServerHostName(), realm);
FreeIpaClient ipaClient = freeIpaClientFactory.getFreeIpaClientForStack(freeIpaStack);
deleteService(canonicalPrincipal, ipaClient);
VaultPathBuilder vaultPathBuilder = new VaultPathBuilder().withSecretType(VaultPathBuilder.SecretType.SERVICE_KEYTAB).withAccountId(accountId).withEnvironmentCrn(request.getEnvironmentCrn()).withClusterCrn(request.getClusterCrn()).withServerHostName(request.getServerHostName()).withServiceName(request.getServiceName());
vaultComponent.recursivelyCleanupVault(vaultPathBuilder.withSubType(VaultPathBuilder.SecretSubType.SERVICE_PRINCIPAL).build());
vaultComponent.recursivelyCleanupVault(vaultPathBuilder.withSubType(VaultPathBuilder.SecretSubType.KEYTAB).build());
roleComponent.deleteRoleIfItIsNoLongerUsed(request.getRoleName(), ipaClient);
keytabCacheService.deleteByEnvironmentCrnAndPrincipal(request.getEnvironmentCrn(), canonicalPrincipal);
}
Aggregations