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);
}
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);
}
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));
}
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);
}
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()));
}
}
Aggregations