use of com.sequenceiq.environment.environment.domain.EnvironmentAuthentication in project cloudbreak by hortonworks.
the class EnvironmentModificationService method editAuthenticationIfChanged.
@VisibleForTesting
void editAuthenticationIfChanged(EnvironmentEditDto editDto, Environment environment) {
AuthenticationDto authenticationDto = editDto.getAuthentication();
if (authenticationDto != null) {
EnvironmentValidatorService validatorService = environmentService.getValidatorService();
ValidationResult validationResult = validatorService.validateAuthenticationModification(editDto, environment);
if (validationResult.hasError()) {
throw new BadRequestException(validationResult.getFormattedErrors());
}
EnvironmentAuthentication originalAuthentication = environment.getAuthentication();
if (environmentResourceService.isRawSshKeyUpdateSupported(environment)) {
EnvironmentAuthentication updated = authenticationDtoConverter.dtoToSshUpdatedAuthentication(authenticationDto);
updated.setLoginUserName(originalAuthentication.getLoginUserName());
updated.setId(originalAuthentication.getId());
environment.setAuthentication(updated);
} else if (environmentResourceService.isExistingSshKeyUpdateSupported(environment)) {
environment.setAuthentication(authenticationDtoConverter.dtoToAuthentication(authenticationDto));
boolean cleanupOldSshKey = true;
if (StringUtils.isNotEmpty(authenticationDto.getPublicKey())) {
cleanupOldSshKey = environmentResourceService.createAndUpdateSshKey(environment);
}
if (cleanupOldSshKey) {
String oldSshKeyId = originalAuthentication.getPublicKeyId();
LOGGER.info("The '{}' of ssh key is replaced with {}", oldSshKeyId, environment.getAuthentication().getPublicKeyId());
if (originalAuthentication.isManagedKey()) {
environmentResourceService.deletePublicKey(environment, oldSshKeyId);
}
} else {
LOGGER.info("Authentication modification was unsuccessful. The authentication was reverted to the previous version.");
environment.setAuthentication(originalAuthentication);
}
}
}
}
use of com.sequenceiq.environment.environment.domain.EnvironmentAuthentication in project cloudbreak by hortonworks.
the class AuthenticationDtoConverter method dtoToAuthentication.
public EnvironmentAuthentication dtoToAuthentication(AuthenticationDto authenticationDto) {
EnvironmentAuthentication environmentAuthentication = new EnvironmentAuthentication();
if (isValidSshKey(authenticationDto.getPublicKey())) {
List<String> parts = Arrays.asList(StringUtils.split(authenticationDto.getPublicKey(), " "));
environmentAuthentication.setPublicKey(String.format("%s %s %s", parts.get(0), parts.get(1), authenticationDto.getLoginUserName()));
}
environmentAuthentication.setLoginUserName(authenticationDto.getLoginUserName());
environmentAuthentication.setPublicKeyId(authenticationDto.getPublicKeyId());
environmentAuthentication.setManagedKey(authenticationDto.isManagedKey());
return environmentAuthentication;
}
Aggregations