Package com.denimgroup.threadfix.data.entities

Examples of com.denimgroup.threadfix.data.entities.Document


   * @param extension
   * @return
   */
  @Override
  public Document retrieveByAppIdAndFilename(Integer appId, String filename, String extension) {
    Document retVal;
   
    retVal = (Document) sessionFactory
        .getCurrentSession()
        .createQuery(
            "from Document document "
View Full Code Here


            String message = "Bad scanner type of: " + scannerType + " provided. Will not save scan config.";
      log.warn(message);
            return RestResponse.failure(message);
    } else {
      String filename = ScanQueueTask.makeScanAgentConfigFileName(scannerType);
      Document document = this.documentService.saveFileToApp(appId, file, filename);
            String returnedFilename = document == null ? null : document.getName();

      log.debug("Filename of: " + filename + " resulted in final filename of: " + returnedFilename);
            String message = "Scan configuration for scanner: " + scannerType + " saved for appId: " + appId;
      log.info(message);
      return RestResponse.success(message);
View Full Code Here

            return writer.writeValueAsString(RestResponse.failure("File name is too long, max is "
                    + Document.MAX_LENGTH_NAME + " length."));
        }

        try {
            Document document = documentService.saveFileToApp(appId, file);

            if (document == null) {
                log.warn("Saving the file have failed. Returning to file upload page.");
                return writer.writeValueAsString(RestResponse.failure("You don't have permission to upload a document."));
            } else {
View Full Code Here

            return writer.writeValueAsString(RestResponse.failure("File name is too long, max is "
                    + Document.MAX_LENGTH_NAME + " length."));
        }

        try {
            Document document = documentService.saveFileToVuln(vulnId, file);
            if (document == null) {
                log.warn("Saving the document have failed. Returning to file upload page.");
                return writer.writeValueAsString(RestResponse.failure("Unable to save the file to the vulnerability."));
            } else {
                return writer.writeValueAsString(RestResponse.success(document));
View Full Code Here

                                 HttpServletResponse response) throws SQLException, IOException {
        if (!PermissionUtils.isAuthorized(Permission.READ_ACCESS,orgId,appId)){
            return "403";
        }

        Document document = null;
        if (docId != null) {
            document = documentService.loadDocument(docId);
        }

        if (document == null) {
            if (orgId != null && appId != null)
                return "redirect:/organizations/" + orgId + "/applications/" + appId + "/documents";
            else if (orgId != null)
                return "redirect:/organizations/" + orgId;
            else
                return "redirect:/";
        }

        String contentType = document.getContentType();
        response.setContentType(contentType);
        if(contentType.equals(documentService.getContentTypeService().getDefaultType())){
            response.addHeader("Content-Disposition", "attachment; filename=\""+document.getName()+"."+document.getType()+"\"");
            response.setContentType("application/octet-stream");
        }
        response.addHeader("X-Content-Type-Options", "nosniff");
        InputStream in = document.getFile().getBinaryStream();
        ServletOutputStream out = response.getOutputStream();
        IOUtils.copy(in, out);
        in.close();
        out.flush();
        out.close();
View Full Code Here

        if (!PermissionUtils.isAuthorized(Permission.READ_ACCESS,orgId,appId)){
            return "403";
        }

        Document document = null;
        if (docId != null) {
            document = documentService.loadDocument(docId);
        }

        if (document == null) {
            if (orgId != null && appId != null)
                return "redirect:/organizations/" + orgId + "/applications/" + appId + "/documents";
            else if (orgId != null)
                return "redirect:/organizations/" + orgId;
            else
                return "redirect:/";
        }
        response.setHeader("Content-Disposition", "attachment; filename=\"" + document.getName()+ "." + document.getType() + "\"");
        response.setContentType(document.getContentType());
        InputStream in = document.getFile().getBinaryStream();
        ServletOutputStream out = response.getOutputStream();
        IOUtils.copy(in, out);
        in.close();
        out.flush();
        out.close();
View Full Code Here

        if (!PermissionUtils.isAuthorized(Permission.CAN_MANAGE_APPLICATIONS,orgId,appId)){
            return writer.writeValueAsString(RestResponse.failure("You don't have permission to delete a document."));
        }

        Document document = null;
        if (docId != null) {
            document = documentService.loadDocument(docId);
        }

        if (document == null) {
            if (orgId != null && appId != null)
                return writer.writeValueAsString(RestResponse.success("Invalid document ID received."));
            else if (orgId != null)
                return "redirect:/organizations/" + orgId;
            else
                return "redirect:/";
        }
        boolean appPage = document.getApplication() != null && document.getApplication().getId() != null;
        boolean vulnPage = document.getVulnerability() != null && document.getVulnerability().getId() != null;

        documentService.deleteDocument(document);

        if (appPage || vulnPage) {
            return writer.writeValueAsString(RestResponse.success("Successfully deleted document."));
View Full Code Here

    if (!contentTypeService.isValidUpload(file.getContentType())){
      log.warn("Invalid filetype for upload: "+file.getContentType());
      return null;
    }
   
    Document doc = new Document();
    String fileFullName;
   
    if(overrideFilename != null) {
      fileFullName = overrideFilename;
    } else {
      fileFullName = file.getOriginalFilename();
    }
    doc.setApplication(application);
    doc.setName(getFileName(fileFullName));
    doc.setType(getFileType(fileFullName));
    if(!doc.getType().equals("json")){
      doc.setContentType(contentTypeService.translateContentType(file.getContentType()))
    }else{
      doc.setContentType(contentTypeService.translateContentType("json"));
    }

    try {
      Blob blob = new SerialBlob(file.getBytes());
      doc.setFile(blob);

      List<Document> appDocs = application.getDocuments();
      if (appDocs == null) {
        appDocs = list();
      }
View Full Code Here

    if (vulnerability == null) {
      log.warn("Unable to retrieve Vulnerability - document save failed.");
      return null;
    }
   
    Document doc = new Document();
    String fileFullName = file.getOriginalFilename();
    doc.setVulnerability(vulnerability);
    doc.setName(getFileName(fileFullName));
    doc.setType(getFileType(fileFullName));
    doc.setContentType(contentTypeService.translateContentType(file.getContentType()));
    try {
      Blob blob = new SerialBlob(file.getBytes());
      doc.setFile(blob);

      List<Document> appDocs = vulnerability.getDocuments();
      if (appDocs == null)
        appDocs = list();
      appDocs.add(doc);
View Full Code Here

TOP

Related Classes of com.denimgroup.threadfix.data.entities.Document

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.