Search in sources :

Example 1 with AccountId

use of com.sequenceiq.cloudbreak.auth.security.internal.AccountId in project cloudbreak by hortonworks.

the class EventV4Controller method download.

@Override
@CheckPermissionByAccount(action = AuthorizationResourceAction.POWERUSER_ONLY)
public Response download(String name, @AccountId String accountId) {
    StructuredEventContainer events = legacyStructuredEventService.getStructuredEventsForStack(name, workspaceService.getForCurrentUser().getId());
    StreamingOutput streamingOutput = output -> {
        try (ZipOutputStream zipOutputStream = new ZipOutputStream(output)) {
            zipOutputStream.putNextEntry(new ZipEntry("struct-events.json"));
            zipOutputStream.write(JsonUtil.writeValueAsString(events).getBytes());
            zipOutputStream.closeEntry();
        }
    };
    return Response.ok(streamingOutput).header("content-disposition", "attachment; filename = struct-events.zip").build();
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) WorkspaceEntityType(com.sequenceiq.cloudbreak.workspace.controller.WorkspaceEntityType) StructuredEventEntity(com.sequenceiq.cloudbreak.domain.StructuredEventEntity) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) Controller(org.springframework.stereotype.Controller) Inject(javax.inject.Inject) AccountId(com.sequenceiq.cloudbreak.auth.security.internal.AccountId) LegacyStructuredEventService(com.sequenceiq.cloudbreak.structuredevent.LegacyStructuredEventService) Sort(org.springframework.data.domain.Sort) CloudbreakEventV4Responses(com.sequenceiq.cloudbreak.api.endpoint.v4.events.responses.CloudbreakEventV4Responses) ZipEntry(java.util.zip.ZipEntry) NotFoundException.notFound(com.sequenceiq.cloudbreak.common.exception.NotFoundException.notFound) TxType(javax.transaction.Transactional.TxType) Transactional(javax.transaction.Transactional) PageRequest(org.springframework.data.domain.PageRequest) WorkspaceService(com.sequenceiq.cloudbreak.service.workspace.WorkspaceService) StreamingOutput(javax.ws.rs.core.StreamingOutput) CheckPermissionByAccount(com.sequenceiq.authorization.annotation.CheckPermissionByAccount) Page(org.springframework.data.domain.Page) EventV4Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v4.events.EventV4Endpoint) List(java.util.List) Response(javax.ws.rs.core.Response) CloudbreakEventsFacade(com.sequenceiq.cloudbreak.facade.CloudbreakEventsFacade) StructuredEventContainer(com.sequenceiq.cloudbreak.structuredevent.event.StructuredEventContainer) Optional(java.util.Optional) AuthorizationResourceAction(com.sequenceiq.authorization.resource.AuthorizationResourceAction) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) TenantAwareParam(com.sequenceiq.cloudbreak.auth.security.internal.TenantAwareParam) CloudbreakEventV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.events.responses.CloudbreakEventV4Response) ZipOutputStream(java.util.zip.ZipOutputStream) StructuredEventContainer(com.sequenceiq.cloudbreak.structuredevent.event.StructuredEventContainer) ZipEntry(java.util.zip.ZipEntry) StreamingOutput(javax.ws.rs.core.StreamingOutput) CheckPermissionByAccount(com.sequenceiq.authorization.annotation.CheckPermissionByAccount)

Example 2 with AccountId

use of com.sequenceiq.cloudbreak.auth.security.internal.AccountId 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)2 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 Controller (org.springframework.stereotype.Controller)2 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 ThreadBasedUserCrnProvider (com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider)1 CredentialPrerequisitesResponse (com.sequenceiq.cloudbreak.cloud.response.CredentialPrerequisitesResponse)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 NotFoundException.notFound (com.sequenceiq.cloudbreak.common.exception.NotFoundException.notFound)1 JsonUtil (com.sequenceiq.cloudbreak.common.json.JsonUtil)1 StructuredEventEntity (com.sequenceiq.cloudbreak.domain.StructuredEventEntity)1 StackView (com.sequenceiq.cloudbreak.domain.view.StackView)1 ResourceEvent (com.sequenceiq.cloudbreak.event.ResourceEvent)1 CloudbreakEventsFacade (com.sequenceiq.cloudbreak.facade.CloudbreakEventsFacade)1 StackService (com.sequenceiq.cloudbreak.service.stack.StackService)1 WorkspaceService (com.sequenceiq.cloudbreak.service.workspace.WorkspaceService)1 LegacyStructuredEventService (com.sequenceiq.cloudbreak.structuredevent.LegacyStructuredEventService)1