Search in sources :

Example 26 with ActionResponse

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

the class PolicyNotificationFilterCustomFunctionAction method createPagedActionResponse.

@Override
public ActionResponse<NotificationFilterModelOptions> createPagedActionResponse(FieldModel fieldModel, HttpServletContentWrapper servletContentWrapper, int pageNumber, int pageSize, String searchTerm) throws IntegrationException {
    Optional<FieldValueModel> fieldValueModel = fieldModel.getFieldValueModel(ProviderDescriptor.KEY_NOTIFICATION_TYPES);
    Collection<String> selectedNotificationTypes = fieldValueModel.map(FieldValueModel::getValues).orElse(List.of());
    int totalPages = 1;
    List<NotificationFilterModel> options = List.of();
    if (isJobFilterableByPolicy(selectedNotificationTypes)) {
        try {
            Optional<BlackDuckServicesFactory> blackDuckServicesFactory = createBlackDuckServicesFactory(fieldModel);
            if (blackDuckServicesFactory.isPresent()) {
                BlackDuckPageResponse<PolicyRuleView> policyRulesPage = retrievePolicyRules(blackDuckServicesFactory.get(), pageNumber, pageSize, searchTerm);
                totalPages = (policyRulesPage.getTotalCount() + (pageSize - 1)) / pageSize;
                options = convertToNotificationFilterModel(policyRulesPage.getItems());
            }
        } catch (IntegrationException e) {
            logger.errorAndDebug("There was an issue communicating with Black Duck. " + e.getMessage(), e);
            throw new AlertException("Unable to communicate with Black Duck.", e);
        }
    }
    NotificationFilterModelOptions notificationFilterModelOptions = new NotificationFilterModelOptions(totalPages, pageNumber, pageSize, options);
    return new ActionResponse<>(HttpStatus.OK, notificationFilterModelOptions);
}
Also used : IntegrationException(com.synopsys.integration.exception.IntegrationException) PolicyRuleView(com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 27 with ActionResponse

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

the class VulnerabilityNotificationFilterCustomFunctionAction method createActionResponse.

@Override
public ActionResponse<LabelValueSelectOptions> createActionResponse(FieldModel fieldModel, HttpServletContentWrapper servletContentWrapper) {
    Optional<FieldValueModel> fieldValueModel = fieldModel.getFieldValueModel(ProviderDescriptor.KEY_NOTIFICATION_TYPES);
    Collection<String> selectedNotificationTypes = fieldValueModel.map(FieldValueModel::getValues).orElse(List.of());
    List<LabelValueSelectOption> options = List.of();
    if (isFilterableVulnerability(selectedNotificationTypes)) {
        options = retrieveBlackDuckVulnerabilityOptions();
    }
    LabelValueSelectOptions optionList = new LabelValueSelectOptions(options);
    return new ActionResponse<>(HttpStatus.OK, optionList);
}
Also used : LabelValueSelectOption(com.synopsys.integration.alert.common.descriptor.config.field.LabelValueSelectOption) LabelValueSelectOptions(com.synopsys.integration.alert.common.descriptor.config.field.LabelValueSelectOptions) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 28 with ActionResponse

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

the class BlackDuckProjectCustomFunctionAction method getBlackDuckProjectsActionResponse.

private ActionResponse<ProviderProjectOptions> getBlackDuckProjectsActionResponse(Long blackDuckGlobalConfigId, int pageNumber, int pageSize, String searchTerm) {
    AlertPagedModel<ProviderProject> providerProjectsPage = providerDataAccessor.getProjectsByProviderConfigId(blackDuckGlobalConfigId, pageNumber, pageSize, searchTerm);
    List<ProviderProjectSelectOption> options = providerProjectsPage.getModels().stream().map(project -> new ProviderProjectSelectOption(project.getName(), project.getHref(), project.getDescription())).collect(Collectors.toList());
    return new ActionResponse<>(HttpStatus.OK, new ProviderProjectOptions(providerProjectsPage.getTotalPages(), providerProjectsPage.getCurrentPage(), providerProjectsPage.getPageSize(), options));
}
Also used : ProviderDataAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) HashSet(java.util.HashSet) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) ProviderDescriptor(com.synopsys.integration.alert.api.provider.ProviderDescriptor) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) BlackDuckPropertiesFactory(com.synopsys.integration.alert.provider.blackduck.factory.BlackDuckPropertiesFactory) BlackDuckApiTokenValidator(com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckApiTokenValidator) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) ResponseStatusException(org.springframework.web.server.ResponseStatusException) Collection(java.util.Collection) ProviderProjectOptions(com.synopsys.integration.alert.common.descriptor.config.field.endpoint.table.model.ProviderProjectOptions) ChannelDescriptor(com.synopsys.integration.alert.common.descriptor.ChannelDescriptor) ProviderProjectSelectOption(com.synopsys.integration.alert.common.descriptor.config.field.endpoint.table.model.ProviderProjectSelectOption) Set(java.util.Set) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel) Collectors(java.util.stream.Collectors) BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) HttpServletContentWrapper(com.synopsys.integration.alert.common.rest.HttpServletContentWrapper) HttpStatus(org.springframework.http.HttpStatus) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) List(java.util.List) Component(org.springframework.stereotype.Component) PagedCustomFunctionAction(com.synopsys.integration.alert.common.action.PagedCustomFunctionAction) Optional(java.util.Optional) ProviderProjectOptions(com.synopsys.integration.alert.common.descriptor.config.field.endpoint.table.model.ProviderProjectOptions) ProviderProjectSelectOption(com.synopsys.integration.alert.common.descriptor.config.field.endpoint.table.model.ProviderProjectSelectOption) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 29 with ActionResponse

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

