use of com.sequenceiq.cloudbreak.domain.Credential in project cloudbreak by hortonworks.
the class TestUtil method gcpCredential.
public static Credential gcpCredential() {
Credential credential = new Credential();
credential.setId(1L);
credential.setName(DUMMY_NAME);
credential.setCloudPlatform(GCP);
credential.setPublicInAccount(true);
credential.setDescription(DUMMY_DESCRIPTION);
return credential;
}
use of com.sequenceiq.cloudbreak.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 {
credentialService.createWithRetry(extendedCloudCredential.getOwner(), extendedCloudCredential.getAccount(), credential);
} catch (DuplicateKeyValueException e) {
sendErrorNotification(extendedCloudCredential.getOwner(), extendedCloudCredential.getAccount(), extendedCloudCredential.getCloudPlatform(), DuplicatedKeyValueExceptionMapper.errorMessage(e));
} catch (BadRequestException e) {
sendErrorNotification(extendedCloudCredential.getOwner(), extendedCloudCredential.getAccount(), extendedCloudCredential.getCloudPlatform(), e.getMessage());
}
}
use of com.sequenceiq.cloudbreak.domain.Credential in project cloudbreak by hortonworks.
the class UserProfileService method put.
public void put(UserProfileRequest request, IdentityUser user) {
UserProfile userProfile = get(user.getAccount(), user.getUserId(), user.getUsername());
if (request.getCredentialId() != null) {
Credential credential = credentialService.get(request.getCredentialId(), userProfile.getAccount());
userProfile.setCredential(credential);
} else if (request.getCredentialName() != null) {
Credential credential = credentialService.get(request.getCredentialName(), userProfile.getAccount());
userProfile.setCredential(credential);
}
for (Entry<String, Object> uiStringObjectEntry : request.getUiProperties().entrySet()) {
Map<String, Object> map = userProfile.getUiProperties().getMap();
if (map == null || map.isEmpty()) {
map = new HashMap<>();
}
map.put(uiStringObjectEntry.getKey(), uiStringObjectEntry.getValue());
try {
userProfile.setUiProperties(new Json(map));
} catch (JsonProcessingException ignored) {
throw new BadRequestException("The modification of the ui properties was unsuccesfull.");
}
}
userProfileRepository.save(userProfile);
}
use of com.sequenceiq.cloudbreak.domain.Credential in project cloudbreak by hortonworks.
the class UserResourceCheck method hasResources.
@Transactional(readOnly = true)
public boolean hasResources(IdentityUser admin, String userId) {
IdentityUser user = userDetailsService.getDetails(userId, UserFilterField.USERID);
LOGGER.info("{} / {} checks resources of {}", admin.getUserId(), admin.getUsername(), userId);
String errorMessage = null;
if (!admin.getRoles().contains(IdentityUserRole.ADMIN)) {
errorMessage = "Forbidden: user (%s) is not authorized for this operation on %s";
}
if (!admin.getAccount().equals(user.getAccount())) {
errorMessage = "Forbidden: admin (%s) and user (%s) are not under the same account.";
}
if (!Strings.isNullOrEmpty(errorMessage)) {
throw new AccessDeniedException(String.format(errorMessage, admin.getUsername(), user.getUsername()));
}
Set<Template> templates = templateRepository.findForUser(user.getUserId());
Set<Credential> credentials = credentialRepository.findForUser(user.getUserId());
Set<Blueprint> blueprints = blueprintRepository.findForUser(user.getUserId());
Set<Network> networks = networkRepository.findForUser(user.getUserId());
Set<Stack> stacks = stackRepository.findForUser(user.getUserId());
return !(stacks.isEmpty() && templates.isEmpty() && credentials.isEmpty() && blueprints.isEmpty() && networks.isEmpty());
}
Aggregations