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);
}
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;
}
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);
}
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);
}
}
}
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);
}
Aggregations