Search in sources :

Example 36 with Credential

use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.

the class EnvironmentModificationService method changeCredential.

private EnvironmentDto changeCredential(String accountId, String environmentName, EnvironmentChangeCredentialDto dto, Environment environment) {
    // CHECKSTYLE:OFF
    // TODO: 2019. 06. 03. also we have to check for SDXs and DistroXs what uses the given credential. If there is at least one, we have to update the crn reference
    // through the other services
    // CHECKSTYLE:ON
    Credential credential = credentialService.getByNameForAccountId(dto.getCredentialName(), accountId, ENVIRONMENT);
    environment.setCredential(credential);
    LOGGER.debug("About to change credential on environment \"{}\"", environmentName);
    Environment saved = environmentService.save(environment);
    return environmentDtoConverter.environmentToDto(saved);
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) Environment(com.sequenceiq.environment.environment.domain.Environment)

Example 37 with Credential

use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.

the class AuditCredentialV1Controller method post.

@Override
@CheckPermissionByAccount(action = AuthorizationResourceAction.CREATE_AUDIT_CREDENTIAL)
public CredentialResponse post(@Valid CredentialRequest request) {
    String accountId = ThreadBasedUserCrnProvider.getAccountId();
    String creator = ThreadBasedUserCrnProvider.getUserCrn();
    Credential credential = credentialConverter.convert(request);
    credential.setType(AUDIT);
    credential.setVerifyPermissions(false);
    notify(ResourceEvent.CREDENTIAL_CREATED);
    Set<Credential> auditCredentialsByPlatfom = credentialService.listAvailablesByAccountId(accountId, AUDIT).stream().filter(c -> c.getCloudPlatform().equals(credential.getCloudPlatform())).collect(Collectors.toSet());
    if (auditCredentialsByPlatfom.isEmpty()) {
        return credentialConverter.convert(credentialService.create(credential, accountId, creator, AUDIT));
    } else {
        throw new BadRequestException(String.format("Audit credential already exist for %s cloud.", credential.getCloudPlatform()));
    }
}
Also used : CredentialToCredentialV1ResponseConverter(com.sequenceiq.environment.credential.v1.converter.CredentialToCredentialV1ResponseConverter) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) CredentialService(com.sequenceiq.environment.credential.service.CredentialService) Credential(com.sequenceiq.environment.credential.domain.Credential) AUDIT(com.sequenceiq.common.model.CredentialType.AUDIT) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Set(java.util.Set) CredentialDeleteService(com.sequenceiq.environment.credential.service.CredentialDeleteService) Controller(org.springframework.stereotype.Controller) CheckPermissionByAccount(com.sequenceiq.authorization.annotation.CheckPermissionByAccount) Collectors(java.util.stream.Collectors) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) Valid(javax.validation.Valid) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) AccountId(com.sequenceiq.cloudbreak.auth.security.internal.AccountId) CredentialRequest(com.sequenceiq.environment.api.v1.credential.model.request.CredentialRequest) CredentialPrerequisitesResponse(com.sequenceiq.cloudbreak.cloud.response.CredentialPrerequisitesResponse) NotificationController(com.sequenceiq.notification.NotificationController) EditCredentialRequest(com.sequenceiq.environment.api.v1.credential.model.request.EditCredentialRequest) AuthorizationResourceAction(com.sequenceiq.authorization.resource.AuthorizationResourceAction) TenantAwareParam(com.sequenceiq.cloudbreak.auth.security.internal.TenantAwareParam) AuditCredentialEndpoint(com.sequenceiq.environment.api.v1.credential.endpoint.AuditCredentialEndpoint) CredentialResponses(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponses) Credential(com.sequenceiq.environment.credential.domain.Credential) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) CheckPermissionByAccount(com.sequenceiq.authorization.annotation.CheckPermissionByAccount)

Example 38 with Credential

use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.

the class AuditCredentialV1Controller method deleteByName.

@Override
@CheckPermissionByAccount(action = AuthorizationResourceAction.CREATE_AUDIT_CREDENTIAL)
public CredentialResponse deleteByName(String name) {
    String accountId = ThreadBasedUserCrnProvider.getAccountId();
    Credential deleted = credentialDeleteService.deleteByName(name, accountId, AUDIT);
    notify(ResourceEvent.CREDENTIAL_DELETED);
    return credentialConverter.convert(deleted);
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) CheckPermissionByAccount(com.sequenceiq.authorization.annotation.CheckPermissionByAccount)

Example 39 with Credential

use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.

the class AuditCredentialV1Controller method put.

@Override
@CheckPermissionByAccount(action = AuthorizationResourceAction.MODIFY_AUDIT_CREDENTIAL)
public CredentialResponse put(@Valid EditCredentialRequest credentialRequest) {
    Credential credential = credentialConverter.convert(credentialRequest);
    credential.setType(AUDIT);
    credential = credentialService.updateByAccountId(credential, ThreadBasedUserCrnProvider.getAccountId(), AUDIT);
    notify(ResourceEvent.CREDENTIAL_MODIFIED);
    return credentialConverter.convert(credential);
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) CheckPermissionByAccount(com.sequenceiq.authorization.annotation.CheckPermissionByAccount)

Example 40 with Credential

use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.

the class CredentialV1Controller method getByEnvironmentCrn.

@Override
@CheckPermissionByResourceCrn(action = AuthorizationResourceAction.DESCRIBE_CREDENTIAL_ON_ENVIRONMENT)
public CredentialResponse getByEnvironmentCrn(@TenantAwareParam @ResourceCrn String environmentCrn) {
    String accountId = ThreadBasedUserCrnProvider.getAccountId();
    Credential credential = credentialService.getByEnvironmentCrnAndAccountId(environmentCrn, accountId, ENVIRONMENT);
    return credentialConverter.convert(credential);
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) CheckPermissionByResourceCrn(com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn)

Aggregations

Credential (com.sequenceiq.environment.credential.domain.Credential)102 Test (org.junit.jupiter.api.Test)49 Environment (com.sequenceiq.environment.environment.domain.Environment)27 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)23 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)13 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)10 ValidationResultBuilder (com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)9 EnvironmentAuthentication (com.sequenceiq.environment.environment.domain.EnvironmentAuthentication)9 EnvironmentCreationDto (com.sequenceiq.environment.environment.dto.EnvironmentCreationDto)9 BadRequestException (javax.ws.rs.BadRequestException)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 CheckPermissionByAccount (com.sequenceiq.authorization.annotation.CheckPermissionByAccount)8 ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)8 Set (java.util.Set)8 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)7 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)7 AwsNetwork (com.sequenceiq.environment.network.dao.domain.AwsNetwork)7 Map (java.util.Map)7 ExtendedPollingResult (com.sequenceiq.cloudbreak.polling.ExtendedPollingResult)6 BaseNetwork (com.sequenceiq.environment.network.dao.domain.BaseNetwork)6