Search in sources :

Example 11 with KeytabCache

use of com.sequenceiq.freeipa.entity.KeytabCache in project cloudbreak by hortonworks.

the class KeytabCacheServiceTest method testSaveOrUpdateNoCached.

@Test
public void testSaveOrUpdateNoCached() {
    when(keytabCacheRepository.findByEnvironmentCrnAndPrincipalHash(ENVIRONMENT_CRN, PRINCIPAL_HASH)).thenReturn(Optional.empty());
    when(keytabCacheRepository.save(any(KeytabCache.class))).thenAnswer(invocation -> invocation.getArgument(0, KeytabCache.class));
    KeytabCache result = underTest.saveOrUpdate(ENVIRONMENT_CRN, KEYTAB_PRINCIPAL, HOSTNAME, KEYTAB);
    assertEquals(KEYTAB, result.getKeytab().getRaw());
    assertEquals(KEYTAB_PRINCIPAL, result.getPrincipal().getRaw());
    assertEquals(ENVIRONMENT_CRN, result.getEnvironmentCrn());
    assertEquals(ACCOUNT, result.getAccountId());
    assertEquals(PRINCIPAL_HASH, result.getPrincipalHash());
    assertEquals(HOSTNAME, result.getHostName());
}
Also used : KeytabCache(com.sequenceiq.freeipa.entity.KeytabCache) Test(org.junit.jupiter.api.Test)

Example 12 with KeytabCache

use of com.sequenceiq.freeipa.entity.KeytabCache 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 13 with KeytabCache

use of com.sequenceiq.freeipa.entity.KeytabCache in project cloudbreak by hortonworks.

the class HostKeytabServiceTest method testGetExistingKeytab.

@Test
public void testGetExistingKeytab() throws FreeIpaClientException {
    HostKeytabRequest request = new HostKeytabRequest();
    request.setEnvironmentCrn(ENVIRONMENT_CRN);
    request.setServerHostName("asdf");
    Stack stack = new Stack();
    when(keytabCommonService.getFreeIpaStackWithMdcContext(request.getEnvironmentCrn(), ACCOUNT_ID)).thenReturn(stack);
    FreeIpaClient freeIpaClient = mock(FreeIpaClient.class);
    when(freeIpaClientFactory.getFreeIpaClientForStack(stack)).thenReturn(freeIpaClient);
    Host host = new Host();
    host.setKrbprincipalname("dfdf");
    when(freeIpaClient.showHost(request.getServerHostName())).thenReturn(host);
    KeytabCache keytabCache = mock(KeytabCache.class);
    Secret keytabSecret = new Secret("keytab", "keytabSecret");
    Secret principalSecret = new Secret("principal", "principalSecret");
    when(keytabCache.getKeytab()).thenReturn(keytabSecret);
    when(keytabCache.getPrincipal()).thenReturn(principalSecret);
    when(keytabCommonService.getExistingKeytab(request.getEnvironmentCrn(), host.getKrbprincipalname(), request.getServerHostName(), freeIpaClient)).thenReturn(keytabCache);
    SecretResponse keytabResponse = new SecretResponse();
    keytabResponse.setSecretPath("keytabPath");
    when(secretResponseConverter.convert(keytabCache.getKeytab().getSecret())).thenReturn(keytabResponse);
    SecretResponse principalResponse = new SecretResponse();
    principalResponse.setSecretPath("principalPath");
    when(secretResponseConverter.convert(keytabCache.getPrincipal().getSecret())).thenReturn(principalResponse);
    HostKeytabResponse response = underTest.getExistingHostKeytab(request, ACCOUNT_ID);
    assertEquals(keytabResponse, response.getKeytab());
    assertEquals(principalResponse, response.getHostPrincipal());
}
Also used : Secret(com.sequenceiq.cloudbreak.service.secret.domain.Secret) SecretResponse(com.sequenceiq.cloudbreak.service.secret.model.SecretResponse) HostKeytabResponse(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.HostKeytabResponse) KeytabCache(com.sequenceiq.freeipa.entity.KeytabCache) HostKeytabRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.HostKeytabRequest) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) Host(com.sequenceiq.freeipa.client.model.Host) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 14 with KeytabCache

use of com.sequenceiq.freeipa.entity.KeytabCache in project cloudbreak by hortonworks.

the class HostKeytabServiceTest method testGenerateHostKeytabDoNotRecreateFalse.

