Search in sources :

Example 31 with Vulnerability

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

the class VulnerabilityController method getVulnerabilities.

@RequestMapping(value = VULNERABILITIES_URL)
public ResponseEntity<Resources<Resource<Vulnerability>>> getVulnerabilities(OAuth2Authentication oAuth2Authentication) {
    User user = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
    List<Vulnerability> vulnerabilities = vulnerabilityService.getVulnerabilities(user);
    List<Resource<Vulnerability>> vulnerabilityResources = new ArrayList<>();
    for (Vulnerability vulnerability : vulnerabilities) {
        vulnerability.setCwe(null);
        vulnerability.setId(null);
        vulnerability.setExternalId(null);
        Resource<Vulnerability> vulnerabilityResource = new Resource<>(vulnerability);
        vulnerabilityResources.add(vulnerabilityResource);
    }
    Resources<Resource<Vulnerability>> resources = new Resources<>(vulnerabilityResources);
    return new ResponseEntity<>(resources, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) User(org.eclipse.sw360.datahandler.thrift.users.User) RepositoryLinksResource(org.springframework.data.rest.webmvc.RepositoryLinksResource) HalResource(org.eclipse.sw360.rest.resourceserver.core.HalResource) Resource(org.springframework.hateoas.Resource) ArrayList(java.util.ArrayList) Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability) Resources(org.springframework.hateoas.Resources) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 32 with Vulnerability

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

the class VulnerabilityResourceProcessor method process.

@Override
public Resource process(Resource<Vulnerability> resource) {
    Vulnerability vulnerability = resource.getContent();
    Link selfLink = linkTo(VulnerabilityController.class).slash("api" + VulnerabilityController.VULNERABILITIES_URL + "/" + vulnerability.getExternalId()).withSelfRel();
    resource.add(selfLink);
    return resource;
}
Also used : Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability) Link(org.springframework.hateoas.Link)

Example 33 with Vulnerability

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

the class VulnerabilitiesPortlet method getFilteredVulnerabilityList.

private void getFilteredVulnerabilityList(PortletRequest request) throws IOException {
    List<Vulnerability> vulnerabilities = Collections.emptyList();
    int totalRows = 0;
    String externalId = request.getParameter(EXTERNAL_ID);
    String vulnerableConfig = request.getParameter(VULNERABLE_CONFIGURATION);
    try {
        final User user = UserCacheHolder.getUserFromRequest(request);
        int limit = CustomFieldHelper.loadAndStoreStickyViewSize(request, user, CUSTOM_FIELD_VULNERABILITIES_VIEW_SIZE);
        VulnerabilityService.Iface vulnerabilityClient = thriftClients.makeVulnerabilityClient();
        if (!isNullOrEmpty(externalId) || !isNullOrEmpty(vulnerableConfig)) {
            vulnerabilities = vulnerabilityClient.getVulnerabilitiesByExternalIdOrConfiguration(externalId, vulnerableConfig, user);
            totalRows = vulnerabilities.size();
            if (limit > 0) {
                vulnerabilities = vulnerabilities.stream().limit(limit).collect(Collectors.toList());
            }
        } else {
            vulnerabilities = vulnerabilityClient.getLatestVulnerabilities(user, limit);
            totalRows = vulnerabilityClient.getTotalVulnerabilityCount(user);
        }
    } catch (TException e) {
        log.error("Could not search components in backend ", e);
    }
    shortenTimeStampsToDates(vulnerabilities);
    for (Vulnerability._Fields field : FILTERED_FIELDS) {
        request.setAttribute(field.getFieldName(), nullToEmpty(request.getParameter(field.toString())));
    }
    request.setAttribute(TOTAL_ROWS, totalRows);
    request.setAttribute(VULNERABILITY_LIST, vulnerabilities);
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) VulnerabilityService(org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityService) Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability)

Example 34 with Vulnerability

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

the class VulnerabilitiesPortlet method prepareDetailView.

private void prepareDetailView(RenderRequest request, RenderResponse response) throws IOException, PortletException {
    User user = UserCacheHolder.getUserFromRequest(request);
    String externalId = request.getParameter(VULNERABILITY_ID);
    if (externalId != null) {
        try {
            VulnerabilityService.Iface client = thriftClients.makeVulnerabilityClient();
            VulnerabilityWithReleaseRelations vulnerabilityWithReleaseRelations = client.getVulnerabilityWithReleaseRelationsByExternalId(externalId, user);
            if (vulnerabilityWithReleaseRelations != null) {
                Vulnerability vulnerability = vulnerabilityWithReleaseRelations.getVulnerability();
                List<Release> releases = getReleasesFromRelations(user, vulnerabilityWithReleaseRelations);
                request.setAttribute(VULNERABILITY, vulnerability);
                request.setAttribute(DOCUMENT_ID, externalId);
                request.setAttribute(USING_RELEASES, releases);
                addVulnerabilityBreadcrumb(request, response, vulnerability);
            }
        } catch (TException e) {
            log.error("Error fetching vulnerability from backend!", e);
        }
    }
}
Also used : VulnerabilityWithReleaseRelations(org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityWithReleaseRelations) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) VulnerabilityService(org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityService) Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 35 with Vulnerability

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

the class VulnerabilitySpecTest method before.

@Before
public void before() {
    vulnerability = new Vulnerability();
    vulnerability.setId("12345");
    vulnerability.setAction("new");
    vulnerability.setCwe("common weakness enumeration");
    vulnerability.setDescription("Description of vulnerability");
    vulnerability.setExternalId("123");
    vulnerability.setPriority("high");
    vulnerability.setTitle("Title of vulnerability 12345");
    vulnerability.setRevision("1");
    vulnerability.setCvss(3);
    vulnerability.setReferences(new HashSet<>(Arrays.asList("reference-1", "reference-2")));
    vulnerability.setPublishDate("01-01-2018");
    vulnerability.setLastExternalUpdate("last-update-id-123");
    Vulnerability vulnerability2 = new Vulnerability();
    vulnerability2.setId("7854");
    vulnerability2.setAction("remove");
    vulnerability2.setCwe("common weakness enumeration");
    vulnerability2.setDescription("Description of vulnerability");
    vulnerability2.setExternalId("7543");
    vulnerability2.setPriority("low");
    vulnerability2.setTitle("Title of vulnerability 7854");
    vulnerability2.setRevision("2");
    vulnerability2.setCvss(4);
    List<Vulnerability> vulnerabilityList = new ArrayList<>();
    vulnerabilityList.add(vulnerability);
    vulnerabilityList.add(vulnerability2);
    User user = new User();
    user.setId("admin@sw360.org");
    user.setEmail("admin@sw360.org");
    user.setFullname("John Doe");
    given(this.userServiceMock.getUserByEmail("admin@sw360.org")).willReturn(user);
    given(this.vulnerabilityServiceMock.getVulnerabilities(anyObject())).willReturn(vulnerabilityList);
    given(this.vulnerabilityServiceMock.getVulnerabilityByExternalId(eq(vulnerability.getExternalId()), anyObject())).willReturn(vulnerability);
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) ArrayList(java.util.ArrayList) Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability) Before(org.junit.Before)

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