Package com.denimgroup.threadfix.data

Examples of com.denimgroup.threadfix.data.ScanCheckResultBean


    public void checkDate(String filePath, Long expectedDate) {

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date(expectedDate));

        ScanCheckResultBean scanCheckResultBean = scanParser.testScan(ScanLocationManager.getRoot() + filePath);
        Calendar testDate = scanCheckResultBean.getTestDate();

        assert testDate != null : "Test date was null for file path " + filePath;

        assert testDate.equals(calendar) :
                "Parsing returned " + getString(testDate) +
View Full Code Here


    @Override
    @Nonnull
    public ScanCheckResultBean checkFile(Integer channelId, String fileName) {
        if (channelId == null || fileName == null) {
            LOG.warn("Scan file checking failed because there was null input.");
            return new ScanCheckResultBean(ScanImportStatus.NULL_INPUT_ERROR);
        }

        if (!ApplicationChannel.matchesFileHandleFormat(fileName)) {
            String message = "Bad file name (" + fileName + ") passed into addFileToQueue. Exiting.";
            LOG.error(message);
            throw new IllegalArgumentException(message);
        }

        ApplicationChannel channel = applicationChannelDao.retrieveById(channelId);

        if (channel == null) {
            LOG.warn("The ApplicationChannel could not be loaded.");
            return new ScanCheckResultBean(ScanImportStatus.OTHER_ERROR);
        }

        ChannelImporter importer = channelImporterFactory.getChannelImporter(channel);

        if (importer == null) {
            LOG.warn("No importer could be loaded for the ApplicationChannel.");
            return new ScanCheckResultBean(ScanImportStatus.OTHER_ERROR);
        }

        importer.setFileName(fileName);

        ScanCheckResultBean result = importer.checkFile();

        if ((!result.getScanCheckResult().equals(ScanImportStatus.SUCCESSFUL_SCAN)
                && !result.getScanCheckResult().equals(ScanImportStatus.EMPTY_SCAN_ERROR))) {
            importer.deleteScanFile();
        }

        Calendar scanQueueDate = applicationChannelDao.getMostRecentQueueScanTime(channel.getId());
   
    if (scanQueueDate != null && result.getTestDate() != null &&
        !result.getTestDate().after(scanQueueDate)) {
      LOG.warn(ScanImportStatus.MORE_RECENT_SCAN_ON_QUEUE.toString());
      return new ScanCheckResultBean(ScanImportStatus.MORE_RECENT_SCAN_ON_QUEUE, result.getTestDate());
    }

    return result;
  }
