Search in sources :

Example 1 with AUDIT

use of com.sequenceiq.common.model.CredentialType.AUDIT 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)1 AuthorizationResourceAction (com.sequenceiq.authorization.resource.AuthorizationResourceAction)1 ThreadBasedUserCrnProvider (com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider)1 AccountId (com.sequenceiq.cloudbreak.auth.security.internal.AccountId)1 TenantAwareParam (com.sequenceiq.cloudbreak.auth.security.internal.TenantAwareParam)1 CredentialPrerequisitesResponse (com.sequenceiq.cloudbreak.cloud.response.CredentialPrerequisitesResponse)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 ResourceEvent (com.sequenceiq.cloudbreak.event.ResourceEvent)1 AUDIT (com.sequenceiq.common.model.CredentialType.AUDIT)1 AuditCredentialEndpoint (com.sequenceiq.environment.api.v1.credential.endpoint.AuditCredentialEndpoint)1 CredentialRequest (com.sequenceiq.environment.api.v1.credential.model.request.CredentialRequest)1 EditCredentialRequest (com.sequenceiq.environment.api.v1.credential.model.request.EditCredentialRequest)1 CredentialResponse (com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse)1 CredentialResponses (com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponses)1 Credential (com.sequenceiq.environment.credential.domain.Credential)1 CredentialDeleteService (com.sequenceiq.environment.credential.service.CredentialDeleteService)1 CredentialService (com.sequenceiq.environment.credential.service.CredentialService)1 CredentialToCredentialV1ResponseConverter (com.sequenceiq.environment.credential.v1.converter.CredentialToCredentialV1ResponseConverter)1 NotificationController (com.sequenceiq.notification.NotificationController)1 Set (java.util.Set)1