RemoteDocumentValidationService { public WSReportsDTO validateDocument(DataToValidateDTO dataToValidate) { LOG.info("ValidateDocument in process..."); SignedDocumentValidator validator = initValidator(dataToValidate); Reports reports = null; RemoteDocument policy = dataToValidate.getPolicy(); if (policy == null) { reports = validator.validateDocument(); } else { reports = validator.validateDocument(getValidationPolicy(policy)); } WSReportsDTO reportsDTO = new WSReportsDTO(reports.getDiagnosticDataJaxb(), reports.getSimpleReportJaxb(), reports.getDetailedReportJaxb(), reports.getEtsiValidationReportJaxb()); LOG.info("ValidateDocument is finished"); return reportsDTO; }  void setVerifier(CertificateVerifier verifier); WSReportsDTO validateDocument(DataToValidateDTO dataToValidate); List<RemoteDocument> getOriginalDocuments(DataToValidateDTO dataToValidate);  }
@Test public void testWithNoPolicyAndNoOriginalFile() throws Exception { RemoteDocument signedFile = RemoteDocumentConverter.toRemoteDocument(new FileDocument("src/test/resources/xadesLTA.xml")); DataToValidateDTO dto = new DataToValidateDTO(signedFile, (RemoteDocument) null, null); WSReportsDTO result = validationService.validateDocument(dto); validateReports(result); }
@Test public void testWithNoPolicyAndNoOriginalFileAndStrategy() throws Exception { RemoteDocument signedFile = RemoteDocumentConverter.toRemoteDocument(new FileDocument("src/test/resources/xadesLTA.xml")); DataToValidateDTO dto = new DataToValidateDTO(signedFile, (RemoteDocument) null, null); dto.setTokenExtractionStategy(TokenExtractionStategy.EXTRACT_CERTIFICATES_ONLY); WSReportsDTO result = validationService.validateDocument(dto); validateReports(result); }
@Test public void testWithNoPolicyAndOriginalFile() throws Exception { RemoteDocument signedFile = RemoteDocumentConverter.toRemoteDocument(new FileDocument("src/test/resources/xades-detached.xml")); RemoteDocument originalFile = RemoteDocumentConverter.toRemoteDocument(new FileDocument("src/test/resources/sample.png")); DataToValidateDTO dto = new DataToValidateDTO(signedFile, originalFile, null); WSReportsDTO result = validationService.validateDocument(dto); validateReports(result); }
@Test public void testWithNoPolicyAndDigestOriginalFile() throws Exception { RemoteDocument signedFile = RemoteDocumentConverter.toRemoteDocument(new FileDocument("src/test/resources/xades-detached.xml")); FileDocument fileDocument = new FileDocument("src/test/resources/sample.png"); RemoteDocument originalFile = new RemoteDocument(DSSUtils.digest(DigestAlgorithm.SHA256, fileDocument), DigestAlgorithm.SHA256, fileDocument.getName()); DataToValidateDTO dto = new DataToValidateDTO(signedFile, originalFile, null); WSReportsDTO result = validationService.validateDocument(dto); validateReports(result); }
@Test public void testWithPolicyAndOriginalFile() throws Exception { RemoteDocument signedFile = RemoteDocumentConverter.toRemoteDocument(new FileDocument("src/test/resources/xades-detached.xml")); RemoteDocument originalFile = RemoteDocumentConverter.toRemoteDocument(new FileDocument("src/test/resources/sample.png")); RemoteDocument policy = RemoteDocumentConverter.toRemoteDocument(new FileDocument("src/test/resources/constraint.xml")); DataToValidateDTO dto = new DataToValidateDTO(signedFile, originalFile, policy); WSReportsDTO result = validationService.validateDocument(dto); validateReports(result); }
@Test public void testWithPolicyAndNoOriginalFile() throws Exception { RemoteDocument signedFile = RemoteDocumentConverter.toRemoteDocument(new FileDocument("src/test/resources/xades-detached.xml")); RemoteDocument policy = RemoteDocumentConverter.toRemoteDocument(new FileDocument("src/test/resources/constraint.xml")); DataToValidateDTO dto = new DataToValidateDTO(signedFile, (RemoteDocument) null, policy); WSReportsDTO result = validationService.validateDocument(dto); assertNotNull(result.getDiagnosticData()); assertNotNull(result.getDetailedReport()); assertNotNull(result.getSimpleReport()); assertNotNull(result.getValidationReport()); assertEquals(1, result.getSimpleReport().getSignaturesCount()); assertEquals(2, result.getDiagnosticData().getSignatures().get(0).getFoundTimestamps().size()); assertEquals(Indication.INDETERMINATE, result.getSimpleReport().getSignatureOrTimestamp().get(0).getIndication()); Reports reports = new Reports(result.getDiagnosticData(), result.getDetailedReport(), result.getSimpleReport(), result.getValidationReport()); assertNotNull(reports); assertNotNull(reports.getDiagnosticData()); assertNotNull(reports.getDetailedReport()); assertNotNull(reports.getSimpleReport()); DiagnosticData diagnosticData = reports.getDiagnosticData(); SignatureWrapper signature = diagnosticData.getSignatureById(diagnosticData.getFirstSignatureId()); assertNotNull(signature); assertEquals(SignatureLevel.XAdES_BASELINE_LTA, signature.getSignatureFormat()); List<XmlDigestMatcher> digestMatchers = signature.getDigestMatchers(); assertTrue(Utils.isCollectionNotEmpty(digestMatchers)); assertFalse(signature.isBLevelTechnicallyValid()); }