use of com.synopsys.integration.alert.common.action.ValidationActionResponse in project hub-alert by blackducksoftware.
the class AbstractResourceActions method validate.
public final ValidationActionResponse validate(T resource) {
if (!authorizationManager.hasExecutePermission(context, descriptorKey)) {
logger.debug(String.format(FORBIDDEN_ACTION_FORMAT, "Validate"));
ValidationResponseModel responseModel = ValidationResponseModel.generalError(ActionResponse.FORBIDDEN_MESSAGE);
return new ValidationActionResponse(HttpStatus.FORBIDDEN, responseModel);
}
ValidationActionResponse response = validateWithoutChecks(resource);
return ValidationActionResponse.createOKResponseWithContent(response);
}
use of com.synopsys.integration.alert.common.action.ValidationActionResponse in project hub-alert by blackducksoftware.
the class AbstractResourceActions method test.
public final ValidationActionResponse test(T resource) {
if (!authorizationManager.hasExecutePermission(context, descriptorKey)) {
logger.debug(String.format(FORBIDDEN_ACTION_FORMAT, "Test"));
ValidationResponseModel responseModel = ValidationResponseModel.generalError(ActionResponse.FORBIDDEN_MESSAGE);
return new ValidationActionResponse(HttpStatus.FORBIDDEN, responseModel);
}
ValidationActionResponse validationResponse = validateWithoutChecks(resource);
if (validationResponse.isError()) {
return ValidationActionResponse.createOKResponseWithContent(validationResponse);
}
return testWithoutChecks(resource);
}
use of com.synopsys.integration.alert.common.action.ValidationActionResponse in project hub-alert by blackducksoftware.
the class AbstractResourceActions method update.
public final ActionResponse<T> update(Long id, T resource) {
if (!authorizationManager.hasWritePermission(context, descriptorKey)) {
logger.debug(String.format(FORBIDDEN_ACTION_FORMAT, "Update"));
return ActionResponse.createForbiddenResponse();
}
Optional<T> existingItem = findExisting(id);
if (existingItem.isEmpty()) {
return new ActionResponse<>(HttpStatus.NOT_FOUND);
}
ValidationActionResponse validationResponse = validateWithoutChecks(resource);
if (validationResponse.isError()) {
return new ActionResponse<>(validationResponse.getHttpStatus(), validationResponse.getMessage().orElse(null));
}
return updateWithoutChecks(id, resource);
}
use of com.synopsys.integration.alert.common.action.ValidationActionResponse in project hub-alert by blackducksoftware.
the class AbstractJobResourceActions method create.
public final ActionResponse<JobFieldModel> create(JobFieldModel resource) {
boolean hasPermissions = hasRequiredPermissions(resource.getFieldModels(), authorizationManager::hasCreatePermission);
if (!hasPermissions) {
return ActionResponse.createForbiddenResponse();
}
// Clean input
resource.setJobId(null);
correctProjectsField(resource);
ValidationActionResponse validationResponse = validateWithoutChecks(resource);
if (validationResponse.isError()) {
return new ActionResponse<>(validationResponse.getHttpStatus(), validationResponse.getMessage().orElse(null));
}
return createWithoutChecks(resource);
}
use of com.synopsys.integration.alert.common.action.ValidationActionResponse in project hub-alert by blackducksoftware.
the class AbstractJobResourceActions method validate.
public final ValidationActionResponse validate(JobFieldModel resource) {
boolean hasPermissions = resource.getFieldModels().stream().allMatch(model -> authorizationManager.hasCreatePermission(model.getContext(), model.getDescriptorName()) || authorizationManager.hasWritePermission(model.getContext(), model.getDescriptorName()) || authorizationManager.hasExecutePermission(model.getContext(), model.getDescriptorName()));
if (!hasPermissions) {
ValidationResponseModel responseModel = ValidationResponseModel.generalError(ActionResponse.FORBIDDEN_MESSAGE);
return new ValidationActionResponse(HttpStatus.FORBIDDEN, responseModel);
}
// Clean input
correctProjectsField(resource);
ValidationActionResponse response = validateWithoutChecks(resource);
return ValidationActionResponse.createOKResponseWithContent(response);
}
Aggregations