Search in sources :

Example 1 with Keytab

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);
    }
}
Also used : RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException) Keytab(com.sequenceiq.freeipa.client.model.Keytab) KeytabCreationException(com.sequenceiq.freeipa.kerberosmgmt.exception.KeytabCreationException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException)

Example 2 with Keytab

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);
}
Also used : KeytabCache(com.sequenceiq.freeipa.entity.KeytabCache) Keytab(com.sequenceiq.freeipa.client.model.Keytab) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) Test(org.junit.jupiter.api.Test)

Example 3 with Keytab

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);
}
Also used : KeytabCache(com.sequenceiq.freeipa.entity.KeytabCache) Keytab(com.sequenceiq.freeipa.client.model.Keytab) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) Test(org.junit.jupiter.api.Test)

Example 4 with Keytab

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);
}
Also used : FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) Keytab(com.sequenceiq.freeipa.client.model.Keytab) KeytabCacheService(com.sequenceiq.freeipa.kerberosmgmt.v1.KeytabCacheService) Service(com.sequenceiq.freeipa.client.model.Service) KeytabCleanupService(com.sequenceiq.freeipa.kerberosmgmt.v1.KeytabCleanupService) KeytabCommonService(com.sequenceiq.freeipa.kerberosmgmt.v1.KeytabCommonService) HostDeletionService(com.sequenceiq.freeipa.service.freeipa.host.HostDeletionService) Host(com.sequenceiq.freeipa.client.model.Host) Stack(com.sequenceiq.freeipa.entity.Stack) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 5 with 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);
    }
}
Also used : RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException) KeytabCache(com.sequenceiq.freeipa.entity.KeytabCache) Keytab(com.sequenceiq.freeipa.client.model.Keytab) KeytabCreationException(com.sequenceiq.freeipa.kerberosmgmt.exception.KeytabCreationException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException)

Aggregations

Keytab (com.sequenceiq.freeipa.client.model.Keytab)5 KeytabCache (com.sequenceiq.freeipa.entity.KeytabCache)3 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)2 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)2 RetryableFreeIpaClientException (com.sequenceiq.freeipa.client.RetryableFreeIpaClientException)2 KeytabCreationException (com.sequenceiq.freeipa.kerberosmgmt.exception.KeytabCreationException)2 Test (org.junit.jupiter.api.Test)2 Host (com.sequenceiq.freeipa.client.model.Host)1 Service (com.sequenceiq.freeipa.client.model.Service)1 FreeIpa (com.sequenceiq.freeipa.entity.FreeIpa)1 Stack (com.sequenceiq.freeipa.entity.Stack)1 KeytabCacheService (com.sequenceiq.freeipa.kerberosmgmt.v1.KeytabCacheService)1 KeytabCleanupService (com.sequenceiq.freeipa.kerberosmgmt.v1.KeytabCleanupService)1 KeytabCommonService (com.sequenceiq.freeipa.kerberosmgmt.v1.KeytabCommonService)1 HostDeletionService (com.sequenceiq.freeipa.service.freeipa.host.HostDeletionService)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1