use of com.sequenceiq.freeipa.entity.KeytabCache in project cloudbreak by hortonworks.
the class ServiceKeytabService method getExistingServiceKeytab.
public ServiceKeytabResponse getExistingServiceKeytab(ServiceKeytabRequest request, String accountId) throws FreeIpaClientException {
LOGGER.debug("Request to get service keytab for account {}: {}", accountId, request);
validateRoleRequestNotPresent(request);
Stack freeIpaStack = keytabCommonService.getFreeIpaStackWithMdcContext(request.getEnvironmentCrn(), accountId);
String realm = keytabCommonService.getRealm(freeIpaStack);
String servicePrincipal = keytabCommonService.constructPrincipal(request.getServiceName(), request.getServerHostName(), realm);
Optional<KeytabCache> keytabCacheOptional = keytabCacheService.findByEnvironmentCrnAndPrincipal(request.getEnvironmentCrn(), servicePrincipal);
if (keytabCacheOptional.isPresent()) {
LOGGER.debug("Keytab is found in cache, using it");
return createServiceKeytabResponse(keytabCacheOptional.get());
} else {
LOGGER.debug("Keytab is not found in cache.");
FreeIpaClient ipaClient = freeIpaClientFactory.getFreeIpaClientForStack(freeIpaStack);
KeytabCache serviceKeytab = keytabCommonService.getExistingKeytab(request.getEnvironmentCrn(), servicePrincipal, request.getServerHostName(), ipaClient);
return createServiceKeytabResponse(serviceKeytab);
}
}
use of com.sequenceiq.freeipa.entity.KeytabCache in project cloudbreak by hortonworks.
the class HostKeytabService method generateHostKeytab.
public HostKeytabResponse generateHostKeytab(HostKeytabRequest request, String accountId) throws FreeIpaClientException {
LOGGER.debug("Request to generate host keytab: {}", request);
Stack freeIpaStack = keytabCommonService.getFreeIpaStackWithMdcContext(request.getEnvironmentCrn(), accountId);
FreeIpaClient ipaClient = freeIpaClientFactory.getFreeIpaClientForStack(freeIpaStack);
if (!roleComponent.privilegesExist(request.getRoleRequest(), ipaClient)) {
throw new BadRequestException(PRIVILEGE_DOES_NOT_EXIST);
} else {
Host host = keytabCommonService.addHost(request.getServerHostName(), request.getRoleRequest(), ipaClient);
KeytabCache hostKeytab = fetchKeytab(request, ipaClient, host);
return createHostKeytabResponse(hostKeytab);
}
}
use of com.sequenceiq.freeipa.entity.KeytabCache in project cloudbreak by hortonworks.
the class HostKeytabService method getExistingHostKeytab.
public HostKeytabResponse getExistingHostKeytab(HostKeytabRequest request, String accountId) throws FreeIpaClientException {
LOGGER.debug("Request to get host keytab for account {}: {}", accountId, request);
if (request.getRoleRequest() != null) {
throw new BadRequestException(ROLE_NOT_ALLOWED);
} else {
Stack freeIpaStack = keytabCommonService.getFreeIpaStackWithMdcContext(request.getEnvironmentCrn(), accountId);
FreeIpaClient ipaClient = freeIpaClientFactory.getFreeIpaClientForStack(freeIpaStack);
String hostPrincipal = ipaClient.showHost(request.getServerHostName()).getKrbprincipalname();
KeytabCache hostKeytab = keytabCommonService.getExistingKeytab(request.getEnvironmentCrn(), hostPrincipal, request.getServerHostName(), ipaClient);
return createHostKeytabResponse(hostKeytab);
}
}
use of com.sequenceiq.freeipa.entity.KeytabCache in project cloudbreak by hortonworks.
the class KeytabCacheServiceTest method testSaveOrUpdateCachedDifferent.
@Test
public void testSaveOrUpdateCachedDifferent() {
KeytabCache keytabCache = new KeytabCache();
keytabCache.setKeytab("oldone");
when(keytabCacheRepository.findByEnvironmentCrnAndPrincipalHash(ENVIRONMENT_CRN, PRINCIPAL_HASH)).thenReturn(Optional.of(keytabCache));
when(keytabCacheRepository.save(keytabCache)).thenAnswer(invocation -> invocation.getArgument(0, KeytabCache.class));
KeytabCache result = underTest.saveOrUpdate(ENVIRONMENT_CRN, KEYTAB_PRINCIPAL, HOSTNAME, KEYTAB);
assertEquals(KEYTAB, result.getKeytab().getRaw());
}
use of com.sequenceiq.freeipa.entity.KeytabCache in project cloudbreak by hortonworks.
the class KeytabCacheServiceTest method testSaveOrUpdateCachedSame.
@Test
public void testSaveOrUpdateCachedSame() {
KeytabCache keytabCache = new KeytabCache();
keytabCache.setKeytab(KEYTAB);
when(keytabCacheRepository.findByEnvironmentCrnAndPrincipalHash(ENVIRONMENT_CRN, PRINCIPAL_HASH)).thenReturn(Optional.of(keytabCache));
KeytabCache result = underTest.saveOrUpdate(ENVIRONMENT_CRN, KEYTAB_PRINCIPAL, HOSTNAME, KEYTAB);
assertEquals(keytabCache, result);
verify(keytabCacheRepository, times(0)).save(any(KeytabCache.class));
}
Aggregations