Search in sources :

Example 6 with SecurityAccessDto

use of com.sequenceiq.environment.environment.dto.SecurityAccessDto in project cloudbreak by hortonworks.

the class EnvironmentValidatorServiceTest method testValidateSecurityAccessModificationWhenEnvCidrIsNotEmptyAndKnoxAndDefaultSecGroupAdded.

@Test
void testValidateSecurityAccessModificationWhenEnvCidrIsNotEmptyAndKnoxAndDefaultSecGroupAdded() {
    Environment environment = new Environment();
    environment.setCidr("cidr");
    SecurityAccessDto securityAccessDto = SecurityAccessDto.builder().withDefaultSecurityGroupId("sec-group").withSecurityGroupIdForKnox("knox-sec-group").build();
    ValidationResult validationResult = underTest.validateSecurityAccessModification(securityAccessDto, environment);
    assertFalse(validationResult.hasError());
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) SecurityAccessDto(com.sequenceiq.environment.environment.dto.SecurityAccessDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with SecurityAccessDto

use of com.sequenceiq.environment.environment.dto.SecurityAccessDto in project cloudbreak by hortonworks.

the class EnvironmentApiConverter method initCreationDto.

public EnvironmentCreationDto initCreationDto(EnvironmentRequest request) {
    LOGGER.debug("Creating EnvironmentCreationDto from EnvironmentRequest: {}", request);
    String accountId = ThreadBasedUserCrnProvider.getAccountId();
    String cloudPlatform = credentialService.getCloudPlatformByCredential(request.getCredentialName(), accountId, ENVIRONMENT);
    Builder builder = EnvironmentCreationDto.builder().withAccountId(accountId).withCreator(ThreadBasedUserCrnProvider.getUserCrn()).withName(request.getName()).withDescription(request.getDescription()).withCloudPlatform(cloudPlatform).withCredential(request).withCreated(System.currentTimeMillis()).withFreeIpaCreation(freeIpaConverter.convert(request.getFreeIpa(), accountId, cloudPlatform)).withLocation(locationRequestToDto(request.getLocation())).withTelemetry(telemetryApiConverter.convert(request.getTelemetry(), accountTelemetryService.getOrDefault(accountId).getFeatures(), accountId)).withBackup((request.getBackup() != null && isNotEmpty(request.getBackup().getStorageLocation())) ? backupConverter.convert(request.getBackup()) : backupConverter.convert(request.getTelemetry())).withRegions(locationRequestToRegions(request.getLocation(), cloudPlatform)).withAuthentication(authenticationRequestToDto(request.getAuthentication())).withAdminGroupName(request.getAdminGroupName()).withTags(request.getTags()).withCrn(createCrn(ThreadBasedUserCrnProvider.getAccountId())).withExperimentalFeatures(ExperimentalFeatures.builder().withIdBrokerMappingSource(request.getIdBrokerMappingSource()).withCloudStorageValidation(request.getCloudStorageValidation()).withTunnel(tunnelConverter.convert(request.getTunnel())).withOverrideTunnel(request.getOverrideTunnel()).withCcmV2TlsType(request.getCcmV2TlsType()).build()).withParameters(paramsToParametersDto(request, cloudPlatform)).withParentEnvironmentName(request.getParentEnvironmentName()).withProxyConfigName(request.getProxyConfigName());
    NullUtil.doIfNotNull(request.getNetwork(), network -> builder.withNetwork(networkRequestToDto(network)));
    NullUtil.doIfNotNull(request.getSecurityAccess(), securityAccess -> builder.withSecurityAccess(securityAccessRequestToDto(securityAccess)));
    // TODO temporary until CCM not really integrated
    if (request.getSecurityAccess() == null && !CloudPlatform.GCP.name().equals(cloudPlatform)) {
        SecurityAccessDto securityAccess = SecurityAccessDto.builder().withCidr("0.0.0.0/0").build();
        builder.withSecurityAccess(securityAccess);
    }
    return builder.build();
}
Also used : Builder(com.sequenceiq.environment.environment.dto.EnvironmentCreationDto.Builder) SecurityAccessDto(com.sequenceiq.environment.environment.dto.SecurityAccessDto)

Example 8 with SecurityAccessDto

use of com.sequenceiq.environment.environment.dto.SecurityAccessDto in project cloudbreak by hortonworks.

the class GcpEnvironmentSecurityGroupValidator method validate.

@Override
public void validate(EnvironmentValidationDto environmentValidationDto, ValidationResult.ValidationResultBuilder resultBuilder) {
    EnvironmentDto environmentDto = environmentValidationDto.getEnvironmentDto();
    SecurityAccessDto securityAccessDto = environmentDto.getSecurityAccess();
    if (securityAccessDto != null) {
        if (onlyOneSecurityGroupIdDefined(securityAccessDto)) {
            resultBuilder.error(securityGroupIdsMustBePresent());
        } else if (isSecurityGroupIdDefined(securityAccessDto)) {
            if (!Strings.isNullOrEmpty(securityAccessDto.getDefaultSecurityGroupId())) {
                validateSecurityGroup(environmentDto, resultBuilder, securityAccessDto.getDefaultSecurityGroupId());
            }
            if (!Strings.isNullOrEmpty(securityAccessDto.getSecurityGroupIdForKnox())) {
                validateSecurityGroup(environmentDto, resultBuilder, securityAccessDto.getSecurityGroupIdForKnox());
            }
        }
    }
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) SecurityAccessDto(com.sequenceiq.environment.environment.dto.SecurityAccessDto)

Example 9 with SecurityAccessDto

use of com.sequenceiq.environment.environment.dto.SecurityAccessDto in project cloudbreak by hortonworks.

the class EnvironmentModificationService method editSecurityAccessIfChanged.

private void editSecurityAccessIfChanged(EnvironmentEditDto editDto, Environment environment) {
    SecurityAccessDto securityAccessDto = editDto.getSecurityAccess();
    if (securityAccessDto != null) {
        EnvironmentValidatorService validatorService = environmentService.getValidatorService();
        ValidationResult validationResult = validatorService.validateSecurityAccessModification(securityAccessDto, environment);
        if (validationResult.hasError()) {
            throw new BadRequestException(validationResult.getFormattedErrors());
        }
        validationResult = validatorService.validateSecurityGroups(editDto, environment);
        if (validationResult.hasError()) {
            throw new BadRequestException(validationResult.getFormattedErrors());
        }
        environmentService.editSecurityAccess(environment, securityAccessDto);
    }
}
Also used : BadRequestException(javax.ws.rs.BadRequestException) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) EnvironmentValidatorService(com.sequenceiq.environment.environment.validation.EnvironmentValidatorService) SecurityAccessDto(com.sequenceiq.environment.environment.dto.SecurityAccessDto)

