Search in sources :

Example 11 with ValidationActionResponse

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);
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse)

Example 12 with ValidationActionResponse

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);
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse)

Example 13 with ValidationActionResponse

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);
}
Also used : ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 14 with ValidationActionResponse

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);
}
Also used : ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 15 with ValidationActionResponse

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);
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse)

Aggregations

ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)44 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)33 Test (org.junit.jupiter.api.Test)28 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)15 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)13 AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)10 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)9 PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)9 PermissionMatrixModel (com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel)8 ChannelKey (com.synopsys.integration.alert.descriptor.api.model.ChannelKey)8 AuthenticationTestUtils (com.synopsys.integration.alert.test.common.AuthenticationTestUtils)8 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)7 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)7 AlertFieldException (com.synopsys.integration.alert.common.exception.AlertFieldException)7 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)7 FieldModelTestAction (com.synopsys.integration.alert.common.action.FieldModelTestAction)6 FieldUtility (com.synopsys.integration.alert.common.persistence.accessor.FieldUtility)6 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)6 IntegrationException (com.synopsys.integration.exception.IntegrationException)6 IntegrationRestException (com.synopsys.integration.rest.exception.IntegrationRestException)6