Search in sources :

Example 1 with Credential

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

the class InteractiveCredentialCreationHandler method accept.

@Override
public void accept(Event<InteractiveCredentialCreationRequest> interactiveCredentialCreationRequestEvent) {
    InteractiveCredentialCreationRequest interactiveCredentialCreationRequest = interactiveCredentialCreationRequestEvent.getData();
    ExtendedCloudCredential extendedCloudCredential = interactiveCredentialCreationRequest.getExtendedCloudCredential();
    Credential credential = extendedCloudCredentialToCredentialConverter.convert(extendedCloudCredential);
    try {
        LOGGER.debug("Azure init code grant flow for account id {} creator {} credential name {}", credential.getAccountId(), credential.getCreator(), credential.getName());
        credentialService.initCodeGrantFlow(credential.getAccountId(), credential, credential.getCreator());
        CredentialResponse payload = extendedCloudCredentialToCredentialConverter.convert(credential);
        LOGGER.debug("Sending notification that the interactive credential successfully created account id {} creator {} credential name {}", credential.getAccountId(), credential.getCreator(), credential.getName());
        eventService.sendEventAndNotificationWithPayload(credential, credential.getCreator(), CREDENTIAL_AZURE_INTERACTIVE_CREATED, payload);
        LOGGER.info("Azure interactive credential ({}) succesfully created", credential.getName());
    } catch (BadRequestException e) {
        LOGGER.debug("Sending notification that the interactive credential failed to create account id {} creator {} credential name {}", credential.getAccountId(), credential.getCreator(), credential.getName());
        eventService.sendEventAndNotificationWithPayload(credential, credential.getCreator(), CREDENTIAL_AZURE_INTERACTIVE_FAILED, null);
        LOGGER.info("Failed to create Azure interactive credential with name \"{}\"", credential.getName());
    }
}
Also used : ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) Credential(com.sequenceiq.environment.credential.domain.Credential) BadRequestException(javax.ws.rs.BadRequestException) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) InteractiveCredentialCreationRequest(com.sequenceiq.cloudbreak.cloud.event.credential.InteractiveCredentialCreationRequest)

Example 2 with Credential

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

the class CredentialDeleteService method deleteByName.

public Credential deleteByName(String name, String accountId, CredentialType type) {
    Credential credential = credentialService.findByNameAndAccountId(name, accountId, getEnabledPlatforms(), type).orElseThrow(notFound(NOT_FOUND_FORMAT_MESS_NAME, name));
    checkEnvironmentsForDeletion(credential);
    LOGGER.debug("About to archive credential: {}", name);
    Credential archived = archiveCredential(credential);
    ownerAssignmentService.notifyResourceDeleted(archived.getResourceCrn(), MDCUtils.getRequestId());
    sendCredentialNotification(credential, ResourceEvent.CREDENTIAL_DELETED);
    return archived;
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential)

Example 3 with Credential

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

the class CredentialDeleteService method deleteByCrn.

public Credential deleteByCrn(String crn, String accountId, CredentialType type) {
    Credential credential = credentialService.findByCrnAndAccountId(crn, accountId, getEnabledPlatforms(), type).orElseThrow(notFound(NOT_FOUND_FORMAT_MESS_NAME, crn));
    checkEnvironmentsForDeletion(credential);
    LOGGER.debug("About to archive credential: {}", crn);
    Credential archived = archiveCredential(credential);
    ownerAssignmentService.notifyResourceDeleted(archived.getResourceCrn(), MDCUtils.getRequestId());
    sendCredentialNotification(credential, ResourceEvent.CREDENTIAL_DELETED);
    return archived;
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential)

Example 4 with Credential

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

the class CredentialService method authorizeCodeGrantFlow.

public Credential authorizeCodeGrantFlow(String code, @Nonnull String state, String accountId, @Nonnull String platform) {
    String cloudPlatformUpperCased = platform.toUpperCase();
    Set<Credential> credentials = repository.findAllByAccountId(accountId, List.of(cloudPlatformUpperCased), ENVIRONMENT);
    Credential original = getCredentialByCodeGrantFlowState(state, credentials);
    LOGGER.info("Authorizing credential('{}') with Authorization Code Grant flow.", original.getName());
    String attributesSecret = original.getAttributesSecret();
    updateAuthorizationCodeOfAzureCredential(original, code);
    Credential updated = repository.save(credentialAdapter.verify(original, accountId).getCredential());
    secretService.delete(attributesSecret);
    return updated;
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential)

Example 5 with Credential

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

the class CredentialService method initCodeGrantFlow.

public String initCodeGrantFlow(String accountId, @Nonnull Credential credential, String creatorUserCrn) {
    repository.findByNameAndAccountId(credential.getName(), accountId, getEnabledPlatforms(), ENVIRONMENT).map(Credential::getName).ifPresent(name -> {
        throw new BadRequestException("Credential already exists with name: " + name);
    });
    LOGGER.debug("Validating credential for cloudPlatform {} and creator {}.", credential.getCloudPlatform(), creatorUserCrn);
    credentialValidator.validateCredentialCloudPlatform(credential.getCloudPlatform(), creatorUserCrn, ENVIRONMENT);
    validateDeploymentAddress(credential);
    Credential created = credentialAdapter.initCodeGrantFlow(credential, accountId);
    created.setResourceCrn(createCRN(accountId));
    created.setAccountId(accountId);
    created.setCreator(creatorUserCrn);
    created = repository.save(created);
    return getCodeGrantFlowAppLoginUrl(created);
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) BadRequestException(javax.ws.rs.BadRequestException)

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