Search in sources :

Example 16 with Vulnerability

use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability in project sw360portal by sw360.

the class VulnerabilityConnector method addOrUpdate.

public VulnerabilityUpdateStatus addOrUpdate(Vulnerability vulnerability, ReleaseVulnerabilityRelation partiallyFilledRelation, VulnerabilityUpdateStatus currentVulnerabilityUpdateStatus) {
    UpdateType updateType = addOrUpdate(vulnerability, partiallyFilledRelation);
    currentVulnerabilityUpdateStatus.getStatusToVulnerabilityIds().get(updateType).add(vulnerability.getExternalId());
    return currentVulnerabilityUpdateStatus;
}
Also used : UpdateType(org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType)

Example 17 with Vulnerability

use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability in project sw360portal by sw360.

the class VulnerabilityConnector method addOrUpdateVulnerabilityAndSetId.

public Map<UpdateType, List<Vulnerability>> addOrUpdateVulnerabilityAndSetId(Vulnerability vulnerability, Map<UpdateType, List<Vulnerability>> statusToVulnerabilities) {
    Vulnerability dbVulnerability = vulnerabilityDatabaseHandler.getByExternalId(Vulnerability.class, vulnerability.getExternalId());
    if (dbVulnerability != null) {
        if (!isMoreRecent(vulnerability, dbVulnerability)) {
            statusToVulnerabilities.get(UpdateType.OLD).add(dbVulnerability);
            return statusToVulnerabilities;
        } else {
            dbVulnerability = VulnerabilityMapper.updateFromVulnerability(dbVulnerability, vulnerability);
            RequestStatus requestStatus = vulnerabilityDatabaseHandler.update(dbVulnerability);
            if (RequestStatus.SUCCESS.equals(requestStatus)) {
                statusToVulnerabilities.get(UpdateType.UPDATED).add(dbVulnerability);
                return statusToVulnerabilities;
            }
        }
    } else {
        RequestStatus requestStatus = vulnerabilityDatabaseHandler.add(vulnerability);
        if (RequestStatus.SUCCESS.equals(requestStatus)) {
            statusToVulnerabilities.get(UpdateType.NEW).add(vulnerability);
            return statusToVulnerabilities;
        }
    }
    statusToVulnerabilities.get(UpdateType.FAILED).add(vulnerability);
    return statusToVulnerabilities;
}
Also used : Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus)

Example 18 with Vulnerability

use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability in project sw360portal by sw360.

the class CveSearchDataToVulnerabilityTranslator method apply.

@Override
public Vulnerability apply(CveSearchData cveSearchData) {
    Vulnerability vulnerability = new Vulnerability().setTitle(cveSearchData.getId()).setCveReferences(getCVEReferencesForCveSearchdata(cveSearchData)).setDescription(cveSearchData.getSummary()).setPublishDate(cveSearchData.getPublished()).setLastExternalUpdate(cveSearchData.getModified()).setReferences(cveSearchData.getReferences()).setExternalId(cveSearchData.getId()).setImpact(cveSearchData.getImpact()).setAccess(cveSearchData.getAccess()).setVulnerableConfiguration(cveSearchData.getVulnerable_configuration()).setCwe(cveSearchData.getCwe()).setCveFurtherMetaDataPerSource(cveSearchData.getMap_cve_all());
    if (cveSearchData.getCvss() != null) {
        vulnerability.setIsSetCvss(true);
        vulnerability.setCvss(cveSearchData.getCvss());
        vulnerability.setCvssTime(cveSearchData.getCvss_time());
    }
    return vulnerability;
}
Also used : Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability)

Example 19 with Vulnerability

use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability in project sw360portal by sw360.

the class VulnerabilityConnectorTest method testAddOrUpdateVulnerabilityAndSetIdNewVulnerability.

@Test
public void testAddOrUpdateVulnerabilityAndSetIdNewVulnerability() throws Exception {
    Vulnerability v1 = new Vulnerability().setId("idv1").setExternalId("eid");
    when(vulnerabilityDatabaseHandler.getByExternalId(Vulnerability.class, "eid")).thenReturn(null);
    when(vulnerabilityDatabaseHandler.add(v1)).thenReturn(RequestStatus.SUCCESS);
    Map<UpdateType, List<Vulnerability>> resultMap = vulnerabilityConnector.addOrUpdateVulnerabilityAndSetId(v1, statusToVulnerabilityMap);
    assertThat(resultMap.get(UpdateType.NEW).get(0).getId(), is("idv1"));
    assertThat(resultMap.get(UpdateType.OLD), is(Collections.EMPTY_LIST));
    assertThat(resultMap.get(UpdateType.UPDATED), is(Collections.EMPTY_LIST));
    assertThat(resultMap.get(UpdateType.FAILED), is(Collections.EMPTY_LIST));
}
Also used : Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability) UpdateType(org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType) Test(org.junit.Test)

Example 20 with Vulnerability

use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability in project sw360portal by sw360.

the class VulnerabilityConnectorTest method testAddOrUpdateVulnerabilityAndSetIdFailUpdate.

@Test
public void testAddOrUpdateVulnerabilityAndSetIdFailUpdate() throws Exception {
    Vulnerability v2 = new Vulnerability().setLastExternalUpdate("2000-01-01").setId("idv2").setExternalId("eid");
    when(vulnerabilityDatabaseHandler.getByExternalId(Vulnerability.class, "eid")).thenReturn(null);
    when(vulnerabilityDatabaseHandler.add(v2)).thenReturn(RequestStatus.FAILURE);
    Map<UpdateType, List<Vulnerability>> resultMap = vulnerabilityConnector.addOrUpdateVulnerabilityAndSetId(v2, statusToVulnerabilityMap);
    assertThat(resultMap.get(UpdateType.FAILED).get(0).getId(), is("idv2"));
    assertThat(resultMap.get(UpdateType.NEW), is(Collections.EMPTY_LIST));
    assertThat(resultMap.get(UpdateType.OLD), is(Collections.EMPTY_LIST));
    assertThat(resultMap.get(UpdateType.UPDATED), is(Collections.EMPTY_LIST));
}
Also used : Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability) UpdateType(org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType) Test(org.junit.Test)

Aggregations

Vulnerability (org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability)28 Test (org.junit.Test)15 UpdateType (org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType)10 User (org.eclipse.sw360.datahandler.thrift.users.User)8 TException (org.apache.thrift.TException)6 VulnerabilityService (org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityService)5 ReleaseVulnerabilityRelation (org.eclipse.sw360.datahandler.thrift.vulnerabilities.ReleaseVulnerabilityRelation)4 JSONObject (com.liferay.portal.kernel.json.JSONObject)3 PrintWriter (java.io.PrintWriter)3 VulnerabilityUpdateStatus (org.eclipse.sw360.datahandler.thrift.cvesearch.VulnerabilityUpdateStatus)3 Before (org.junit.Before)3 IOException (java.io.IOException)2 java.util (java.util)2 ArrayList (java.util.ArrayList)2 Collectors (java.util.stream.Collectors)2 CommonUtils (org.eclipse.sw360.datahandler.common.CommonUtils)2 PortletUtils.getVerificationState (org.eclipse.sw360.portal.common.PortletUtils.getVerificationState)2 ResponseEntity (org.springframework.http.ResponseEntity)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1