Search in sources :

Example 41 with Credential

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;
}
Also used : Credential(com.sequenceiq.cloudbreak.domain.Credential)

Example 42 with 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());
    }
}
Also used : ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) Credential(com.sequenceiq.cloudbreak.domain.Credential) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) InteractiveCredentialCreationRequest(com.sequenceiq.cloudbreak.cloud.event.credential.InteractiveCredentialCreationRequest) DuplicateKeyValueException(com.sequenceiq.cloudbreak.service.DuplicateKeyValueException)

Example 43 with Credential

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);
}
Also used : Credential(com.sequenceiq.cloudbreak.domain.Credential) UserProfile(com.sequenceiq.cloudbreak.domain.UserProfile) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Json(com.sequenceiq.cloudbreak.domain.json.Json) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 44 with Credential

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());
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) Credential(com.sequenceiq.cloudbreak.domain.Credential) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Template(com.sequenceiq.cloudbreak.domain.Template) Stack(com.sequenceiq.cloudbreak.domain.Stack) IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) Network(com.sequenceiq.cloudbreak.domain.Network) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Credential (com.sequenceiq.cloudbreak.domain.Credential)44 Test (org.junit.Test)14 IdentityUser (com.sequenceiq.cloudbreak.common.model.user.IdentityUser)8 AccessDeniedException (org.springframework.security.access.AccessDeniedException)8 Json (com.sequenceiq.cloudbreak.domain.json.Json)7 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)6 Template (com.sequenceiq.cloudbreak.domain.Template)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 FileSystemConfiguration (com.sequenceiq.cloudbreak.api.model.FileSystemConfiguration)3 FileSystemScriptConfig (com.sequenceiq.cloudbreak.blueprint.filesystem.FileSystemScriptConfig)3 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)3 Transactional (javax.transaction.Transactional)3 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)2 GcsFileSystemConfiguration (com.sequenceiq.cloudbreak.api.model.GcsFileSystemConfiguration)2 ExtendedCloudCredential (com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential)2 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)2 PlatformDisks (com.sequenceiq.cloudbreak.cloud.model.PlatformDisks)2 VmTypeMeta (com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta)2 VolumeParameterConfig (com.sequenceiq.cloudbreak.cloud.model.VolumeParameterConfig)2 RecipeScript (com.sequenceiq.cloudbreak.common.model.recipe.RecipeScript)2