use of com.sequenceiq.freeipa.entity.KeytabCache in project cloudbreak by hortonworks.
the class KeytabCacheService method saveOrUpdate.
public KeytabCache saveOrUpdate(String environmentCrn, String principal, String hostname, String keytab) {
Optional<KeytabCache> keytabCache = findByEnvironmentCrnAndPrincipal(environmentCrn, principal);
if (keytabCache.isPresent()) {
KeytabCache cached = keytabCache.get();
if (Objects.equals(cached.getKeytab().getRaw(), keytab)) {
LOGGER.debug("Keytab exists in cache with the same value");
return cached;
} else {
LOGGER.debug("Keytab exists in cache with different value, updating");
cached.setKeytab(keytab);
return keytabCacheRepository.save(cached);
}
} else {
LOGGER.debug("Keytab doesn't exist in cache, saving.");
return save(environmentCrn, principal, hostname, keytab);
}
}
use of com.sequenceiq.freeipa.entity.KeytabCache 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);
}
}
use of com.sequenceiq.freeipa.entity.KeytabCache in project cloudbreak by hortonworks.
the class ServiceKeytabService method generateServiceKeytab.
public ServiceKeytabResponse generateServiceKeytab(ServiceKeytabRequest request, String accountId) throws FreeIpaClientException {
LOGGER.debug("Request to generate service keytab: {}", request);
Stack freeIpaStack = keytabCommonService.getFreeIpaStackWithMdcContext(request.getEnvironmentCrn(), accountId);
String realm = keytabCommonService.getRealm(freeIpaStack);
String principal = keytabCommonService.constructPrincipal(request.getServiceName(), request.getServerHostName(), realm);
Optional<KeytabCache> keytabCache = keytabCacheService.findByEnvironmentCrnAndPrincipal(request.getEnvironmentCrn(), principal);
if (request.getDoNotRecreateKeytab() && keytabCache.isPresent()) {
LOGGER.debug("Keytab is found in cache, using it");
return createServiceKeytabResponse(keytabCache.get());
} else {
LOGGER.debug("Keytab is not found in cache, or existing can't be reused.");
FreeIpaClient ipaClient = freeIpaClientFactory.getFreeIpaClientForStack(freeIpaStack);
if (!roleComponent.privilegesExist(request.getRoleRequest(), ipaClient)) {
throw new KeytabCreationException(PRIVILEGE_DOES_NOT_EXIST);
}
keytabCommonService.addHost(request.getServerHostName(), null, ipaClient);
com.sequenceiq.freeipa.client.model.Service service = addAndSetupService(request, realm, ipaClient);
KeytabCache serviceKeytab = fetchKeytabFromFreeIpa(request, ipaClient, service);
return createServiceKeytabResponse(serviceKeytab);
}
}
Aggregations