Search in sources :

Example 16 with KerberosConfig

use of com.sequenceiq.freeipa.kerberos.KerberosConfig in project cloudbreak by hortonworks.

the class KerberosConfigV1Service method getKerberosConfigIfFreeIPAExists.

private DescribeKerberosConfigResponse getKerberosConfigIfFreeIPAExists(String environmentCrn, String accountId, String clusterName, Stack stack) throws FreeIpaClientException {
    MDCBuilder.buildMdcContext(stack);
    LOGGER.debug("Get kerberos config when FreeIPA exists for env");
    Optional<KerberosConfig> existingKerberosConfig = kerberosConfigService.find(environmentCrn, accountId, clusterName);
    KerberosConfig kerberosConfig;
    if (existingKerberosConfig.isPresent()) {
        LOGGER.debug("Kerberos config already exists");
        kerberosConfig = existingKerberosConfig.get();
    } else {
        kerberosConfig = createNewKerberosConfig(environmentCrn, clusterName, stack, false);
    }
    return convertKerberosConfigToDescribeKerberosConfigResponse(kerberosConfig);
}
Also used : KerberosConfig(com.sequenceiq.freeipa.kerberos.KerberosConfig)

Example 17 with KerberosConfig

use of com.sequenceiq.freeipa.kerberos.KerberosConfig in project cloudbreak by hortonworks.

the class KerberosConfigRegisterService method createKerberosConfig.

public KerberosConfig createKerberosConfig(Long stackId, String dn, String password, String clusterName, String environmentCrn) {
    FreeIpa freeIpa = getFreeIpaService().findByStackId(stackId);
    Stack stack = getStackWithInstanceMetadata(stackId);
    if (StringUtils.isEmpty(environmentCrn)) {
        environmentCrn = stack.getEnvironmentCrn();
    }
    KerberosConfig kerberosConfig = new KerberosConfig();
    kerberosConfig.setDomain(freeIpa.getDomain());
    kerberosConfig.setEnvironmentCrn(environmentCrn);
    kerberosConfig.setName(stack.getName());
    kerberosConfig.setPrincipal(dn);
    kerberosConfig.setRealm(freeIpa.getDomain().toUpperCase());
    kerberosConfig.setType(KerberosType.FREEIPA);
    Set<InstanceMetaData> allNotDeletedInstances = stack.getInstanceGroups().stream().flatMap(instanceGroup -> instanceGroup.getNotDeletedInstanceMetaDataSet().stream()).collect(Collectors.toSet());
    String allFreeIpaIpJoined = allNotDeletedInstances.stream().map(InstanceMetaData::getPrivateIp).collect(Collectors.joining(","));
    kerberosConfig.setNameServers(allFreeIpaIpJoined);
    addServerAddress(freeIpa, stack, kerberosConfig, allNotDeletedInstances);
    kerberosConfig.setPassword(StringUtils.isBlank(password) ? freeIpa.getAdminPassword() : password);
    kerberosConfig.setClusterName(clusterName);
    return kerberosConfigService.createKerberosConfig(kerberosConfig, stack.getAccountId());
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Logger(org.slf4j.Logger) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) Inject(javax.inject.Inject) Service(org.springframework.stereotype.Service) KerberosConfigService(com.sequenceiq.freeipa.kerberos.KerberosConfigService) KerberosConfig(com.sequenceiq.freeipa.kerberos.KerberosConfig) BalancedDnsAvailabilityChecker(com.sequenceiq.freeipa.util.BalancedDnsAvailabilityChecker) KerberosType(com.sequenceiq.freeipa.api.v1.kerberos.model.KerberosType) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Stack(com.sequenceiq.freeipa.entity.Stack) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) KerberosConfig(com.sequenceiq.freeipa.kerberos.KerberosConfig) Stack(com.sequenceiq.freeipa.entity.Stack)

Example 18 with KerberosConfig

use of com.sequenceiq.freeipa.kerberos.KerberosConfig in project cloudbreak by hortonworks.

the class KerberosConfigUpdateService method updateNameservers.

public void updateNameservers(Long stackId) {
    Stack stack = getStackWithInstanceMetadata(stackId);
    String environmentCrn = stack.getEnvironmentCrn();
    Set<InstanceMetaData> allNotDeletedInstances = stack.getInstanceGroups().stream().flatMap(instanceGroup -> instanceGroup.getNotDeletedInstanceMetaDataSet().stream()).collect(Collectors.toSet());
    String allFreeIpaIpJoined = allNotDeletedInstances.stream().map(InstanceMetaData::getPrivateIp).collect(Collectors.joining(","));
    List<KerberosConfig> kerberosConfigs = kerberosConfigService.findAllInEnvironment(environmentCrn);
    kerberosConfigs.forEach(kerberosConfig -> {
        kerberosConfig.setNameServers(allFreeIpaIpJoined);
    });
    kerberosConfigService.saveAll(kerberosConfigs);
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Inject(javax.inject.Inject) List(java.util.List) Logger(org.slf4j.Logger) Service(org.springframework.stereotype.Service) LoggerFactory(org.slf4j.LoggerFactory) KerberosConfigService(com.sequenceiq.freeipa.kerberos.KerberosConfigService) Set(java.util.Set) KerberosConfig(com.sequenceiq.freeipa.kerberos.KerberosConfig) StackService(com.sequenceiq.freeipa.service.stack.StackService) Collectors(java.util.stream.Collectors) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Stack(com.sequenceiq.freeipa.entity.Stack) KerberosConfig(com.sequenceiq.freeipa.kerberos.KerberosConfig) Stack(com.sequenceiq.freeipa.entity.Stack)

Aggregations

KerberosConfig (com.sequenceiq.freeipa.kerberos.KerberosConfig)18 Test (org.junit.jupiter.api.Test)8 CreateKerberosConfigRequest (com.sequenceiq.freeipa.api.v1.kerberos.model.create.CreateKerberosConfigRequest)5 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)4 Stack (com.sequenceiq.freeipa.entity.Stack)4 ActiveDirectoryKerberosDescriptor (com.sequenceiq.freeipa.api.v1.kerberos.model.create.ActiveDirectoryKerberosDescriptor)2 FreeIpa (com.sequenceiq.freeipa.entity.FreeIpa)2 InstanceGroup (com.sequenceiq.freeipa.entity.InstanceGroup)2 CreateBindUserEvent (com.sequenceiq.freeipa.flow.freeipa.binduser.create.event.CreateBindUserEvent)2 KerberosConfigService (com.sequenceiq.freeipa.kerberos.KerberosConfigService)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Service (org.springframework.stereotype.Service)2 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)1 HandlerEvent (com.sequenceiq.flow.reactor.api.handler.HandlerEvent)1