View Full Code Here

        for (Map.Entry<ScannerType, Collection<String>> entry : FolderMappings.getEntries()) {
            Calendar mostRecent = null;
            for (String file : entry.getValue()) {
                try {
                    ScanCheckResultBean returnBean =
                            threadFixBridge.testScan(entry.getKey(), new File(file));

                    assertTrue("Got null return bean while testing " + file, returnBean != null);
                    assertTrue("Response status wasn't success for file " + file + ", it was " +
                            returnBean.getScanCheckResult(),
                            returnBean.getScanCheckResult() == ScanImportStatus.SUCCESSFUL_SCAN);

                    if (mostRecent == null || mostRecent.before(returnBean.getTestDate())) {
                        mostRecent = returnBean.getTestDate();
                    }
                } catch (ScanFileUnavailableException e) {
                    e.printStackTrace();
                    assertTrue("Response status wasn't success for file " + file +
                            ". Encountered ScanFileUnavailableException.", false);
View Full Code Here

                if (innerEntry.getKey() != outerEntry.getKey()) {

                    for (String file : innerEntry.getValue()) {
                        try {
                            ScanCheckResultBean returnBean =
                                    threadFixBridge.testScan(outerEntry.getKey(), new File(file));

                            assertTrue("Got null return bean while testing " + file, returnBean != null);
                            assertTrue("Response status was success for scanner " + outerEntry.getKey() +
                                            " and file " + file + ".",
                                    returnBean.getScanCheckResult() != ScanImportStatus.SUCCESSFUL_SCAN);

                        } catch (ScanFileUnavailableException | IllegalStateException e) {
                            // This happens sometimes if zip files can't be read properly
                            e.printStackTrace();
                        }
View Full Code Here

        for (int i = 0; i < 20; i++) {
            System.out.print('.');
            for (String file : FolderMappings.getValue(ScannerType.SKIPFISH)) {
                System.out.print('-');
                ScanCheckResultBean returnBean =
                        threadFixBridge.testScan(ScannerType.SKIPFISH, new File(file));

                assertTrue("Got null return bean while testing " + file, returnBean != null);
                assertTrue("Response status wasn't success for file " + file + ", it was " +
                        returnBean.getScanCheckResult(),
                        returnBean.getScanCheckResult() == ScanImportStatus.SUCCESSFUL_SCAN);

                threadFixBridge.getScan(ScannerType.SKIPFISH, new File(file));
            }
        }
    }
View Full Code Here

            return failure(SCAN_TYPE_LOOKUP_FAILED);
        }
   
    String fileName = scanTypeCalculationService.saveFile(myChannelId, file);
   
    ScanCheckResultBean returnValue = scanService.checkFile(myChannelId, fileName);
   
    if (ScanImportStatus.SUCCESSFUL_SCAN == returnValue.getScanCheckResult()) {
      Scan scan = scanMergeService.saveRemoteScanAndRun(myChannelId, fileName);
            return writeSuccessObjectWithView(scan, AllViews.RestViewScan2_1.class);
    } else {
      return failure(returnValue.getScanCheckResult().toString());
    }
  }
View Full Code Here

    Integer myChannelId = scanTypeCalculationService.calculateScanType(taskApp.getId(), file, null);
   
    try {
      String fileName = scanTypeCalculationService.saveFile(myChannelId, file);
     
      ScanCheckResultBean returnValue = scanService.checkFile(myChannelId, fileName);
     
      if (ScanImportStatus.SUCCESSFUL_SCAN == returnValue.getScanCheckResult()) {
        scanMergeService.saveRemoteScanAndRun(myChannelId, fileName);
        //  Scan has been saved. Let's update the ScanQueueTask
        this.scanQueueService.completeTask(scanQueueTaskId);
        log.info("Results from scan queue task: " + myTask.getId() + " saved successfully.");
        return RestResponse.success(myTask);
      } else if (ScanImportStatus.EMPTY_SCAN_ERROR == returnValue.getScanCheckResult()) {
        String message = "Task appeared to complete successfully, but results provided were empty.";
        this.scanQueueService.failTask(scanQueueTaskId, message);
        log.warn("When saving scan queue task: " + myTask.getId() + ": " + message);
        return RestResponse.failure(message);
      } else {
        String message = "Task appeared to complete successfully, but the scan upload attempt returned this message: " + returnValue.getScanCheckResult();
        this.scanQueueService.failTask(scanQueueTaskId, message);
        log.warn("When saving scan queue task: " + myTask.getId() + ": " + message);
        return RestResponse.failure(message);
      }
    } catch (Exception e) {
View Full Code Here

            zipFile = unpackZipStream();
            auditXmlStream = getFileFromZip("audit.xml");
            fvdlInputStream = getFileFromZip("audit.fvdl");

            if (zipFile == null || fvdlInputStream == null)
                return new ScanCheckResultBean(ScanImportStatus.WRONG_FORMAT_ERROR);

            testDate = getTime(auditXmlStream);

            inputStream = fvdlInputStream;
            return testSAXInput(new FortifySAXValidator());
View Full Code Here

    } catch (IOException e) {
      log.error("Problems manipulating input stream and byte array.", e);
    }
   
    if (byteArray == null) {
      return new ScanCheckResultBean(ScanImportStatus.WRONG_FORMAT_ERROR);
    }
   
    String jsonString = new String(byteArray);
   
    // Check the first character to avoid a possible exception
    if (jsonString.trim().startsWith("[")) {
      try {
        JSONArray array = new JSONArray(jsonString);
                done = true;
                log.info("Scan is using the old JSON output format.");
                if (array.length() > 0) {
                    hasFindings = true;
                    JSONObject oneFinding = array.getJSONObject(0);
                    if (oneFinding != null) {
                        correctFormat = oneFinding.get("location") != null &&
                                        oneFinding.get("file") != null &&
                                        oneFinding.get("message") != null &&
                                        oneFinding.get("confidence") != null &&
                                        oneFinding.get("code") != null &&
                                        oneFinding.get("warning_type") != null;
                    }
                }
      } catch (JSONException e) {
        log.warn("Encountered JSONException.", e);
      }
    }
   
    // Output Version 2
    // Check the first character to avoid a possible exception
    if (!done && jsonString.trim().startsWith("{")) {
      try {
        JSONObject object = new JSONObject(jsonString);
                log.info("Scan is using the new JSON output format.");

                testDate = getDate(jsonString);
                hasDate = testDate != null;

                JSONArray array = object.getJSONArray("warnings");

                if (array.length() > 0) {
                    hasFindings = true;
                    JSONObject oneFinding = array.getJSONObject(0);
                    if (oneFinding != null) {
                        correctFormat = oneFinding.get("location") != null &&
                                        oneFinding.get("file") != null &&
                                        oneFinding.get("message") != null &&
                                        oneFinding.get("confidence") != null &&
                                        oneFinding.get("code") != null &&
                                        oneFinding.get("user_input") != null &&
                                        oneFinding.get("line") != null &&
                                        oneFinding.get("warning_type") != null;
                    }
        }
      } catch (JSONException e) {
        log.warn("Encountered JSONException.", e);
      }
    }

    return new ScanCheckResultBean(getTestStatus(), testDate);
  }
View Full Code Here

            ScanImportStatus returnValue = null;

            if (sampleFileInputStream == null) {
                log.error("Sample file input stream was null. Returning null.");
                return new ScanCheckResultBean(ScanImportStatus.WRONG_FORMAT_ERROR);
            }

            List<?> map = getArrayFromSamplesFile(sampleFileInputStream);

            if (map == null) {
                log.error("Map returned from samples file was null. Returning WRONG_FORMAT_ERROR");
                returnValue = ScanImportStatus.WRONG_FORMAT_ERROR;
            }

            if (returnValue == null && map.size() == 0)
                returnValue = ScanImportStatus.EMPTY_SCAN_ERROR;

            if (returnValue == null) {
                checkMap(map);

                if (testDate != null) {
                    returnValue = checkTestDate();
                }
            }

            if (returnValue == null) {
                returnValue = ScanImportStatus.SUCCESSFUL_SCAN;
            }

            return new ScanCheckResultBean(returnValue, testDate);
        } catch (IOException e) {
            log.warn("IOException encountered in SkipfishChannelImporter.", e);
            return new ScanCheckResultBean(ScanImportStatus.CONFIGURATION_ERROR, null);
        } catch (ScanFileUnavailableException e) {
            log.error("Unable to proceed because the scan file wasn't found.", e);
            return new ScanCheckResultBean(ScanImportStatus.NULL_INPUT_ERROR, null);
        } finally {
            deleteZipFile();
        }
  }
View Full Code Here

TOP

Related Classes of com.denimgroup.threadfix.data.ScanCheckResultBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.