use of com.sequenceiq.freeipa.client.model.Keytab in project cloudbreak by hortonworks.
the class KeytabCommonService method getKeytab.
public KeytabCache getKeytab(String environmentCrn, String canonicalPrincipal, String hostName, FreeIpaClient ipaClient) throws FreeIpaClientException, KeytabCreationException {
try {
LOGGER.debug("Fetching keytab from FreeIPA");
Keytab keytab = ipaClient.getKeytab(canonicalPrincipal);
return keytabCacheService.saveOrUpdate(environmentCrn, canonicalPrincipal, hostName, keytab.getKeytab());
} catch (RetryableFreeIpaClientException e) {
LOGGER.error(KEYTAB_GENERATION_FAILED + " " + e.getLocalizedMessage(), e);
throw new RetryableFreeIpaClientException(KEYTAB_GENERATION_FAILED, e, new KeytabCreationException(KEYTAB_GENERATION_FAILED));
} catch (FreeIpaClientException e) {
LOGGER.error(KEYTAB_GENERATION_FAILED + " " + e.getLocalizedMessage(), e);
throw new KeytabCreationException(KEYTAB_GENERATION_FAILED);
}
}
use of com.sequenceiq.freeipa.client.model.Keytab in project cloudbreak by hortonworks.
the class KeytabCommonServiceTest method testGetKeytab.
@Test
public void testGetKeytab() throws FreeIpaClientException {
FreeIpaClient ipaClient = mock(FreeIpaClient.class);
Keytab keytab = new Keytab();
keytab.setKeytab(KEYTAB);
when(ipaClient.getKeytab(PRINCIPAL)).thenReturn(keytab);
KeytabCache keytabCache = new KeytabCache();
when(keytabCacheService.saveOrUpdate(ENVIRONMENT_CRN, PRINCIPAL, HOST, KEYTAB)).thenReturn(keytabCache);
KeytabCache result = underTest.getKeytab(ENVIRONMENT_CRN, PRINCIPAL, HOST, ipaClient);
assertEquals(keytabCache, result);
}
use of com.sequenceiq.freeipa.client.model.Keytab in project cloudbreak by hortonworks.
the class KeytabCommonServiceTest method testGetExistingKeytabFromIpaClient.
@Test
public void testGetExistingKeytabFromIpaClient() throws FreeIpaClientException {
FreeIpaClient ipaClient = mock(FreeIpaClient.class);
KeytabCache keytabCache = new KeytabCache();
when(keytabCacheService.findByEnvironmentCrnAndPrincipal(ENVIRONMENT_CRN, PRINCIPAL)).thenReturn(Optional.empty());
Keytab keytab = new Keytab();
keytab.setKeytab(KEYTAB);
when(ipaClient.getExistingKeytab(PRINCIPAL)).thenReturn(keytab);
when(keytabCacheService.saveOrUpdate(ENVIRONMENT_CRN, PRINCIPAL, HOST, KEYTAB)).thenReturn(keytabCache);
KeytabCache result = underTest.getExistingKeytab(ENVIRONMENT_CRN, PRINCIPAL, HOST, ipaClient);
assertEquals(keytabCache, result);
}
use of com.sequenceiq.freeipa.client.model.Keytab in project cloudbreak by hortonworks.
the class KeytabCleanupServiceTest method init.
@BeforeAll
public static void init() {
freeIpa = new FreeIpa();
freeIpa.setDomain(DOMAIN);
stack = new Stack();
host = new Host();
host.setFqdn(HOST);
host.setKrbprincipalname(HOST_PRINCIPAL);
service = new Service();
service.setKrbprincipalname(List.of(SERVICE_PRINCIPAL));
service.setKrbcanonicalname(SERVICE_PRINCIPAL);
keytab = new Keytab();
keytab.setKeytab(KEYTAB);
}
use of com.sequenceiq.freeipa.client.model.Keytab in project cloudbreak by hortonworks.
the class KeytabCommonService method getExistingKeytab.
public KeytabCache getExistingKeytab(String environmentCrn, String canonicalPrincipal, String hostName, FreeIpaClient ipaClient) throws FreeIpaClientException, KeytabCreationException {
try {
Optional<KeytabCache> keytabCache = keytabCacheService.findByEnvironmentCrnAndPrincipal(environmentCrn, canonicalPrincipal);
if (keytabCache.isPresent()) {
LOGGER.debug("Returning keytab from cache");
return keytabCache.get();
} else {
LOGGER.debug("Keytab is not found in cache, fetching existing from FreeIPA");
Keytab keytab = ipaClient.getExistingKeytab(canonicalPrincipal);
return keytabCacheService.saveOrUpdate(environmentCrn, canonicalPrincipal, hostName, keytab.getKeytab());
}
} catch (RetryableFreeIpaClientException e) {
LOGGER.error(KEYTAB_FETCH_FAILED + " " + e.getLocalizedMessage(), e);
throw new RetryableFreeIpaClientException(KEYTAB_FETCH_FAILED, e, new KeytabCreationException(KEYTAB_FETCH_FAILED));
} catch (FreeIpaClientException e) {
LOGGER.error(KEYTAB_FETCH_FAILED + " " + e.getLocalizedMessage(), e);
throw new KeytabCreationException(KEYTAB_FETCH_FAILED);
}
}
Aggregations