use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability in project sw360portal by sw360.
the class ComponentPortlet method updateVulnerabilityVerification.
private void updateVulnerabilityVerification(ResourceRequest request, ResourceResponse response) throws IOException {
String[] releaseIds = request.getParameterValues(PortalConstants.RELEASE_IDS + "[]");
String[] vulnerabilityIds = request.getParameterValues(PortalConstants.VULNERABILITY_IDS + "[]");
User user = UserCacheHolder.getUserFromRequest(request);
VulnerabilityService.Iface vulClient = thriftClients.makeVulnerabilityClient();
RequestStatus requestStatus = RequestStatus.SUCCESS;
try {
if (vulnerabilityIds.length != releaseIds.length) {
throw new SW360Exception("Length of vulnerabilities (" + vulnerabilityIds.length + ") does not match the length of releases (" + releaseIds.length + ")!");
}
for (int i = 0; i < vulnerabilityIds.length; i++) {
String vulnerabilityId = vulnerabilityIds[i];
String releaseId = releaseIds[i];
Vulnerability dbVulnerability = vulClient.getVulnerabilityByExternalId(vulnerabilityId, user);
ReleaseVulnerabilityRelation dbRelation = vulClient.getRelationByIds(releaseId, dbVulnerability.getId(), user);
ReleaseVulnerabilityRelation resultRelation = ComponentPortletUtils.updateReleaseVulnerabilityRelationFromRequest(dbRelation, request);
requestStatus = vulClient.updateReleaseVulnerabilityRelation(resultRelation, user);
if (requestStatus != RequestStatus.SUCCESS) {
break;
}
}
} catch (TException e) {
log.error("Error updating vulnerability verification in backend.", e);
requestStatus = RequestStatus.FAILURE;
}
JSONObject responseData = JSONFactoryUtil.createJSONObject();
responseData.put(PortalConstants.REQUEST_STATUS, requestStatus.toString());
PrintWriter writer = response.getWriter();
writer.write(responseData.toString());
}
use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability 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);
}
use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability 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));
}
}
use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability in project sw360portal by sw360.
the class CveSearchDataTranslatorTest method testWithApacheData.
@Test
public void testWithApacheData() throws IOException {
List<CveSearchData> cveSearchDatas = new CveSearchApiImpl(host).search("apache", ".*");
List<CveSearchDataTranslator.VulnerabilityWithRelation> vms = cveSearchDatas.stream().map(cveSearchData -> cveSearchDataTranslator.apply(cveSearchData)).collect(Collectors.toList());
assert (vms != null);
List<Vulnerability> vs = vms.stream().map(vm -> vm.vulnerability).collect(Collectors.toList());
assert (vs.size() > 700);
}
use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability in project sw360portal by sw360.
the class VulnerabilityController method getVulnerability.
@RequestMapping(VULNERABILITIES_URL + "/{id}")
public ResponseEntity<HalResource<Vulnerability>> getVulnerability(@PathVariable("id") String id, OAuth2Authentication oAuth2Authentication) {
User user = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
Vulnerability vulnerability = vulnerabilityService.getVulnerabilityByExternalId(id, user);
HalResource<Vulnerability> vulnerabilityHalResource = createHalVulnerability(vulnerability, user);
return new ResponseEntity<>(vulnerabilityHalResource, HttpStatus.OK);
}
Aggregations