the class UserActions method updateWithoutChecks.

@Override
protected ActionResponse<UserConfig> updateWithoutChecks(Long id, UserConfig resource) {
    Optional<UserModel> userModel = userAccessor.getUser(id);
    if (userModel.isPresent()) {
        UserModel existingUser = userModel.get();
        boolean passwordMissing = StringUtils.isBlank(resource.getPassword());
        String userName = resource.getUsername();
        String password = passwordMissing ? existingUser.getPassword() : resource.getPassword();
        String emailAddress = resource.getEmailAddress();
        UserModel newUserModel = UserModel.existingUser(existingUser.getId(), userName, password, emailAddress, existingUser.getAuthenticationType(), existingUser.getRoles(), existingUser.isEnabled());
        try {
            logger.debug(actionMessageCreator.updateStartMessage("user", userName));
            userAccessor.updateUser(newUserModel, passwordMissing);
            Set<String> configuredRoleNames = resource.getRoleNames();
            if (null != configuredRoleNames && !configuredRoleNames.isEmpty()) {
                Collection<UserRoleModel> roleNames = roleAccessor.getRoles().stream().filter(role -> configuredRoleNames.contains(role.getName())).collect(Collectors.toList());
                authorizationManager.updateUserRoles(existingUser.getId(), roleNames);
            }
            userSystemValidator.validateDefaultAdminUser(id);
            UserConfig user = userAccessor.getUser(id).map(this::convertDatabaseModelToRestModel).orElse(resource);
            logger.debug(actionMessageCreator.updateSuccessMessage("User", userName));
            return new ActionResponse<>(HttpStatus.NO_CONTENT);
        } catch (AlertException ex) {
            logger.error(actionMessageCreator.updateErrorMessage("User", userName));
            return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
        }
    }
    logger.warn(actionMessageCreator.updateNotFoundMessage("User", id));
    return new ActionResponse<>(HttpStatus.NOT_FOUND);
}
Also used : UserModel(com.synopsys.integration.alert.common.persistence.model.UserModel) UserManagementDescriptorKey(com.synopsys.integration.alert.component.users.UserManagementDescriptorKey) AbstractResourceActions(com.synopsys.integration.alert.common.action.api.AbstractResourceActions) StringUtils(org.apache.commons.lang.StringUtils) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) UserModel(com.synopsys.integration.alert.common.persistence.model.UserModel) Autowired(org.springframework.beans.factory.annotation.Autowired) DefaultUserRole(com.synopsys.integration.alert.common.enumeration.DefaultUserRole) UserSystemValidator(com.synopsys.integration.alert.component.users.UserSystemValidator) ArrayList(java.util.ArrayList) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) AlertLoggerFactory(com.synopsys.integration.alert.common.logging.AlertLoggerFactory) ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) ActionMessageCreator(com.synopsys.integration.alert.common.action.api.ActionMessageCreator) AuthenticationTypeDetails(com.synopsys.integration.alert.common.persistence.model.AuthenticationTypeDetails) UserAccessor(com.synopsys.integration.alert.common.persistence.accessor.UserAccessor) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) Logger(org.slf4j.Logger) Collection(java.util.Collection) Set(java.util.Set) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) Collectors(java.util.stream.Collectors) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) HttpStatus(org.springframework.http.HttpStatus) RoleAccessor(com.synopsys.integration.alert.common.descriptor.accessor.RoleAccessor) List(java.util.List) Component(org.springframework.stereotype.Component) AuthenticationTypeAccessor(com.synopsys.integration.alert.common.persistence.accessor.AuthenticationTypeAccessor) NumberUtils(org.apache.commons.lang3.math.NumberUtils) Optional(java.util.Optional) UserRoleModel(com.synopsys.integration.alert.common.persistence.model.UserRoleModel) Transactional(org.springframework.transaction.annotation.Transactional) UserRoleModel(com.synopsys.integration.alert.common.persistence.model.UserRoleModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 30 with ActionResponse

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

the class UserActions method createWithoutChecks.

@Override
protected ActionResponse<UserConfig> createWithoutChecks(UserConfig resource) {
    try {
        String userName = resource.getUsername();
        String password = resource.getPassword();
        String emailAddress = resource.getEmailAddress();
        logger.debug(actionMessageCreator.createStartMessage("user", userName));
        UserModel userModel = userAccessor.addUser(userName, password, emailAddress);
        Long userId = userModel.getId();
        Set<String> configuredRoleNames = resource.getRoleNames();
        if (null != configuredRoleNames && !configuredRoleNames.isEmpty()) {
            Collection<UserRoleModel> roleNames = roleAccessor.getRoles().stream().filter(role -> configuredRoleNames.contains(role.getName())).collect(Collectors.toList());
            authorizationManager.updateUserRoles(userId, roleNames);
        }
        userModel = userAccessor.getUser(userId).orElse(userModel);
        logger.debug(actionMessageCreator.createSuccessMessage("User", userName));
        return new ActionResponse<>(HttpStatus.CREATED, convertDatabaseModelToRestModel(userModel));
    } catch (AlertException ex) {
        logger.error(actionMessageCreator.createErrorMessage("user", resource.getUsername()));
        return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, String.format("There was an issue creating the user. %s", ex.getMessage()));
    }
}
Also used : UserModel(com.synopsys.integration.alert.common.persistence.model.UserModel) UserManagementDescriptorKey(com.synopsys.integration.alert.component.users.UserManagementDescriptorKey) AbstractResourceActions(com.synopsys.integration.alert.common.action.api.AbstractResourceActions) StringUtils(org.apache.commons.lang.StringUtils) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) UserModel(com.synopsys.integration.alert.common.persistence.model.UserModel) Autowired(org.springframework.beans.factory.annotation.Autowired) DefaultUserRole(com.synopsys.integration.alert.common.enumeration.DefaultUserRole) UserSystemValidator(com.synopsys.integration.alert.component.users.UserSystemValidator) ArrayList(java.util.ArrayList) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) AlertLoggerFactory(com.synopsys.integration.alert.common.logging.AlertLoggerFactory) ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) ActionMessageCreator(com.synopsys.integration.alert.common.action.api.ActionMessageCreator) AuthenticationTypeDetails(com.synopsys.integration.alert.common.persistence.model.AuthenticationTypeDetails) UserAccessor(com.synopsys.integration.alert.common.persistence.accessor.UserAccessor) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) Logger(org.slf4j.Logger) Collection(java.util.Collection) Set(java.util.Set) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) Collectors(java.util.stream.Collectors) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) HttpStatus(org.springframework.http.HttpStatus) RoleAccessor(com.synopsys.integration.alert.common.descriptor.accessor.RoleAccessor) List(java.util.List) Component(org.springframework.stereotype.Component) AuthenticationTypeAccessor(com.synopsys.integration.alert.common.persistence.accessor.AuthenticationTypeAccessor) NumberUtils(org.apache.commons.lang3.math.NumberUtils) Optional(java.util.Optional) UserRoleModel(com.synopsys.integration.alert.common.persistence.model.UserRoleModel) Transactional(org.springframework.transaction.annotation.Transactional) UserRoleModel(com.synopsys.integration.alert.common.persistence.model.UserRoleModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Aggregations

ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)66 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)23 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)20 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)19 PermissionMatrixModel (com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel)17 PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)16 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)15 ChannelKey (com.synopsys.integration.alert.descriptor.api.model.ChannelKey)15 AuthenticationTestUtils (com.synopsys.integration.alert.test.common.AuthenticationTestUtils)15 Test (org.junit.jupiter.api.Test)15 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)12 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)8 JobFieldModel (com.synopsys.integration.alert.common.rest.model.JobFieldModel)8 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)6 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)6 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)5 MultiFieldModel (com.synopsys.integration.alert.common.rest.model.MultiFieldModel)5 Collection (java.util.Collection)5 Optional (java.util.Optional)5 Set (java.util.Set)5