List of usage examples for org.apache.commons.codec.digest DigestUtils shaHex
@Deprecated public static String shaHex(String data)
From source file:com.adobe.acs.commons.analysis.jcrchecksum.impl.ChecksumGeneratorImpl.java
/** * Aggregates a set of checksum entries into a single checksum value. * @param checksums the checksums//from w w w. j av a 2s . c o m * @return the checksum value */ protected String aggregateChecksums(final Map<String, String> checksums) { StringBuilder data = new StringBuilder(); for (Map.Entry<String, String> entry : checksums.entrySet()) { data.append(entry.getKey() + "=" + entry.getValue()); } return DigestUtils.shaHex(data.toString()); }
From source file:be.fedict.eid.tsl.tool.TslInternalFrame.java
@Override public void valueChanged(TreeSelectionEvent event) { DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); if (treeNode.isLeaf()) { TrustService trustService = (TrustService) treeNode.getUserObject(); this.serviceName.setText(trustService.getName()); this.serviceType.setText(trustService.getType() .substring(trustService.getType().indexOf("Svctype/") + "Svctype/".length())); this.serviceStatus.setText(trustService.getStatus() .substring(trustService.getStatus().indexOf("Svcstatus/") + "Svcstatus/".length())); X509Certificate certificate = trustService.getServiceDigitalIdentity(); byte[] encodedCertificate; try {//ww w.ja v a 2s .co m encodedCertificate = certificate.getEncoded(); } catch (CertificateEncodingException e) { throw new RuntimeException("cert: " + e.getMessage(), e); } String sha1Thumbprint = DigestUtils.shaHex(encodedCertificate); this.serviceSha1Thumbprint.setText(sha1Thumbprint); String sha256Thumbprint = DigestUtils.sha256Hex(encodedCertificate); this.serviceSha256Thumbprint.setText(sha256Thumbprint); this.validityBegin.setText(certificate.getNotBefore().toString()); this.validityEnd.setText(certificate.getNotAfter().toString()); } else { this.serviceName.setText(""); this.serviceType.setText(""); this.serviceStatus.setText(""); this.serviceSha1Thumbprint.setText(""); this.serviceSha256Thumbprint.setText(""); this.validityBegin.setText(""); this.validityEnd.setText(""); } }
From source file:com.ebay.pulsar.analytics.metricstore.druid.aggregator.AggregatorTest.java
public void testMinAggregator() { String aggregatorName = "MinAggrTest"; String fieldName = "FieldName"; MinAggregator minAggr = new MinAggregator(aggregatorName, fieldName); String fieldNameGot = minAggr.getFieldName(); assertEquals("FieldName must be 'FieldName'", fieldName, fieldNameGot); String aggregatorNameGot = minAggr.getName(); assertEquals("Name must be 'MinAggrTest'", aggregatorName, aggregatorNameGot); byte[] cacheKey = minAggr.cacheKey(); String hashCacheKeyExpected = "261dd9d040a946b9cc554a7150ac3793d2dfa662"; String hashCacheKeyGot = DigestUtils.shaHex(cacheKey); assertEquals("Hash of cacheKey NOT Equals", hashCacheKeyExpected, hashCacheKeyGot); String aggregatorName2 = "MinAggrTest2"; String fieldName2 = "FieldName2"; MinAggregator agg2 = new MinAggregator(aggregatorName2, fieldName2); MinAggregator agg3 = new MinAggregator(null, null); assertTrue(!agg3.equals(agg2));//from ww w . j a v a 2 s .com assertTrue(!agg2.equals(agg3)); MinAggregator agg4 = new MinAggregator(aggregatorName2, null); assertTrue(!agg4.equals(agg2)); assertTrue(!agg4.equals(agg3)); MinAggregator agg5 = new MinAggregator(aggregatorName2, fieldName2); assertTrue(agg5.equals(agg2)); assertTrue(agg2.equals(agg5)); assertTrue(!agg2.equals(new CountAggregator(aggregatorName2))); assertTrue(agg5.hashCode() == agg2.hashCode()); }
From source file:com.adobe.acs.commons.analysis.jcrchecksum.impl.ChecksumGeneratorImplTest.java
@Test public void testGeneratePropertyChecksums() throws RepositoryException, IOException { Node node = session.getRootNode().addNode("page/jcr:content"); node.setProperty("jcr:title", "My Title"); node.setProperty("jcr:description", "This is my test node"); node.setProperty("long", new Long(100)); node.setProperty("double", new Double(99.99)); node.setProperty("boolean", true); node.setProperty("unsorted", new String[] { "woof", "bark", "howl" }); node.setProperty("sorted", new String[] { "yelp", "arf" }); session.save();//from w w w. j a v a 2s.c o m // Expected to be sorted alphabetically String raw = "jcr:content/boolean=" + DigestUtils.shaHex("true") + "jcr:content/double=" + DigestUtils.shaHex("99.99") + "jcr:content/jcr:description=" + DigestUtils.shaHex("This is my test node") + "jcr:content/jcr:primaryType=" + DigestUtils.shaHex("nt:unstructured") + "jcr:content/jcr:title=" + DigestUtils.shaHex("My Title") + "jcr:content/long=" + DigestUtils.shaHex("100") + "jcr:content/sorted=" + DigestUtils.shaHex("yelp") + "," + DigestUtils.shaHex("arf") // This order is dictated by the sorted values of the corresponding hashes + "jcr:content/unsorted=" + DigestUtils.shaHex("howl") + "," + DigestUtils.shaHex("bark") + "," + DigestUtils.shaHex("woof"); String expected = DigestUtils.shaHex(raw); CustomChecksumGeneratorOptions opts = new CustomChecksumGeneratorOptions(); opts.addSortedProperties(new String[] { "sorted" }); String actual = checksumGenerator.generatePropertyChecksums(node.getPath(), node, opts); assertEquals(expected, actual); }
From source file:eu.europa.ec.markt.dss.report.Tsl2PdfExporter.java
/** * Produce a human readable export of the given tsl to the given file. * //from w w w. ja v a2 s. c o m * @param tsl * the TrustServiceList to export * @param pdfFile * the file to generate * @return * @throws IOException */ public void humanReadableExport(final TrustServiceList tsl, final File pdfFile) { Document document = new Document(); OutputStream outputStream; try { outputStream = new FileOutputStream(pdfFile); } catch (FileNotFoundException e) { throw new RuntimeException("file not found: " + pdfFile.getAbsolutePath(), e); } try { final PdfWriter pdfWriter = PdfWriter.getInstance(document, outputStream); pdfWriter.setPDFXConformance(PdfWriter.PDFA1B); // title final EUCountry country = EUCountry.valueOf(tsl.getSchemeTerritory()); final String title = country.getShortSrcLangName() + " (" + country.getShortEnglishName() + "): Trusted List"; Phrase footerPhrase = new Phrase("PDF document generated on " + new Date().toString() + ", page ", headerFooterFont); HeaderFooter footer = new HeaderFooter(footerPhrase, true); document.setFooter(footer); Phrase headerPhrase = new Phrase(title, headerFooterFont); HeaderFooter header = new HeaderFooter(headerPhrase, false); document.setHeader(header); document.open(); addTitle(title, title0Font, Paragraph.ALIGN_CENTER, 0, 20, document); addLongItem("Scheme name", tsl.getSchemeName(), document); addLongItem("Legal Notice", tsl.getLegalNotice(), document); // information table PdfPTable informationTable = createInfoTable(); addItemRow("Scheme territory", tsl.getSchemeTerritory(), informationTable); addItemRow("Scheme status determination approach", substringAfter(tsl.getStatusDeterminationApproach(), "StatusDetn/"), informationTable); final List<String> schemeTypes = new ArrayList<String>(); for (final String schemeType : tsl.getSchemeTypes()) { schemeTypes.add(schemeType); } addItemRow("Scheme type community rules", schemeTypes, informationTable); addItemRow("Issue date", tsl.getListIssueDateTime().toString(), informationTable); addItemRow("Next update", tsl.getNextUpdate().toString(), informationTable); addItemRow("Historical information period", tsl.getHistoricalInformationPeriod().toString() + " days", informationTable); addItemRow("Sequence number", tsl.getSequenceNumber().toString(), informationTable); addItemRow("Scheme information URIs", tsl.getSchemeInformationUris(), informationTable); document.add(informationTable); addTitle("Scheme Operator", title1Font, Paragraph.ALIGN_CENTER, 0, 10, document); informationTable = createInfoTable(); addItemRow("Scheme operator name", tsl.getSchemeOperatorName(), informationTable); PostalAddressType schemeOperatorPostalAddress = tsl.getSchemeOperatorPostalAddress(Locale.ENGLISH); addItemRow("Scheme operator street address", schemeOperatorPostalAddress.getStreetAddress(), informationTable); addItemRow("Scheme operator postal code", schemeOperatorPostalAddress.getPostalCode(), informationTable); addItemRow("Scheme operator locality", schemeOperatorPostalAddress.getLocality(), informationTable); addItemRow("Scheme operator state", schemeOperatorPostalAddress.getStateOrProvince(), informationTable); addItemRow("Scheme operator country", schemeOperatorPostalAddress.getCountryName(), informationTable); List<String> schemeOperatorElectronicAddressess = tsl.getSchemeOperatorElectronicAddresses(); addItemRow("Scheme operator contact", schemeOperatorElectronicAddressess, informationTable); document.add(informationTable); addTitle("Trust Service Providers", title1Font, Paragraph.ALIGN_CENTER, 10, 2, document); List<TrustServiceProvider> trustServiceProviders = tsl.getTrustServiceProviders(); for (TrustServiceProvider trustServiceProvider : trustServiceProviders) { addTitle(trustServiceProvider.getName(), title1Font, Paragraph.ALIGN_LEFT, 10, 2, document); PdfPTable providerTable = createInfoTable(); addItemRow("Service provider trade name", trustServiceProvider.getTradeName(), providerTable); addItemRow("Information URI", trustServiceProvider.getInformationUris(), providerTable); PostalAddressType postalAddress = trustServiceProvider.getPostalAddress(); addItemRow("Service provider street address", postalAddress.getStreetAddress(), providerTable); addItemRow("Service provider postal code", postalAddress.getPostalCode(), providerTable); addItemRow("Service provider locality", postalAddress.getLocality(), providerTable); addItemRow("Service provider state", postalAddress.getStateOrProvince(), providerTable); addItemRow("Service provider country", postalAddress.getCountryName(), providerTable); document.add(providerTable); List<TrustService> trustServices = trustServiceProvider.getTrustServices(); for (TrustService trustService : trustServices) { addTitle(trustService.getName(), title2Font, Paragraph.ALIGN_LEFT, 10, 2, document); PdfPTable serviceTable = createInfoTable(); addItemRow("Type", substringAfter(trustService.getType(), "Svctype/"), serviceTable); addItemRow("Status", substringAfter(trustService.getStatus(), "Svcstatus/"), serviceTable); addItemRow("Status starting time", trustService.getStatusStartingTime().toString(), serviceTable); document.add(serviceTable); addTitle("Service digital identity (X509)", title3Font, Paragraph.ALIGN_LEFT, 2, 0, document); final X509Certificate certificate = trustService.getServiceDigitalIdentity(); final PdfPTable serviceIdentityTable = createInfoTable(); addItemRow("Version", Integer.toString(certificate.getVersion()), serviceIdentityTable); addItemRow("Serial number", certificate.getSerialNumber().toString(), serviceIdentityTable); addItemRow("Signature algorithm", certificate.getSigAlgName(), serviceIdentityTable); addItemRow("Issuer", certificate.getIssuerX500Principal().toString(), serviceIdentityTable); addItemRow("Valid from", certificate.getNotBefore().toString(), serviceIdentityTable); addItemRow("Valid to", certificate.getNotAfter().toString(), serviceIdentityTable); addItemRow("Subject", certificate.getSubjectX500Principal().toString(), serviceIdentityTable); addItemRow("Public key", certificate.getPublicKey().toString(), serviceIdentityTable); // TODO certificate policies addItemRow("Subject key identifier", toHex(getSKId(certificate)), serviceIdentityTable); addItemRow("CRL distribution points", getCrlDistributionPoints(certificate), serviceIdentityTable); addItemRow("Authority key identifier", toHex(getAKId(certificate)), serviceIdentityTable); addItemRow("Key usage", getKeyUsage(certificate), serviceIdentityTable); addItemRow("Basic constraints", getBasicConstraints(certificate), serviceIdentityTable); byte[] encodedCertificate; try { encodedCertificate = certificate.getEncoded(); } catch (CertificateEncodingException e) { throw new RuntimeException("cert: " + e.getMessage(), e); } addItemRow("SHA1 Thumbprint", DigestUtils.shaHex(encodedCertificate), serviceIdentityTable); addItemRow("SHA256 Thumbprint", DigestUtils.sha256Hex(encodedCertificate), serviceIdentityTable); document.add(serviceIdentityTable); List<ExtensionType> extensions = trustService.getExtensions(); for (ExtensionType extension : extensions) { printExtension(extension, document); } addLongMonoItem("The decoded certificate:", certificate.toString(), document); addLongMonoItem("The certificate in PEM format:", toPem(certificate), document); } } X509Certificate signerCertificate = tsl.verifySignature(); if (null != signerCertificate) { Paragraph tslSignerTitle = new Paragraph("Trusted List Signer", title1Font); tslSignerTitle.setAlignment(Paragraph.ALIGN_CENTER); document.add(tslSignerTitle); final PdfPTable signerTable = createInfoTable(); addItemRow("Subject", signerCertificate.getSubjectX500Principal().toString(), signerTable); addItemRow("Issuer", signerCertificate.getIssuerX500Principal().toString(), signerTable); addItemRow("Not before", signerCertificate.getNotBefore().toString(), signerTable); addItemRow("Not after", signerCertificate.getNotAfter().toString(), signerTable); addItemRow("Serial number", signerCertificate.getSerialNumber().toString(), signerTable); addItemRow("Version", Integer.toString(signerCertificate.getVersion()), signerTable); byte[] encodedPublicKey = signerCertificate.getPublicKey().getEncoded(); addItemRow("Public key SHA1 Thumbprint", DigestUtils.shaHex(encodedPublicKey), signerTable); addItemRow("Public key SHA256 Thumbprint", DigestUtils.sha256Hex(encodedPublicKey), signerTable); document.add(signerTable); addLongMonoItem("The decoded certificate:", signerCertificate.toString(), document); addLongMonoItem("The certificate in PEM format:", toPem(signerCertificate), document); addLongMonoItem("The public key in PEM format:", toPem(signerCertificate.getPublicKey()), document); } document.close(); } catch (DocumentException e) { throw new RuntimeException("PDF document error: " + e.getMessage(), e); } catch (Exception e) { throw new RuntimeException("Exception: " + e.getMessage(), e); } }
From source file:eionet.cr.harvest.load.FeedSaver.java
/** * @param person//from w ww.j a v a 2 s . c o m * @param personUri * @throws RepositoryException */ private void saveSyndPerson(SyndPerson person, String personUri) throws RepositoryException { saveResourceTriple(personUri, Predicates.RDF_TYPE, Subjects.FOAF_PERSON_CLASS); String personName = person.getName(); if (StringUtils.isNotBlank(personName)) { saveLiteralTriple(personUri, Predicates.FOAF_NAME, personName); } String personEmail = person.getEmail(); if (StringUtils.isNotBlank(personEmail)) { // From the RSS 2.0 specs it seems we can assume that e-mails are provided implicitly, // so lets make an SHA-1 checksum of them. saveLiteralTriple(personUri, Predicates.FOAF_MBOX_SHA1SUM, DigestUtils.shaHex(personEmail)); } }
From source file:be.fedict.eid.tsl.Tsl2PdfExporter.java
/** * Produce a human readable export of the given tsl to the given file. * // w ww. jav a 2s. c om * @param tsl * the TrustServiceList to export * @param pdfFile * the file to generate * @return * @throws IOException */ public void humanReadableExport(final TrustServiceList tsl, final File pdfFile) { Document document = new Document(); OutputStream outputStream; try { outputStream = new FileOutputStream(pdfFile); } catch (FileNotFoundException e) { throw new RuntimeException("file not found: " + pdfFile.getAbsolutePath(), e); } try { final PdfWriter pdfWriter = PdfWriter.getInstance(document, outputStream); pdfWriter.setPDFXConformance(PdfWriter.PDFA1B); // title final EUCountry country = EUCountry.valueOf(tsl.getSchemeTerritory()); final String title = country.getShortSrcLangName() + " (" + country.getShortEnglishName() + "): Trusted List"; Phrase footerPhrase = new Phrase("PDF document generated on " + new Date().toString() + ", page ", headerFooterFont); HeaderFooter footer = new HeaderFooter(footerPhrase, true); document.setFooter(footer); Phrase headerPhrase = new Phrase(title, headerFooterFont); HeaderFooter header = new HeaderFooter(headerPhrase, false); document.setHeader(header); document.open(); addTitle(title, title0Font, Paragraph.ALIGN_CENTER, 0, 20, document); addLongItem("Scheme name", tsl.getSchemeName(), document); addLongItem("Legal Notice", tsl.getLegalNotice(), document); // information table PdfPTable informationTable = createInfoTable(); addItemRow("Scheme territory", tsl.getSchemeTerritory(), informationTable); addItemRow("Scheme status determination approach", substringAfter(tsl.getStatusDeterminationApproach(), "StatusDetn/"), informationTable); /* final List<String> schemeTypes = new ArrayList<String>(); for (final String schemeType : tsl.getSchemeTypes()) { schemeTypes.add(schemeType); } */ final List<String> schemeTypes = new ArrayList<String>(); List<NonEmptyMultiLangURIType> uris = tsl.getSchemeTypes(); for (NonEmptyMultiLangURIType uri : uris) { schemeTypes.add(uri.getValue()); } addItemRow("Scheme type community rules", schemeTypes, informationTable); addItemRow("Issue date", tsl.getListIssueDateTime().toString(), informationTable); addItemRow("Next update", tsl.getNextUpdate().toString(), informationTable); addItemRow("Historical information period", tsl.getHistoricalInformationPeriod().toString() + " days", informationTable); addItemRow("Sequence number", tsl.getSequenceNumber().toString(), informationTable); addItemRow("Scheme information URIs", tsl.getSchemeInformationUris(), informationTable); document.add(informationTable); addTitle("Scheme Operator", title1Font, Paragraph.ALIGN_CENTER, 0, 10, document); informationTable = createInfoTable(); addItemRow("Scheme operator name", tsl.getSchemeOperatorName(), informationTable); PostalAddressType schemeOperatorPostalAddress = tsl.getSchemeOperatorPostalAddress(Locale.ENGLISH); addItemRow("Scheme operator street address", schemeOperatorPostalAddress.getStreetAddress(), informationTable); addItemRow("Scheme operator postal code", schemeOperatorPostalAddress.getPostalCode(), informationTable); addItemRow("Scheme operator locality", schemeOperatorPostalAddress.getLocality(), informationTable); addItemRow("Scheme operator state", schemeOperatorPostalAddress.getStateOrProvince(), informationTable); addItemRow("Scheme operator country", schemeOperatorPostalAddress.getCountryName(), informationTable); List<String> schemeOperatorElectronicAddressess = tsl.getSchemeOperatorElectronicAddresses(); addItemRow("Scheme operator contact", schemeOperatorElectronicAddressess, informationTable); document.add(informationTable); addTitle("Trust Service Providers", title1Font, Paragraph.ALIGN_CENTER, 10, 2, document); List<TrustServiceProvider> trustServiceProviders = tsl.getTrustServiceProviders(); for (TrustServiceProvider trustServiceProvider : trustServiceProviders) { addTitle(trustServiceProvider.getName(), title1Font, Paragraph.ALIGN_LEFT, 10, 2, document); PdfPTable providerTable = createInfoTable(); addItemRow("Service provider trade name", trustServiceProvider.getTradeNames(), providerTable); addItemRow("Information URI", trustServiceProvider.getInformationUris(), providerTable); PostalAddressType postalAddress = trustServiceProvider.getPostalAddress(); addItemRow("Service provider street address", postalAddress.getStreetAddress(), providerTable); addItemRow("Service provider postal code", postalAddress.getPostalCode(), providerTable); addItemRow("Service provider locality", postalAddress.getLocality(), providerTable); addItemRow("Service provider state", postalAddress.getStateOrProvince(), providerTable); addItemRow("Service provider country", postalAddress.getCountryName(), providerTable); document.add(providerTable); List<TrustService> trustServices = trustServiceProvider.getTrustServices(); for (TrustService trustService : trustServices) { addTitle(trustService.getName(), title2Font, Paragraph.ALIGN_LEFT, 10, 2, document); PdfPTable serviceTable = createInfoTable(); addItemRow("Type", substringAfter(trustService.getType(), "Svctype/"), serviceTable); addItemRow("Status", substringAfter(trustService.getStatus(), "Svcstatus/"), serviceTable); addItemRow("Status starting time", trustService.getStatusStartingTime().toString(), serviceTable); document.add(serviceTable); addTitle("Service digital identity (X509)", title3Font, Paragraph.ALIGN_LEFT, 2, 0, document); final X509Certificate certificate = trustService.getServiceDigitalIdentity(); final PdfPTable serviceIdentityTable = createInfoTable(); addItemRow("Version", Integer.toString(certificate.getVersion()), serviceIdentityTable); addItemRow("Serial number", certificate.getSerialNumber().toString(), serviceIdentityTable); addItemRow("Signature algorithm", certificate.getSigAlgName(), serviceIdentityTable); addItemRow("Issuer", certificate.getIssuerX500Principal().toString(), serviceIdentityTable); addItemRow("Valid from", certificate.getNotBefore().toString(), serviceIdentityTable); addItemRow("Valid to", certificate.getNotAfter().toString(), serviceIdentityTable); addItemRow("Subject", certificate.getSubjectX500Principal().toString(), serviceIdentityTable); addItemRow("Public key", certificate.getPublicKey().toString(), serviceIdentityTable); // TODO certificate policies addItemRow("Subject key identifier", toHex(getSKId(certificate)), serviceIdentityTable); addItemRow("CRL distribution points", getCrlDistributionPoints(certificate), serviceIdentityTable); addItemRow("Authority key identifier", toHex(getAKId(certificate)), serviceIdentityTable); addItemRow("Key usage", getKeyUsage(certificate), serviceIdentityTable); addItemRow("Basic constraints", getBasicConstraints(certificate), serviceIdentityTable); byte[] encodedCertificate; try { encodedCertificate = certificate.getEncoded(); } catch (CertificateEncodingException e) { throw new RuntimeException("cert: " + e.getMessage(), e); } addItemRow("SHA1 Thumbprint", DigestUtils.shaHex(encodedCertificate), serviceIdentityTable); addItemRow("SHA256 Thumbprint", DigestUtils.sha256Hex(encodedCertificate), serviceIdentityTable); document.add(serviceIdentityTable); //add Scheme service definition if (null != trustService.getSchemeServiceDefinitionURI()) { addTitle("Scheme Service Definition URI", title3Font, Paragraph.ALIGN_LEFT, 2, 0, document); final PdfPTable schemeServiceDefinitionURITabel = createInfoTable(); for (NonEmptyMultiLangURIType uri : trustService.getSchemeServiceDefinitionURI().getURI()) { addItemRow(uri.getLang(), uri.getValue(), schemeServiceDefinitionURITabel); } document.add(schemeServiceDefinitionURITabel); } List<ExtensionType> extensions = trustService.getExtensions(); for (ExtensionType extension : extensions) { printExtension(extension, document); } addLongMonoItem("The decoded certificate:", certificate.toString(), document); addLongMonoItem("The certificate in PEM format:", toPem(certificate), document); ServiceHistoryType serviceHistoryType = trustService.getServiceHistoryInstanceType(); if (null != serviceHistoryType) { for (ServiceHistoryInstanceType serviceHistoryInstanceType : serviceHistoryType .getServiceHistoryInstance()) { PdfPTable serviceHistoryTable = createInfoTable(); //Service approval history information addTitle("Service approval history information", title3Font, Paragraph.ALIGN_LEFT, 10, 2, document); // service type identifier //5.6.2 Service name InternationalNamesType i18nServiceName = serviceHistoryInstanceType.getServiceName(); String servName = TrustServiceListUtils.getValue(i18nServiceName, Locale.ENGLISH); addItemRow("Name", servName, serviceHistoryTable); //5.6.1 Service type identifier addItemRow("Type", substringAfter(serviceHistoryInstanceType.getServiceTypeIdentifier(), "Svctype/"), serviceHistoryTable); addItemRow("Status", serviceHistoryInstanceType.getServiceStatus(), serviceHistoryTable); //5.6.4 Service previous status addItemRow("Previous status", serviceHistoryInstanceType.getServiceStatus(), serviceHistoryTable); //5.6.5 Previous status starting date and time addItemRow( "Previous starting time", new DateTime(serviceHistoryInstanceType .getStatusStartingTime().toGregorianCalendar()).toString(), serviceHistoryTable); //5.6.3 Service digital identity final X509Certificate previousCertificate = trustService.getServiceDigitalIdentity( serviceHistoryInstanceType.getServiceDigitalIdentity()); document.add(serviceHistoryTable); addTitle("Service digital identity (X509)", title4Font, Paragraph.ALIGN_LEFT, 2, 0, document); final PdfPTable serviceIdentityTableHistory = createInfoTable(); addItemRow("Version", Integer.toString(previousCertificate.getVersion()), serviceIdentityTableHistory); addItemRow("Serial number", previousCertificate.getSerialNumber().toString(), serviceIdentityTableHistory); addItemRow("Signature algorithm", previousCertificate.getSigAlgName(), serviceIdentityTableHistory); addItemRow("Issuer", previousCertificate.getIssuerX500Principal().toString(), serviceIdentityTableHistory); addItemRow("Valid from", previousCertificate.getNotBefore().toString(), serviceIdentityTableHistory); addItemRow("Valid to", previousCertificate.getNotAfter().toString(), serviceIdentityTableHistory); addItemRow("Subject", previousCertificate.getSubjectX500Principal().toString(), serviceIdentityTableHistory); addItemRow("Public key", previousCertificate.getPublicKey().toString(), serviceIdentityTableHistory); // TODO certificate policies addItemRow("Subject key identifier", toHex(getSKId(previousCertificate)), serviceIdentityTableHistory); addItemRow("CRL distribution points", getCrlDistributionPoints(previousCertificate), serviceIdentityTableHistory); addItemRow("Authority key identifier", toHex(getAKId(previousCertificate)), serviceIdentityTableHistory); addItemRow("Key usage", getKeyUsage(previousCertificate), serviceIdentityTableHistory); addItemRow("Basic constraints", getBasicConstraints(previousCertificate), serviceIdentityTableHistory); byte[] encodedHistoryCertificate; try { encodedHistoryCertificate = previousCertificate.getEncoded(); } catch (CertificateEncodingException e) { throw new RuntimeException("cert: " + e.getMessage(), e); } addItemRow("SHA1 Thumbprint", DigestUtils.shaHex(encodedHistoryCertificate), serviceIdentityTableHistory); addItemRow("SHA256 Thumbprint", DigestUtils.sha256Hex(encodedHistoryCertificate), serviceIdentityTableHistory); document.add(serviceIdentityTableHistory); ExtensionsListType previousExtensions = serviceHistoryInstanceType .getServiceInformationExtensions(); if (null != previousExtensions) { for (ExtensionType extension : previousExtensions.getExtension()) { printExtension(extension, document); } } addLongMonoItem("The decoded certificate:", previousCertificate.toString(), document); addLongMonoItem("The certificate in PEM format:", toPem(previousCertificate), document); } } } } X509Certificate signerCertificate = tsl.verifySignature(); if (null != signerCertificate) { Paragraph tslSignerTitle = new Paragraph("Trusted List Signer", title1Font); tslSignerTitle.setAlignment(Paragraph.ALIGN_CENTER); document.add(tslSignerTitle); final PdfPTable signerTable = createInfoTable(); addItemRow("Subject", signerCertificate.getSubjectX500Principal().toString(), signerTable); addItemRow("Issuer", signerCertificate.getIssuerX500Principal().toString(), signerTable); addItemRow("Not before", signerCertificate.getNotBefore().toString(), signerTable); addItemRow("Not after", signerCertificate.getNotAfter().toString(), signerTable); addItemRow("Serial number", signerCertificate.getSerialNumber().toString(), signerTable); addItemRow("Version", Integer.toString(signerCertificate.getVersion()), signerTable); byte[] encodedPublicKey = signerCertificate.getPublicKey().getEncoded(); addItemRow("Public key SHA1 Thumbprint", DigestUtils.shaHex(encodedPublicKey), signerTable); addItemRow("Public key SHA256 Thumbprint", DigestUtils.sha256Hex(encodedPublicKey), signerTable); document.add(signerTable); addLongMonoItem("The decoded certificate:", signerCertificate.toString(), document); addLongMonoItem("The certificate in PEM format:", toPem(signerCertificate), document); addLongMonoItem("The public key in PEM format:", toPem(signerCertificate.getPublicKey()), document); } document.close(); } catch (DocumentException e) { throw new RuntimeException("PDF document error: " + e.getMessage(), e); } catch (Exception e) { throw new RuntimeException("Exception: " + e.getMessage(), e); } }
From source file:com.ebay.pulsar.analytics.metricstore.druid.query.QueryTest.java
public void testTimeSeriesQuery() { String dataSource = "TimeSeriesQueryTest"; List<String> intervals = getIntervals(); List<BaseAggregator> aggregations = getAggregators(); BaseGranularity granularity = BaseGranularity.ALL; TimeSeriesQuery timeSeriesQuery = new TimeSeriesQuery(dataSource, intervals, granularity, aggregations); String dataSourceGot = timeSeriesQuery.getDataSource(); List<String> intervalsGot = timeSeriesQuery.getIntervals(); timeSeriesQuery.getAggregations();/* ww w . ja v a2 s .com*/ BaseGranularity granularityGot = timeSeriesQuery.getGranularity(); assertEquals("DataSource NOT Equals", dataSource, dataSourceGot); assertEquals("Intervals NOT Equals", intervals.get(0), intervalsGot.get(0)); assertEquals("Granularity NOT Equals", granularity, granularityGot); byte[] cacheKey = timeSeriesQuery.cacheKey(); String hashCacheKeyExpected = "e550ce5f344c44103d79536edc332aff7fda3756"; String hashCacheKeyGot = DigestUtils.shaHex(cacheKey); assertEquals("Hash of cacheKey NOT Equals", hashCacheKeyExpected, hashCacheKeyGot); timeSeriesQuery.toString(); List<BasePostAggregator> postAggregations = getPostAggregators(); timeSeriesQuery.setPostAggregations(postAggregations); cacheKey = timeSeriesQuery.cacheKey(); hashCacheKeyExpected = "0c542f5ea795551b325bf6390a32e8dc3a0be805"; hashCacheKeyGot = DigestUtils.shaHex(cacheKey); assertEquals("Hash of cacheKey NOT Equals", hashCacheKeyExpected, hashCacheKeyGot); PeriodGranularity periodGranularity1 = new PeriodGranularity("P2D"); PeriodGranularity periodGranularity2 = new PeriodGranularity("P2D", "MST"); PeriodGranularity periodGranularity3 = new PeriodGranularity("P2D", "MST", "1970-01-01T00:07:00"); TimeSeriesQuery timeSeriesQueryP1 = new TimeSeriesQuery(dataSource, intervals, periodGranularity1, aggregations); TimeSeriesQuery timeSeriesQueryP2 = new TimeSeriesQuery(dataSource, intervals, periodGranularity2, aggregations); TimeSeriesQuery timeSeriesQueryP3 = new TimeSeriesQuery(dataSource, intervals, periodGranularity3, aggregations); byte[] cacheKey1 = timeSeriesQueryP1.cacheKey(); String hashCacheKeyExpected1 = "ac122b80f8600d94b7ebbf8917bf1c8d70224a12"; String hashCacheKeyGot1 = DigestUtils.shaHex(cacheKey1); assertEquals("Hash of cacheKey NOT Equals", hashCacheKeyExpected1, hashCacheKeyGot1); byte[] cacheKey2 = timeSeriesQueryP2.cacheKey(); String hashCacheKeyExpected2 = "6cc28ac5f7feffa54e2ff949d3d7bf0696c0dd0b"; String hashCacheKeyGot2 = DigestUtils.shaHex(cacheKey2); assertEquals("Hash of cacheKey NOT Equals", hashCacheKeyExpected2, hashCacheKeyGot2); byte[] cacheKey3 = timeSeriesQueryP3.cacheKey(); String hashCacheKeyExpected3 = "e42b59020c77cadb62b75a31c14b62da8aa899dd"; String hashCacheKeyGot3 = DigestUtils.shaHex(cacheKey3); assertEquals("Hash of cacheKey NOT Equals", hashCacheKeyExpected3, hashCacheKeyGot3); QueryType type = timeSeriesQuery.getQueryType(); assertEquals("Type NOT Equals", QueryType.timeseries, type); }
From source file:com.adobe.acs.commons.analysis.jcrchecksum.impl.ChecksumGeneratorImplTest.java
@Test public void testGeneratePropertyChecksums_IgnoreProperties() throws RepositoryException, IOException { Node node = session.getRootNode().addNode("page/jcr:content"); node.setProperty("jcr:title", "My Title"); node.setProperty("jcr:description", "This is my test node"); node.setProperty("long", new Long(100)); node.setProperty("double", new Double(99.99)); node.setProperty("boolean", true); node.setProperty("unsorted", new String[] { "woof", "bark", "howl" }); node.setProperty("sorted", new String[] { "yelp", "arf" }); session.save();//from ww w . ja va 2 s. c o m // Expected to be sorted alphabetically String raw = "jcr:content/boolean=" + DigestUtils.shaHex("true") + "jcr:content/double=" + DigestUtils.shaHex("99.99") + "jcr:content/jcr:primaryType=" + DigestUtils.shaHex("nt:unstructured") + "jcr:content/jcr:title=" + DigestUtils.shaHex("My Title") + "jcr:content/sorted=" + DigestUtils.shaHex("yelp") + "," + DigestUtils.shaHex("arf") // This order is dictated by the sorted values of the corresponding hashes + "jcr:content/unsorted=" + DigestUtils.shaHex("howl") + "," + DigestUtils.shaHex("bark") + "," + DigestUtils.shaHex("woof"); String expected = DigestUtils.shaHex(raw); CustomChecksumGeneratorOptions opts = new CustomChecksumGeneratorOptions(); opts.addSortedProperties(new String[] { "sorted" }); opts.addExcludedProperties(new String[] { "jcr:description", "long" }); String actual = checksumGenerator.generatePropertyChecksums(node.getPath(), node, opts); assertEquals(expected, actual); }
From source file:com.adobe.acs.commons.analysis.jcrchecksum.impl.ChecksumGeneratorImplTest.java
@Test public void testAggregateChecksums() { Map<String, String> checksums = new LinkedHashMap<String, String>(); checksums.put("jcr:content/foo", "1234"); checksums.put("jcr:content/bar", "5678,9012"); String expected = DigestUtils.shaHex("jcr:content/foo=1234jcr:content/bar=5678,9012"); String actual = checksumGenerator.aggregateChecksums(checksums); assertEquals(expected, actual);//from w w w. j a v a 2 s . com }