Search in sources :

Example 11 with Credential

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

the class CredentialService method getPublicCredential.

public Credential getPublicCredential(String name, IdentityUser user) {
    Credential credential = credentialRepository.findOneByName(name, user.getAccount());
    if (credential == null) {
        throw new AccessDeniedException(String.format("Access is denied: Credential '%s'", name));
    }
    authorizationService.hasReadPermission(credential);
    return credential;
}
Also used : Credential(com.sequenceiq.cloudbreak.domain.Credential) AccessDeniedException(org.springframework.security.access.AccessDeniedException)

Example 12 with Credential

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

the class CredentialService method delete.

@Transactional(TxType.NEVER)
public void delete(Long id, IdentityUser user) {
    Credential credential = credentialRepository.findByIdInAccount(id, user.getAccount());
    if (credential == null) {
        throw new AccessDeniedException(String.format("Access is denied: Credential '%d'.", id));
    }
    delete(credential);
}
Also used : Credential(com.sequenceiq.cloudbreak.domain.Credential) AccessDeniedException(org.springframework.security.access.AccessDeniedException) Transactional(javax.transaction.Transactional)

Example 13 with Credential

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

the class CredentialService method delete.

@Transactional(TxType.NEVER)
public void delete(String name, IdentityUser user) {
    Credential credential = credentialRepository.findByNameInAccount(name, user.getAccount(), user.getUserId());
    if (credential == null) {
        throw new AccessDeniedException(String.format("Access is denied: Credential '%s'.", name));
    }
    delete(credential);
}
Also used : Credential(com.sequenceiq.cloudbreak.domain.Credential) AccessDeniedException(org.springframework.security.access.AccessDeniedException) Transactional(javax.transaction.Transactional)

Example 14 with Credential

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

the class ServiceTestUtils method createCredential.

public static Credential createCredential(String owner, String account, String platform) {
    switch(platform) {
        case AWS:
            Credential awsCredential = new Credential();
            awsCredential.setId(1L);
            awsCredential.setOwner(owner);
            awsCredential.setCloudPlatform(platform);
            awsCredential.setAccount(account);
            awsCredential.setPublicInAccount(true);
            return awsCredential;
        case GCP:
            Credential gcpCredential = new Credential();
            gcpCredential.setId(1L);
            gcpCredential.setOwner(owner);
            gcpCredential.setCloudPlatform(platform);
            gcpCredential.setAccount(account);
            gcpCredential.setPublicInAccount(true);
            return gcpCredential;
        default:
            return null;
    }
}
Also used : Credential(com.sequenceiq.cloudbreak.domain.Credential)

Example 15 with Credential

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

the class CredentialServiceTest method testModifyDifferentPlatform.

@Test
public void testModifyDifferentPlatform() {
    Credential credential = new Credential();
    credential.setCloudPlatform("BAD");
    thrown.expect(BadRequestException.class);
    thrown.expectMessage("Modifying credential platform is forbidden");
    credentialService.modify(user, credential);
}
Also used : Credential(com.sequenceiq.cloudbreak.domain.Credential) Test(org.junit.Test)

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