Search in sources :

Example 61 with ActionResponse

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

the class AuditEntryActions method queryForAuditInfoInJobs.

public ActionResponse<AuditJobStatusesModel> queryForAuditInfoInJobs(JobIdsRequestModel queryRequestModel) {
    if (!authorizationManager.hasReadPermission(ConfigContextEnum.GLOBAL, descriptorKey)) {
        return new ActionResponse<>(HttpStatus.FORBIDDEN, ActionResponse.FORBIDDEN_MESSAGE);
    }
    List<UUID> jobIds = queryRequestModel.getJobIds();
    for (UUID jobId : jobIds) {
        if (null == jobId) {
            return new ActionResponse<>(HttpStatus.BAD_REQUEST, "The field 'jobIds' cannot contain null values");
        }
    }
    List<AuditJobStatusModel> auditJobStatusModels = auditAccessor.findByJobIds(jobIds);
    return new ActionResponse<>(HttpStatus.OK, new AuditJobStatusesModel(auditJobStatusModels));
}
Also used : AuditJobStatusModel(com.synopsys.integration.alert.common.persistence.model.AuditJobStatusModel) UUID(java.util.UUID) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) AuditJobStatusesModel(com.synopsys.integration.alert.common.rest.model.AuditJobStatusesModel)

Example 62 with ActionResponse

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

the class JiraServerCustomFunctionAction method createActionResponse.

@Override
public ActionResponse<String> createActionResponse(FieldModel fieldModel, HttpServletContentWrapper ignoredServletContent) {
    try {
        JiraServerProperties jiraProperties = jiraServerPropertiesFactory.createJiraPropertiesWithJobId(UUID.fromString(fieldModel.getId()));
        JiraServerServiceFactory jiraServicesFactory = jiraProperties.createJiraServicesServerFactory(logger, gson);
        PluginManagerService jiraAppService = jiraServicesFactory.createPluginManagerService();
        try {
            jiraAppService.installMarketplaceServerApp(JiraConstants.JIRA_APP_KEY);
        } catch (IntegrationRestException e) {
            if (RestConstants.NOT_FOUND_404 == e.getHttpStatusCode()) {
                return new ActionResponse<>(HttpStatus.NOT_FOUND, String.format("The marketplace listing of the '%s' app may not support your version of Jira. Please install the app manually or request a compatibility update. Error: %s", JiraConstants.JIRA_ALERT_APP_NAME, e.getMessage()));
            }
            return createBadRequestIntegrationException(e);
        }
        boolean jiraPluginInstalled = JiraPluginCheckUtils.checkIsAppInstalledAndRetryIfNecessary(jiraAppService);
        if (!jiraPluginInstalled) {
            return new ActionResponse<>(HttpStatus.NOT_FOUND, String.format("Unable to confirm Jira server successfully installed the '%s' plugin. Please verify the installation on you Jira server.", JiraConstants.JIRA_ALERT_APP_NAME));
        }
        return new ActionResponse<>(HttpStatus.OK, String.format("Successfully installed the '%s' plugin on Jira server.", JiraConstants.JIRA_ALERT_APP_NAME));
    } catch (IntegrationException e) {
        return createBadRequestIntegrationException(e);
    } catch (InterruptedException e) {
        logger.error("Thread was interrupted while validating Jira plugin installation.", e);
        Thread.currentThread().interrupt();
        return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, String.format("Thread was interrupted while validating Jira '%s' plugin installation: %s", JiraConstants.JIRA_ALERT_APP_NAME, e.getMessage()));
    }
}
Also used : PluginManagerService(com.synopsys.integration.jira.common.rest.service.PluginManagerService) IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) JiraServerServiceFactory(com.synopsys.integration.jira.common.server.service.JiraServerServiceFactory) IntegrationException(com.synopsys.integration.exception.IntegrationException) JiraServerProperties(com.synopsys.integration.alert.channel.jira.server.JiraServerProperties) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 63 with ActionResponse

use of com.synopsys.integration.alert.common.action.ActionResponse in project blackduck-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.api.common.model.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) ActionMessageCreator(com.synopsys.integration.alert.common.action.api.ActionMessageCreator) AuthenticationTypeDetails(com.synopsys.integration.alert.common.persistence.model.AuthenticationTypeDetails) ValidationResponseModel(com.synopsys.integration.alert.api.common.model.ValidationResponseModel) 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 64 with ActionResponse

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

the class RoleActions method updateWithoutChecks.

@Override
protected ActionResponse<RolePermissionModel> updateWithoutChecks(Long id, RolePermissionModel resource) {
    try {
        String roleName = resource.getRoleName();
        Optional<UserRoleModel> existingRole = roleAccessor.getRoles(List.of(id)).stream().findFirst();
        if (existingRole.isPresent()) {
            logger.debug(actionMessageCreator.updateStartMessage("role", existingRole.get().getName()));
            if (!existingRole.get().getName().equals(roleName)) {
                authorizationManager.updateRoleName(id, roleName);
            }
            Set<PermissionModel> permissions = resource.getPermissions();
            PermissionMatrixModel permissionMatrixModel = PermissionModelUtil.convertToPermissionMatrixModel(permissions);
            authorizationManager.updatePermissionsForRole(roleName, permissionMatrixModel);
            logger.debug(actionMessageCreator.updateSuccessMessage("Role", roleName));
            return new ActionResponse<>(HttpStatus.NO_CONTENT);
        }
        logger.warn(actionMessageCreator.updateNotFoundMessage("Role", id));
        return new ActionResponse<>(HttpStatus.NOT_FOUND, "Role not found.");
    } catch (AlertException ex) {
        logger.error(actionMessageCreator.updateErrorMessage("role", resource.getRoleName()));
        return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
    }
}
Also used : PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) 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 65 with ActionResponse

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

the class RoleActions method createWithoutChecks.

@Override
protected ActionResponse<RolePermissionModel> createWithoutChecks(RolePermissionModel resource) {
    String roleName = resource.getRoleName();
    Set<PermissionModel> permissions = resource.getPermissions();
    PermissionMatrixModel permissionMatrixModel = PermissionModelUtil.convertToPermissionMatrixModel(permissions);
    logger.debug(actionMessageCreator.createStartMessage("role", roleName));
    UserRoleModel userRoleModel = authorizationManager.createRoleWithPermissions(roleName, permissionMatrixModel);
    logger.debug(actionMessageCreator.createSuccessMessage("Role", roleName));
    return new ActionResponse<>(HttpStatus.OK, convertDatabaseModelToRestModel(userRoleModel));
}
Also used : PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) 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)

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