@Test
public void testGenerateHostKeytabDoNotRecreateFalse() throws FreeIpaClientException {
    HostKeytabRequest request = new HostKeytabRequest();
    request.setEnvironmentCrn(ENVIRONMENT_CRN);
    request.setRoleRequest(new RoleRequest());
    request.setDoNotRecreateKeytab(Boolean.FALSE);
    request.setServerHostName("asdf");
    Stack stack = new Stack();
    when(keytabCommonService.getFreeIpaStackWithMdcContext(request.getEnvironmentCrn(), ACCOUNT_ID)).thenReturn(stack);
    FreeIpaClient freeIpaClient = mock(FreeIpaClient.class);
    when(freeIpaClientFactory.getFreeIpaClientForStack(stack)).thenReturn(freeIpaClient);
    when(roleComponent.privilegesExist(request.getRoleRequest(), freeIpaClient)).thenReturn(Boolean.TRUE);
    Host host = new Host();
    host.setHasKeytab(Boolean.TRUE);
    host.setKrbprincipalname("dfdf");
    when(keytabCommonService.addHost(request.getServerHostName(), request.getRoleRequest(), freeIpaClient)).thenReturn(host);
    KeytabCache keytabCache = mock(KeytabCache.class);
    Secret keytabSecret = new Secret("keytab", "keytabSecret");
    Secret principalSecret = new Secret("principal", "principalSecret");
    when(keytabCache.getKeytab()).thenReturn(keytabSecret);
    when(keytabCache.getPrincipal()).thenReturn(principalSecret);
    when(keytabCommonService.getKeytab(request.getEnvironmentCrn(), host.getKrbprincipalname(), request.getServerHostName(), freeIpaClient)).thenReturn(keytabCache);
    SecretResponse keytabResponse = new SecretResponse();
    keytabResponse.setSecretPath("keytabPath");
    when(secretResponseConverter.convert(keytabCache.getKeytab().getSecret())).thenReturn(keytabResponse);
    SecretResponse principalResponse = new SecretResponse();
    principalResponse.setSecretPath("principalPath");
    when(secretResponseConverter.convert(keytabCache.getPrincipal().getSecret())).thenReturn(principalResponse);
    HostKeytabResponse response = underTest.generateHostKeytab(request, ACCOUNT_ID);
    assertEquals(keytabResponse, response.getKeytab());
    assertEquals(principalResponse, response.getHostPrincipal());
}
Also used : Secret(com.sequenceiq.cloudbreak.service.secret.domain.Secret) SecretResponse(com.sequenceiq.cloudbreak.service.secret.model.SecretResponse) HostKeytabResponse(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.HostKeytabResponse) KeytabCache(com.sequenceiq.freeipa.entity.KeytabCache) HostKeytabRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.HostKeytabRequest) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) Host(com.sequenceiq.freeipa.client.model.Host) RoleRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 15 with KeytabCache

use of com.sequenceiq.freeipa.entity.KeytabCache in project cloudbreak by hortonworks.

the class KeytabCacheService method save.

public KeytabCache save(String environmentCrn, String principal, String hostname, String keytab) {
    String accountId = Crn.safeFromString(environmentCrn).getAccountId();
    KeytabCache keytabCache = new KeytabCache();
    keytabCache.setKeytab(keytab);
    keytabCache.setPrincipal(principal);
    keytabCache.setEnvironmentCrn(environmentCrn);
    keytabCache.setAccountId(accountId);
    keytabCache.setPrincipalHash(hashPrincipal(principal));
    keytabCache.setHostName(hostname);
    LOGGER.debug("Saving keytab in env [{}] for principal hash: [{}]", environmentCrn, keytabCache.getPrincipalHash());
    return keytabCacheRepository.save(keytabCache);
}
Also used : KeytabCache(com.sequenceiq.freeipa.entity.KeytabCache)

Aggregations

KeytabCache (com.sequenceiq.freeipa.entity.KeytabCache)18 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)11 Test (org.junit.jupiter.api.Test)11 Stack (com.sequenceiq.freeipa.entity.Stack)8 Host (com.sequenceiq.freeipa.client.model.Host)5 Secret (com.sequenceiq.cloudbreak.service.secret.domain.Secret)4 SecretResponse (com.sequenceiq.cloudbreak.service.secret.model.SecretResponse)4 HostKeytabRequest (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.HostKeytabRequest)4 HostKeytabResponse (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.HostKeytabResponse)4 RoleRequest (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest)3 Keytab (com.sequenceiq.freeipa.client.model.Keytab)3 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)2 KeytabCreationException (com.sequenceiq.freeipa.kerberosmgmt.exception.KeytabCreationException)2 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)1 RetryableFreeIpaClientException (com.sequenceiq.freeipa.client.RetryableFreeIpaClientException)1