Search in sources :

Example 1 with VulnerabilityDTO

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

the class VulnerabilityDTOResourceProcessor method process.

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

Example 2 with VulnerabilityDTO

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

the class ProjectController method getVulnerabilitiesOfReleases.

@RequestMapping(value = PROJECTS_URL + "/{id}/vulnerabilities", method = RequestMethod.GET)
public ResponseEntity<Resources<Resource<VulnerabilityDTO>>> getVulnerabilitiesOfReleases(@PathVariable("id") String id, OAuth2Authentication oAuth2Authentication) {
    final User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
    final List<VulnerabilityDTO> allVulnerabilityDTOs = vulnerabilityService.getVulnerabilitiesByProjectId(id, sw360User);
    final List<Resource<VulnerabilityDTO>> vulnerabilityResources = new ArrayList<>();
    for (final VulnerabilityDTO vulnerabilityDTO : allVulnerabilityDTOs) {
        final Resource<VulnerabilityDTO> vulnerabilityDTOResource = new Resource<>(vulnerabilityDTO);
        vulnerabilityResources.add(vulnerabilityDTOResource);
    }
    final Resources<Resource<VulnerabilityDTO>> 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) Resource(org.springframework.hateoas.Resource) HalResource(org.eclipse.sw360.rest.resourceserver.core.HalResource) Resources(org.springframework.hateoas.Resources) VulnerabilityDTO(org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityDTO)

Example 3 with VulnerabilityDTO

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

the class ComponentPortlet method putVulnerabilityMetadatasInRequest.

private void putVulnerabilityMetadatasInRequest(RenderRequest request, List<VulnerabilityDTO> vuls) {
    Map<String, Map<String, String>> vulnerabilityTooltips = new HashMap<>();
    Map<String, Map<String, VerificationState>> vulnerabilityVerifications = new HashMap<>();
    for (VulnerabilityDTO vulnerability : vuls) {
        addToVulnerabilityVerifications(vulnerabilityVerifications, vulnerabilityTooltips, vulnerability);
    }
    long numberOfCorrectVuls = vuls.stream().filter(vul -> !VerificationState.INCORRECT.equals(getVerificationState(vul))).map(vul -> vul.getExternalId()).collect(Collectors.toSet()).size();
    request.setAttribute(NUMBER_OF_CHECKED_OR_UNCHECKED_VULNERABILITIES, numberOfCorrectVuls);
    if (PermissionUtils.isAdmin(UserCacheHolder.getUserFromRequest(request))) {
        long numberOfIncorrectVuls = vuls.stream().filter(v -> VerificationState.INCORRECT.equals(getVerificationState(v))).map(vul -> vul.getExternalId()).collect(Collectors.toSet()).size();
        request.setAttribute(NUMBER_OF_INCORRECT_VULNERABILITIES, numberOfIncorrectVuls);
    }
    request.setAttribute(PortalConstants.VULNERABILITY_VERIFICATIONS, vulnerabilityVerifications);
    request.setAttribute(PortalConstants.VULNERABILITY_VERIFICATION_TOOLTIPS, vulnerabilityTooltips);
}
Also used : SW360Constants(org.eclipse.sw360.datahandler.common.SW360Constants) ContentTypes(com.liferay.portal.kernel.util.ContentTypes) PortletURLFactoryUtil(com.liferay.portlet.PortletURLFactoryUtil) User(org.eclipse.sw360.datahandler.thrift.users.User) TSimpleJSONProtocol(org.apache.thrift.protocol.TSimpleJSONProtocol) WebKeys(com.liferay.portal.kernel.util.WebKeys) TSerializer(org.apache.thrift.TSerializer) PortalUtil(com.liferay.portal.util.PortalUtil) Logger(org.apache.log4j.Logger) SW360Utils.printName(org.eclipse.sw360.datahandler.common.SW360Utils.printName) CONTENT_TYPE_OPENXML_SPREADSHEET(org.eclipse.sw360.datahandler.common.SW360Constants.CONTENT_TYPE_OPENXML_SPREADSHEET) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) ThriftEnumUtils(org.eclipse.sw360.datahandler.common.ThriftEnumUtils) VulnerabilityDTO(org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityDTO) LifeRayUserSession(org.eclipse.sw360.portal.users.LifeRayUserSession) Project(org.eclipse.sw360.datahandler.thrift.projects.Project) Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability) PrintWriter(java.io.PrintWriter) CveSearchService(org.eclipse.sw360.datahandler.thrift.cvesearch.CveSearchService) ComponentExporter(org.eclipse.sw360.exporter.ComponentExporter) UserGroup(org.eclipse.sw360.datahandler.thrift.users.UserGroup) PermissionUtils(org.eclipse.sw360.datahandler.permissions.PermissionUtils) org.eclipse.sw360.portal.common(org.eclipse.sw360.portal.common) VulnerabilityUpdateStatus(org.eclipse.sw360.datahandler.thrift.cvesearch.VulnerabilityUpdateStatus) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay) CommonUtils(org.eclipse.sw360.datahandler.common.CommonUtils) VendorService(org.eclipse.sw360.datahandler.thrift.vendors.VendorService) ReleaseVulnerabilityRelation(org.eclipse.sw360.datahandler.thrift.vulnerabilities.ReleaseVulnerabilityRelation) VulnerabilityService(org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityService) org.eclipse.sw360.datahandler.thrift.components(org.eclipse.sw360.datahandler.thrift.components) LiferayPortletURL(com.liferay.portal.kernel.portlet.LiferayPortletURL) java.util(java.util) Strings.nullToEmpty(com.google.common.base.Strings.nullToEmpty) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) PortletResponseUtil(com.liferay.portal.kernel.portlet.PortletResponseUtil) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) ProjectService(org.eclipse.sw360.datahandler.thrift.projects.ProjectService) org.eclipse.sw360.datahandler.thrift(org.eclipse.sw360.datahandler.thrift) ImmutableList(com.google.common.collect.ImmutableList) SessionMessages(com.liferay.portal.kernel.servlet.SessionMessages) PortletUtils.getVerificationState(org.eclipse.sw360.portal.common.PortletUtils.getVerificationState) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) javax.portlet(javax.portlet) SW360Utils(org.eclipse.sw360.datahandler.common.SW360Utils) RequestedAction(org.eclipse.sw360.datahandler.thrift.users.RequestedAction) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor) HttpServletResponse(javax.servlet.http.HttpServletResponse) TException(org.apache.thrift.TException) JSONFactoryUtil(com.liferay.portal.kernel.json.JSONFactoryUtil) IOException(java.io.IOException) JSONObject(com.liferay.portal.kernel.json.JSONObject) FossologyAwarePortlet(org.eclipse.sw360.portal.portlets.FossologyAwarePortlet) JsonFactory(com.fasterxml.jackson.core.JsonFactory) UserCacheHolder(org.eclipse.sw360.portal.users.UserCacheHolder) PortalConstants(org.eclipse.sw360.portal.common.PortalConstants) VulnerabilityDTO(org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityDTO)

