Search in sources :

Example 91 with ActionResponse

use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.

the class AbstractJobResourceActions method update.

public final ActionResponse<JobFieldModel> update(UUID id, JobFieldModel resource) {
    boolean hasPermissions = hasRequiredPermissions(resource.getFieldModels(), authorizationManager::hasWritePermission);
    if (!hasPermissions) {
        return ActionResponse.createForbiddenResponse();
    }
    Optional<JobFieldModel> existingJob = findJobFieldModel(id);
    if (existingJob.isEmpty()) {
        return new ActionResponse<>(HttpStatus.NOT_FOUND);
    }
    // Clean input
    correctProjectsField(resource);
    ValidationActionResponse validationResponse = validateWithoutChecks(resource);
    if (validationResponse.isError()) {
        return new ActionResponse<>(validationResponse.getHttpStatus(), validationResponse.getMessage().orElse(null));
    }
    return updateWithoutChecks(id, resource);
}
Also used : ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) MultiJobFieldModel(com.synopsys.integration.alert.common.rest.model.MultiJobFieldModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 92 with ActionResponse

use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.

the class AbstractJobResourceActions method getOne.

public final ActionResponse<JobFieldModel> getOne(UUID id) {
    Set<String> descriptorNames = getDescriptorNames();
    if (!authorizationManager.anyReadPermission(List.of(ConfigContextEnum.DISTRIBUTION), descriptorNames)) {
        return ActionResponse.createForbiddenResponse();
    }
    Optional<JobFieldModel> optionalModel = findJobFieldModel(id);
    if (optionalModel.isPresent()) {
        JobFieldModel fieldModel = optionalModel.get();
        boolean hasPermissions = hasRequiredPermissions(fieldModel.getFieldModels(), authorizationManager::hasReadPermission);
        if (!hasPermissions) {
            return ActionResponse.createForbiddenResponse();
        }
        return new ActionResponse<>(HttpStatus.OK, fieldModel);
    }
    return new ActionResponse<>(HttpStatus.NOT_FOUND);
}
Also used : JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) MultiJobFieldModel(com.synopsys.integration.alert.common.rest.model.MultiJobFieldModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 93 with ActionResponse

use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.

the class AbstractJobResourceActions method delete.

public final ActionResponse<JobFieldModel> delete(UUID id) {
    Optional<JobFieldModel> optionalModel = findJobFieldModel(id);
    if (optionalModel.isPresent()) {
        JobFieldModel jobFieldModel = optionalModel.get();
        boolean hasPermissions = hasRequiredPermissions(jobFieldModel.getFieldModels(), authorizationManager::hasDeletePermission);
        if (!hasPermissions) {
            return ActionResponse.createForbiddenResponse();
        }
    } else {
        return new ActionResponse<>(HttpStatus.NOT_FOUND);
    }
    return deleteWithoutChecks(id);
}
Also used : JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) MultiJobFieldModel(com.synopsys.integration.alert.common.rest.model.MultiJobFieldModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 94 with ActionResponse

use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.

the class ConfigurationCrudHelper method update.

public <T extends Obfuscated<T>> ActionResponse<T> update(Supplier<ValidationResponseModel> validator, BooleanSupplier existingModelSupplier, ThrowingSupplier<T, AlertConfigurationException> updateFunction) {
    String actionName = "update";
    logger.trace(ACTION_CALLED_TEMPLATE, descriptorKey.getUniversalKey(), actionName);
    if (!authorizationManager.hasWritePermission(context, descriptorKey)) {
        logger.trace(ACTION_MISSING_PERMISSIONS_TEMPLATE, descriptorKey.getUniversalKey(), actionName);
        return ActionResponse.createForbiddenResponse();
    }
    boolean configurationExists = existingModelSupplier.getAsBoolean();
    if (!configurationExists) {
        logger.trace(ACTION_NOT_FOUND_TEMPLATE, descriptorKey.getUniversalKey(), actionName);
        return new ActionResponse<>(HttpStatus.NOT_FOUND);
    }
    ValidationResponseModel validationResponse = validator.get();
    if (validationResponse.hasErrors()) {
        logger.trace(ACTION_BAD_REQUEST_TEMPLATE, descriptorKey.getUniversalKey(), actionName);
        return new ActionResponse<>(HttpStatus.BAD_REQUEST, validationResponse.getMessage());
    }
    try {
        return new ActionResponse<>(HttpStatus.OK, updateFunction.get().obfuscate());
    } catch (AlertConfigurationException ex) {
        logger.trace(ACTION_BAD_REQUEST_TEMPLATE, descriptorKey.getUniversalKey(), actionName);
        return new ActionResponse<>(HttpStatus.BAD_REQUEST, String.format("Error updating config: %s", ex.getMessage()));
    } catch (Exception ex) {
        logger.error("Error updating config:", ex);
        return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, String.format("Error updating config: %s", ex.getMessage()));
    } finally {
        logger.trace(ACTION_SUCCESS_TEMPLATE, descriptorKey.getUniversalKey(), actionName);
    }
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Example 95 with ActionResponse

use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.

the class AbstractUploadAction method uploadFileExists.

public ActionResponse<ExistenceModel> uploadFileExists() {
    if (isTargetUndefined()) {
        return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, META_DATA_MISSING);
    }
    if (!authorizationManager.hasUploadReadPermission(target.getContext(), target.getDescriptorKey())) {
        return new ActionResponse<>(HttpStatus.FORBIDDEN, ActionResponse.FORBIDDEN_MESSAGE);
    }
    String targetFilename = target.getFilename();
    Boolean exists = filePersistenceUtil.uploadFileExists(targetFilename);
    ExistenceModel content = new ExistenceModel(exists);
    return new ActionResponse<>(HttpStatus.OK, content);
}
Also used : ExistenceModel(com.synopsys.integration.alert.common.rest.model.ExistenceModel) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Aggregations

ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)132 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)46 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)40 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)38 PermissionMatrixModel (com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel)34 PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)32 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)30 ChannelKey (com.synopsys.integration.alert.descriptor.api.model.ChannelKey)30 AuthenticationTestUtils (com.synopsys.integration.alert.test.common.AuthenticationTestUtils)30 Test (org.junit.jupiter.api.Test)30 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)24 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)16 JobFieldModel (com.synopsys.integration.alert.common.rest.model.JobFieldModel)16 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)12 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)10 Collection (java.util.Collection)10 Optional (java.util.Optional)10 Set (java.util.Set)10 Collectors (java.util.stream.Collectors)10 Autowired (org.springframework.beans.factory.annotation.Autowired)10