Example 10 with SecurityAccessDto

use of com.sequenceiq.environment.environment.dto.SecurityAccessDto in project cloudbreak by hortonworks.

the class NetworkServiceTest method testRefreshMetadataFromAwsCloudProviderMustUseSubnetId.

@Test
public void testRefreshMetadataFromAwsCloudProviderMustUseSubnetId() {
    NetworkDto networkDto = mock(NetworkDto.class);
    AuthenticationDto authenticationDto = mock(AuthenticationDto.class);
    EnvironmentTelemetry environmentTelemetry = mock(EnvironmentTelemetry.class);
    EnvironmentBackup environmentBackup = mock(EnvironmentBackup.class);
    SecurityAccessDto securityAccessDto = mock(SecurityAccessDto.class);
    ParametersDto parametersDto = mock(ParametersDto.class);
    EnvironmentNetworkConverter environmentNetworkConverter = mock(EnvironmentNetworkConverter.class);
    Network network = mock(Network.class);
    Credential credential = mock(Credential.class);
    BaseNetwork baseNetwork = new GcpNetwork();
    baseNetwork.setRegistrationType(RegistrationType.EXISTING);
    Environment environment = new Environment();
    environment.setCloudPlatform("AWS");
    environment.setCredential(credential);
    EnvironmentEditDto environmentEditDto = new EnvironmentEditDto("description", "accountId", networkDto, authenticationDto, environmentTelemetry, environmentBackup, securityAccessDto, Tunnel.CCMV2, IdBrokerMappingSource.MOCK, CloudStorageValidation.ENABLED, "adminGroupName", parametersDto);
    when(environmentNetworkConverterMap.get(any(CloudPlatform.class))).thenReturn(environmentNetworkConverter);
    when(environmentNetworkConverter.convertToDto(baseNetwork)).thenReturn(networkDto);
    when(cloudNetworkService.retrieveSubnetMetadata(any(Environment.class), any(NetworkDto.class))).thenReturn(Map.of("s1", cloudSubnet("s1", "subnet1")));
    when(cloudNetworkService.retrieveEndpointGatewaySubnetMetadata(any(Environment.class), any(NetworkDto.class))).thenReturn(Map.of("s1", cloudSubnet("s1", "subnet1")));
    when(environmentNetworkConverter.convertToNetwork(any(BaseNetwork.class))).thenReturn(network);
    when(environmentNetworkService.getNetworkCidr(any(Network.class), anyString(), any(Credential.class))).thenReturn(new NetworkCidr("10.0.0.0", new ArrayList<>()));
    BaseNetwork result = underTest.refreshMetadataFromCloudProvider(baseNetwork, environmentEditDto, environment);
    Assertions.assertEquals(result.getSubnetMetas().keySet().stream().findFirst().get(), "s1");
    Assertions.assertEquals(result.getSubnetMetas().keySet().size(), 1);
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) EnvironmentTelemetry(com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry) Credential(com.sequenceiq.environment.credential.domain.Credential) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) EnvironmentBackup(com.sequenceiq.environment.environment.dto.EnvironmentBackup) GcpNetwork(com.sequenceiq.environment.network.dao.domain.GcpNetwork) ArrayList(java.util.ArrayList) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) EnvironmentNetworkConverter(com.sequenceiq.environment.network.v1.converter.EnvironmentNetworkConverter) NetworkCidr(com.sequenceiq.cloudbreak.cloud.network.NetworkCidr) AuthenticationDto(com.sequenceiq.environment.environment.dto.AuthenticationDto) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) GcpNetwork(com.sequenceiq.environment.network.dao.domain.GcpNetwork) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) Environment(com.sequenceiq.environment.environment.domain.Environment) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) SecurityAccessDto(com.sequenceiq.environment.environment.dto.SecurityAccessDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

SecurityAccessDto (com.sequenceiq.environment.environment.dto.SecurityAccessDto)17 Environment (com.sequenceiq.environment.environment.domain.Environment)11 Test (org.junit.jupiter.api.Test)11 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 EnvironmentEditDto (com.sequenceiq.environment.environment.dto.EnvironmentEditDto)5 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)4 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)4 BadRequestException (javax.ws.rs.BadRequestException)3 Network (com.sequenceiq.cloudbreak.cloud.model.Network)2 NetworkCidr (com.sequenceiq.cloudbreak.cloud.network.NetworkCidr)2 CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)2 Credential (com.sequenceiq.environment.credential.domain.Credential)2 AuthenticationDto (com.sequenceiq.environment.environment.dto.AuthenticationDto)2 EnvironmentBackup (com.sequenceiq.environment.environment.dto.EnvironmentBackup)2 EnvironmentTelemetry (com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry)2 AwsNetwork (com.sequenceiq.environment.network.dao.domain.AwsNetwork)2 BaseNetwork (com.sequenceiq.environment.network.dao.domain.BaseNetwork)2 GcpNetwork (com.sequenceiq.environment.network.dao.domain.GcpNetwork)2 EnvironmentNetworkConverter (com.sequenceiq.environment.network.v1.converter.EnvironmentNetworkConverter)2