Search in sources :

Example 6 with CheckPermissionByAccount

use of com.sequenceiq.authorization.annotation.CheckPermissionByAccount in project cloudbreak by hortonworks.

the class CustomImageCatalogV4Controller method create.

@Override
@CheckPermissionByAccount(action = AuthorizationResourceAction.CREATE_IMAGE_CATALOG)
public CustomImageCatalogV4CreateResponse create(@Valid CustomImageCatalogV4CreateRequest request, @AccountId String accountId) {
    String creator = ThreadBasedUserCrnProvider.getUserCrn();
    ImageCatalog imageCatalog = customImageCatalogV4CreateRequestToImageCatalogConverter.convert(request);
    ImageCatalog savedImageCatalog = customImageCatalogService.create(imageCatalog, restRequestThreadLocalService.getRequestedWorkspaceId(), accountId, creator);
    return imageCatalogToCustomImageCatalogV4CreateResponseConverter.convert(savedImageCatalog);
}
Also used : ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) CheckPermissionByAccount(com.sequenceiq.authorization.annotation.CheckPermissionByAccount)

Example 7 with CheckPermissionByAccount

use of com.sequenceiq.authorization.annotation.CheckPermissionByAccount in project cloudbreak by hortonworks.

the class EnvironmentController method post.

@Override
@CheckPermissionByAccount(action = AuthorizationResourceAction.CREATE_ENVIRONMENT)
@CheckPermissionByRequestProperty(path = "credentialName", type = NAME, action = DESCRIBE_CREDENTIAL)
public DetailedEnvironmentResponse post(@RequestObject @Valid EnvironmentRequest request) {
    EnvironmentCreationDto environmentCreationDto = environmentApiConverter.initCreationDto(request);
    EnvironmentDto envDto = environmentCreationService.create(environmentCreationDto);
    return environmentResponseConverter.dtoToDetailedResponse(envDto);
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) EnvironmentCreationDto(com.sequenceiq.environment.environment.dto.EnvironmentCreationDto) CheckPermissionByRequestProperty(com.sequenceiq.authorization.annotation.CheckPermissionByRequestProperty) CheckPermissionByAccount(com.sequenceiq.authorization.annotation.CheckPermissionByAccount)

Example 8 with CheckPermissionByAccount

use of com.sequenceiq.authorization.annotation.CheckPermissionByAccount in project cloudbreak by hortonworks.

the class AccountTelemetryController method update.

@Override
@CheckPermissionByAccount(action = AuthorizationResourceAction.POWERUSER_ONLY)
public AccountTelemetryResponse update(AccountTelemetryRequest request) {
    String accountId = ThreadBasedUserCrnProvider.getAccountId();
    AccountTelemetry telemetry = accountTelemetryConverter.convert(request);
    return accountTelemetryConverter.convert(accountTelemetryService.create(telemetry, accountId));
}
Also used : AccountTelemetry(com.sequenceiq.environment.telemetry.domain.AccountTelemetry) CheckPermissionByAccount(com.sequenceiq.authorization.annotation.CheckPermissionByAccount)

Example 9 with CheckPermissionByAccount

use of com.sequenceiq.authorization.annotation.CheckPermissionByAccount in project cloudbreak by hortonworks.

the class AccountTagController method generate.

@Override
@CheckPermissionByAccount(action = AuthorizationResourceAction.POWERUSER_ONLY)
public GeneratedAccountTagResponses generate(@ResourceName String environmentName, @ResourceCrn @TenantAwareParam String environmentCrn) {
    String accountId = ThreadBasedUserCrnProvider.getAccountId();
    EnvironmentDto environmentDto = null;
    if (!Strings.isNullOrEmpty(environmentCrn)) {
        environmentDto = environmentService.getByCrnAndAccountId(environmentCrn, accountId);
    } else if (!Strings.isNullOrEmpty(environmentName)) {
        environmentDto = environmentService.getByNameAndAccountId(environmentName, accountId);
    }
    Map<String, String> accountTagsMap = new HashMap<>();
    if (environmentDto != null) {
        accountTagsMap = accountTagService.generate(accountId, environmentDto);
    }
    Set<GeneratedAccountTagResponse> accountTags = new HashSet<>();
    for (Map.Entry<String, String> entry : accountTagsMap.entrySet()) {
        GeneratedAccountTagResponse accountTag = new GeneratedAccountTagResponse();
        accountTag.setKey(entry.getKey());
        accountTag.setValue(entry.getValue());
        accountTags.add(accountTag);
    }
    return new GeneratedAccountTagResponses(accountTags);
}
Also used : GeneratedAccountTagResponses(com.sequenceiq.environment.api.v1.tags.model.response.GeneratedAccountTagResponses) GeneratedAccountTagResponse(com.sequenceiq.environment.api.v1.tags.model.response.GeneratedAccountTagResponse) HashMap(java.util.HashMap) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) CheckPermissionByAccount(com.sequenceiq.authorization.annotation.CheckPermissionByAccount)

