Search in sources :

Example 1 with Recommendation

use of com.blackducksoftware.integration.fortify.hub.model.Recommendation in project hub-fortify-ssc-integration-service by blackducksoftware.

the class VulnerabilityUtil method transformMapping.

/**
 * It will convert Hub Component view to CSV Vulnerability view
 *
 * @param vulnerabilityComponentViews
 * @param hubProjectName
 * @param hubProjectVersion
 * @return List<Vulnerability>
 */
public static List<Vulnerability> transformMapping(final HubServices hubServices, final List<VulnerableComponentView> vulnerabilityComponentViews, final String hubProjectName, final String hubProjectVersion, final Date maxBomUpdatedDate, final PropertyConstants propertyConstants) throws IntegrationException {
    final List<Vulnerability> vulnerabilities = new ArrayList<>();
    final Map<String, Recommendation> recommendations = new HashMap<>();
    for (final VulnerableComponentView vulnerableComponentView : vulnerabilityComponentViews) {
        final String remediatingUrl = vulnerableComponentView.componentVersion + "/remediating";
        Recommendation recommendation = null;
        if (recommendations.containsKey(remediatingUrl)) {
            recommendation = recommendations.get(remediatingUrl);
        } else {
            recommendation = hubServices.getComponentVersionRecommendations(remediatingUrl);
            recommendations.put(remediatingUrl, recommendation);
        }
        final String[] componentVersionLinkArr = vulnerableComponentView.componentVersion.split("/");
        final Vulnerability vulnerability = new Vulnerability(String.valueOf(hubProjectName), String.valueOf(hubProjectVersion), String.valueOf(componentVersionLinkArr[5]), String.valueOf(componentVersionLinkArr[7]), "", String.valueOf(vulnerableComponentView.componentName), String.valueOf(vulnerableComponentView.componentVersionName), String.valueOf(vulnerableComponentView.componentVersionOriginName), String.valueOf(vulnerableComponentView.componentVersionOriginId), String.valueOf(vulnerableComponentView.componentVersionName), String.valueOf(vulnerableComponentView.vulnerabilityWithRemediation.vulnerabilityName), String.valueOf(vulnerableComponentView.vulnerabilityWithRemediation.description.replaceAll("\\r\\n", "")), vulnerableComponentView.vulnerabilityWithRemediation.vulnerabilityPublishedDate, vulnerableComponentView.vulnerabilityWithRemediation.vulnerabilityUpdatedDate, vulnerableComponentView.vulnerabilityWithRemediation.baseScore, vulnerableComponentView.vulnerabilityWithRemediation.exploitabilitySubscore, vulnerableComponentView.vulnerabilityWithRemediation.impactSubscore, String.valueOf(vulnerableComponentView.vulnerabilityWithRemediation.source.toString()), propertyConstants.getHubServerUrl() + "/api/vulnerabilities/" + String.valueOf(vulnerableComponentView.vulnerabilityWithRemediation.vulnerabilityName), String.valueOf(vulnerableComponentView.vulnerabilityWithRemediation.remediationStatus.toString()), vulnerableComponentView.vulnerabilityWithRemediation.remediationTargetAt, vulnerableComponentView.vulnerabilityWithRemediation.remediationActualAt, String.valueOf(""), VulnerabilityWithRemediationSourceType.NVD.equals(vulnerableComponentView.vulnerabilityWithRemediation.source) ? "http://web.nvd.nist.gov/view/vuln/detail?vulnId=" + vulnerableComponentView.vulnerabilityWithRemediation.vulnerabilityName : "", vulnerableComponentView.vulnerabilityWithRemediation.severity != null ? String.valueOf(vulnerableComponentView.vulnerabilityWithRemediation.severity.toString()) : "CRITICAL", recommendation != null && recommendation.getNoVulnerabilities() != null ? recommendation.getNoVulnerabilities().getName() : null, recommendation != null && recommendation.getNoVulnerabilities() != null ? recommendation.getNoVulnerabilities().getReleasedOn() : null, recommendation != null && recommendation.getLatestAfterCurrent() != null ? recommendation.getLatestAfterCurrent().getName() : null, recommendation != null && recommendation.getLatestAfterCurrent() != null ? recommendation.getLatestAfterCurrent().getReleasedOn() : null, maxBomUpdatedDate);
        vulnerabilities.add(vulnerability);
    }
    return vulnerabilities;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Vulnerability(com.blackducksoftware.integration.fortify.batch.model.Vulnerability) Recommendation(com.blackducksoftware.integration.fortify.hub.model.Recommendation) VulnerableComponentView(com.blackducksoftware.integration.hub.api.generated.view.VulnerableComponentView)

Example 2 with Recommendation

use of com.blackducksoftware.integration.fortify.hub.model.Recommendation in project hub-fortify-ssc-integration-service by blackducksoftware.

the class HubServices method getComponentVersionRecommendations.

/**
 * Get the Black Duck component version recommendations for the given component version
 *
 * @param componentVersionRemediatingUrl
 * @return
 * @throws IntegrationException
 */
public Recommendation getComponentVersionRecommendations(final String componentVersionRemediatingUrl) throws IntegrationException {
    logger.debug("Getting Black Duck component version remediating");
    Recommendation recommendation = null;
    if (componentVersionRemediatingUrl != null) {
        final HubService hubResponseService = hubServicesFactory.createHubService();
        try {
            recommendation = hubResponseService.getResponse(componentVersionRemediatingUrl, Recommendation.class);
        } catch (final IntegrationException e) {
            if (!e.getMessage().contains("Error: 404 : 404")) {
                throw new IntegrationException(e);
            }
        }
    }
    return recommendation;
}
Also used : HubIntegrationException(com.blackducksoftware.integration.hub.exception.HubIntegrationException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) Recommendation(com.blackducksoftware.integration.fortify.hub.model.Recommendation) HubService(com.blackducksoftware.integration.hub.service.HubService)

Aggregations

Recommendation (com.blackducksoftware.integration.fortify.hub.model.Recommendation)2 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)1 Vulnerability (com.blackducksoftware.integration.fortify.batch.model.Vulnerability)1 VulnerableComponentView (com.blackducksoftware.integration.hub.api.generated.view.VulnerableComponentView)1 HubIntegrationException (com.blackducksoftware.integration.hub.exception.HubIntegrationException)1 HubService (com.blackducksoftware.integration.hub.service.HubService)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1