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());
}
}
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;
}
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;
}
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;
}
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);
}
Aggregations