Example 4 with VulnerabilityDTO

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

the class ComponentPortlet method addToVulnerabilityVerifications.

private void addToVulnerabilityVerifications(Map<String, Map<String, VerificationState>> vulnerabilityVerifications, Map<String, Map<String, String>> vulnerabilityTooltips, VulnerabilityDTO vulnerability) {
    String vulnerabilityId = vulnerability.getExternalId();
    String releaseId = vulnerability.getIntReleaseId();
    Map<String, VerificationState> vulnerabilityVerification = vulnerabilityVerifications.computeIfAbsent(vulnerabilityId, k -> new HashMap<>());
    Map<String, String> vulnerabilityTooltip = vulnerabilityTooltips.computeIfAbsent(vulnerabilityId, k -> new HashMap<>());
    ReleaseVulnerabilityRelation relation = vulnerability.getReleaseVulnerabilityRelation();
    if (!relation.isSetVerificationStateInfo()) {
        vulnerabilityVerification.put(releaseId, VerificationState.NOT_CHECKED);
        vulnerabilityTooltip.put(releaseId, "Not checked yet.");
    } else {
        List<VerificationStateInfo> infoHistory = relation.getVerificationStateInfo();
        VerificationStateInfo info = infoHistory.get(infoHistory.size() - 1);
        vulnerabilityVerification.put(releaseId, info.getVerificationState());
        vulnerabilityTooltip.put(releaseId, formatedMessageForVul(infoHistory));
    }
}
Also used : ReleaseVulnerabilityRelation(org.eclipse.sw360.datahandler.thrift.vulnerabilities.ReleaseVulnerabilityRelation) PortletUtils.getVerificationState(org.eclipse.sw360.portal.common.PortletUtils.getVerificationState)

Example 5 with VulnerabilityDTO

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

the class VulnerabilityHandler method enrichVulnerabilityDTO.

private VulnerabilityDTO enrichVulnerabilityDTO(VulnerabilityDTO dto, LoadingCache<String, Component> componentCache, LoadingCache<String, Release> releaseCache) {
    String releaseId = dto.getIntReleaseId();
    try {
        Release release = releaseCache.get(releaseId);
        if (release != null) {
            dto.setIntComponentId(release.getComponentId());
            String releaseName = "";
            if (!StringUtils.isEmpty(release.getName())) {
                releaseName = release.getName() + " ";
                dto.setIntComponentName(release.getName());
            } else {
                Component component = componentCache.get(release.getComponentId());
                if (component != null) {
                    releaseName = component.getName() + " ";
                    dto.setIntComponentName(component.getName());
                }
            }
            dto.setIntReleaseName(releaseName + release.getVersion());
        }
    } catch (ExecutionException e) {
        log.error(e);
    }
    return dto;
}
Also used : Component(org.eclipse.sw360.datahandler.thrift.components.Component) ExecutionException(java.util.concurrent.ExecutionException) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Aggregations

ReleaseVulnerabilityRelation (org.eclipse.sw360.datahandler.thrift.vulnerabilities.ReleaseVulnerabilityRelation)2 VulnerabilityDTO (org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityDTO)2 PortletUtils.getVerificationState (org.eclipse.sw360.portal.common.PortletUtils.getVerificationState)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)1 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 Strings.nullToEmpty (com.google.common.base.Strings.nullToEmpty)1 ImmutableList (com.google.common.collect.ImmutableList)1 Sets (com.google.common.collect.Sets)1 JSONFactoryUtil (com.liferay.portal.kernel.json.JSONFactoryUtil)1 JSONObject (com.liferay.portal.kernel.json.JSONObject)1 LiferayPortletURL (com.liferay.portal.kernel.portlet.LiferayPortletURL)1 PortletResponseUtil (com.liferay.portal.kernel.portlet.PortletResponseUtil)1 SessionMessages (com.liferay.portal.kernel.servlet.SessionMessages)1 ContentTypes (com.liferay.portal.kernel.util.ContentTypes)1 WebKeys (com.liferay.portal.kernel.util.WebKeys)1 ThemeDisplay (com.liferay.portal.theme.ThemeDisplay)1 PortalUtil (com.liferay.portal.util.PortalUtil)1