Example 10 with CheckPermissionByAccount

use of com.sequenceiq.authorization.annotation.CheckPermissionByAccount in project cloudbreak by hortonworks.

the class AuditCredentialV1Controller method post.

@Override
@CheckPermissionByAccount(action = AuthorizationResourceAction.CREATE_AUDIT_CREDENTIAL)
public CredentialResponse post(@Valid CredentialRequest request) {
    String accountId = ThreadBasedUserCrnProvider.getAccountId();
    String creator = ThreadBasedUserCrnProvider.getUserCrn();
    Credential credential = credentialConverter.convert(request);
    credential.setType(AUDIT);
    credential.setVerifyPermissions(false);
    notify(ResourceEvent.CREDENTIAL_CREATED);
    Set<Credential> auditCredentialsByPlatfom = credentialService.listAvailablesByAccountId(accountId, AUDIT).stream().filter(c -> c.getCloudPlatform().equals(credential.getCloudPlatform())).collect(Collectors.toSet());
    if (auditCredentialsByPlatfom.isEmpty()) {
        return credentialConverter.convert(credentialService.create(credential, accountId, creator, AUDIT));
    } else {
        throw new BadRequestException(String.format("Audit credential already exist for %s cloud.", credential.getCloudPlatform()));
    }
}
Also used : CredentialToCredentialV1ResponseConverter(com.sequenceiq.environment.credential.v1.converter.CredentialToCredentialV1ResponseConverter) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) CredentialService(com.sequenceiq.environment.credential.service.CredentialService) Credential(com.sequenceiq.environment.credential.domain.Credential) AUDIT(com.sequenceiq.common.model.CredentialType.AUDIT) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Set(java.util.Set) CredentialDeleteService(com.sequenceiq.environment.credential.service.CredentialDeleteService) Controller(org.springframework.stereotype.Controller) CheckPermissionByAccount(com.sequenceiq.authorization.annotation.CheckPermissionByAccount) Collectors(java.util.stream.Collectors) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) Valid(javax.validation.Valid) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) AccountId(com.sequenceiq.cloudbreak.auth.security.internal.AccountId) CredentialRequest(com.sequenceiq.environment.api.v1.credential.model.request.CredentialRequest) CredentialPrerequisitesResponse(com.sequenceiq.cloudbreak.cloud.response.CredentialPrerequisitesResponse) NotificationController(com.sequenceiq.notification.NotificationController) EditCredentialRequest(com.sequenceiq.environment.api.v1.credential.model.request.EditCredentialRequest) AuthorizationResourceAction(com.sequenceiq.authorization.resource.AuthorizationResourceAction) TenantAwareParam(com.sequenceiq.cloudbreak.auth.security.internal.TenantAwareParam) AuditCredentialEndpoint(com.sequenceiq.environment.api.v1.credential.endpoint.AuditCredentialEndpoint) CredentialResponses(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponses) Credential(com.sequenceiq.environment.credential.domain.Credential) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) CheckPermissionByAccount(com.sequenceiq.authorization.annotation.CheckPermissionByAccount)

Aggregations

CheckPermissionByAccount (com.sequenceiq.authorization.annotation.CheckPermissionByAccount)33 Credential (com.sequenceiq.environment.credential.domain.Credential)8 ProxyConfig (com.sequenceiq.environment.proxy.domain.ProxyConfig)4 StackView (com.sequenceiq.cloudbreak.domain.view.StackView)3 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)3 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)3 SdxClusterResponse (com.sequenceiq.sdx.api.model.SdxClusterResponse)3 PageRequest (org.springframework.data.domain.PageRequest)3 AuthorizationResourceAction (com.sequenceiq.authorization.resource.AuthorizationResourceAction)2 AccountId (com.sequenceiq.cloudbreak.auth.security.internal.AccountId)2 TenantAwareParam (com.sequenceiq.cloudbreak.auth.security.internal.TenantAwareParam)2 ImageCatalog (com.sequenceiq.cloudbreak.domain.ImageCatalog)2 ProxyResponse (com.sequenceiq.environment.api.v1.proxy.model.response.ProxyResponse)2 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)2 Controller (org.springframework.stereotype.Controller)2 CheckPermissionByRequestProperty (com.sequenceiq.authorization.annotation.CheckPermissionByRequestProperty)1 EventV4Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v4.events.EventV4Endpoint)1 CloudbreakEventV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.events.responses.CloudbreakEventV4Response)1 CloudbreakEventV4Responses (com.sequenceiq.cloudbreak.api.endpoint.v4.events.responses.CloudbreakEventV4Responses)1 ResourceEventResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.util.responses.ResourceEventResponse)1