Search in sources :

Example 16 with SignedServiceMetadataType

use of com.helger.xsds.bdxr.smp1.SignedServiceMetadataType in project peppol-commons by phax.

the class BDXRClientReadOnlyTest method testReadTOOP.

@Test
@Ignore("Because it may take long to execute")
@IgnoredNaptrTest
public void testReadTOOP() throws SMPDNSResolutionException, SMPClientException {
    final IParticipantIdentifier aPI = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9930:167064991");
    final IDocumentTypeIdentifier aDocTypeID = SimpleIdentifierFactory.INSTANCE.createDocumentTypeIdentifier("toop-doctypeid-qns", "urn:eu:toop:ns:dataexchange-1p40::Response##urn:eu.toop.response.registeredorganization::1.40");
    // TOOP SML
    final ISMLInfo aSMLInfo = new SMLInfo("toop", "SMK", "toop.acc.edelivery.tech.ec.europa.eu.", "https://acc.edelivery.tech.ec.europa.eu/edelivery-sml", true);
    // PEPPOL URL provider
    final BDXRClientReadOnly aBDXRClient = new BDXRClientReadOnly(BDXLURLProvider.INSTANCE, aPI, aSMLInfo);
    aBDXRClient.setVerifySignature(false);
    assertEquals("http://smp.toop.egov.iwvi.uni-koblenz.de/", aBDXRClient.getSMPHostURI());
    if (false) {
        final SignedServiceMetadataType aMetadata = aBDXRClient.getServiceMetadata(aPI, aDocTypeID);
        assertNotNull(aMetadata);
    }
}
Also used : ISMLInfo(com.helger.peppol.sml.ISMLInfo) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) SignedServiceMetadataType(com.helger.xsds.bdxr.smp1.SignedServiceMetadataType) SMLInfo(com.helger.peppol.sml.SMLInfo) ISMLInfo(com.helger.peppol.sml.ISMLInfo) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Ignore(org.junit.Ignore) IgnoredNaptrTest(com.helger.smpclient.IgnoredNaptrTest) IgnoredNaptrTest(com.helger.smpclient.IgnoredNaptrTest) Test(org.junit.Test)

Example 17 with SignedServiceMetadataType

use of com.helger.xsds.bdxr.smp1.SignedServiceMetadataType in project peppol-commons by phax.

the class BDXRClientReadOnlyTest method testReadDE4A.

@Test
@Ignore("Because it may take long to execute")
@IgnoredNaptrTest
public void testReadDE4A() throws Exception {
    final IParticipantIdentifier aPI = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9999:at000000271");
    final IDocumentTypeIdentifier aDocTypeID = SimpleIdentifierFactory.INSTANCE.createDocumentTypeIdentifier("urn:de4a-eu:CanonicalEvidenceType", "CompanyRegistration");
    final KeyStore aTS = KeyStoreHelper.loadKeyStoreDirect(EKeyStoreType.JKS, "truststores/de4a-truststore-test-smp-pw-de4a.jks", "de4a");
    assertNotNull(aTS);
    // TOOP SML
    final ISMLInfo aSMLInfo = new SMLInfo("dea4", "SMK", "de4a.acc.edelivery.tech.ec.europa.eu.", "https://acc.edelivery.tech.ec.europa.eu/edelivery-sml", true);
    // BDXL URL provider
    final BDXRClientReadOnly aBDXRClient = new BDXRClientReadOnly(BDXLURLProvider.INSTANCE, aPI, aSMLInfo);
    // Custom truststore is needed atm
    aBDXRClient.setTrustStore(aTS);
    assertEquals("https://de4a-smp.egovlab.eu/", aBDXRClient.getSMPHostURI());
    {
        final SignedServiceMetadataType aMetadata = aBDXRClient.getServiceMetadata(aPI, aDocTypeID);
        assertNotNull(aMetadata);
    }
}
Also used : ISMLInfo(com.helger.peppol.sml.ISMLInfo) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) SignedServiceMetadataType(com.helger.xsds.bdxr.smp1.SignedServiceMetadataType) SMLInfo(com.helger.peppol.sml.SMLInfo) ISMLInfo(com.helger.peppol.sml.ISMLInfo) KeyStore(java.security.KeyStore) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Ignore(org.junit.Ignore) IgnoredNaptrTest(com.helger.smpclient.IgnoredNaptrTest) IgnoredNaptrTest(com.helger.smpclient.IgnoredNaptrTest) Test(org.junit.Test)

Example 18 with SignedServiceMetadataType

use of com.helger.xsds.bdxr.smp1.SignedServiceMetadataType in project peppol-commons by phax.

the class BDXR1MarshallerSignedServiceMetadataTypeTest method testIssue121.

@Test
public void testIssue121() {
    final String s = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<SignedServiceMetadata\r\n" + "  xmlns=\"http://docs.oasis-open.org/bdxr/ns/SMP/2016/05\"\r\n" + "  xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\">\r\n" + "  <ServiceMetadata>\r\n" + "    <ServiceInformation>\r\n" + "      <ParticipantIdentifier scheme=\"iso6523-actorid-upis\">0106:{KvK}</ParticipantIdentifier>\r\n" + "      <DocumentIdentifier scheme=\"busdox-docid-qns\">urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##urn:www.cenbii.eu:transaction:biicoretrdm010:ver1.0:extended:urn:www.peppol.eu:bis:peppol4a:ver1.0::2.0</DocumentIdentifier>\r\n" + "      <ProcessList>\r\n" + "        <Process>\r\n" + "          <ProcessIdentifier scheme=\"cenbii-procid-ubl\">urn:www.cenbii.eu:profile:bii04:ver1.0</ProcessIdentifier>\r\n" + "          <ServiceEndpointList>\r\n" + "            <Endpoint transportProfile=\"busdox-transport-as2-ver1p0\">\r\n" + "              <EndpointURI>https://example.org/as2</EndpointURI>\r\n" + "              <RequireBusinessLevelSignature>true</RequireBusinessLevelSignature>\r\n" + "                <ServiceActivationDate>\r\n" + "                  2019-01-16T01:00:00.000+01:00\r\n" + "                </ServiceActivationDate>\r\n" + "                <ServiceExpirationDate>\r\n" + "                  2026-03-15T01:00:00.000+01:00\r\n" + "                </ServiceExpirationDate>\r\n" + "              <Certificate>SGFsbG8=</Certificate>\r\n" + "              <ServiceDescription>test</ServiceDescription>\r\n" + "              <TechnicalContactUrl>https://sitename.com</TechnicalContactUrl>\r\n" + "              <TechnicalInformationUrl>https://sitename.com</TechnicalInformationUrl>\r\n" + "            </Endpoint>\r\n" + "          </ServiceEndpointList>\r\n" + "        </Process>\r\n" + "      </ProcessList>\r\n" + "    </ServiceInformation>\r\n" + "  </ServiceMetadata>\r\n" + // Parsing would fail in Signature
    "  <ds:Signature/>\r\n" + "</SignedServiceMetadata>";
    final SignedServiceMetadataType aObj = new BDXR1MarshallerSignedServiceMetadataType(false).read(s);
    assertNotNull(aObj);
}
Also used : SignedServiceMetadataType(com.helger.xsds.bdxr.smp1.SignedServiceMetadataType) Test(org.junit.Test)

Example 19 with SignedServiceMetadataType

use of com.helger.xsds.bdxr.smp1.SignedServiceMetadataType in project peppol-commons by phax.

the class BDXRClientReadOnly method getServiceMetadata.

/**
 * Gets a signed service metadata object given by its service group id and its
 * document type. This is a specification compliant method.
 *
 * @param aServiceGroupID
 *        The service group id of the service metadata to get. May not be
 *        <code>null</code>.
 * @param aDocumentTypeID
 *        The document type of the service metadata to get. May not be
 *        <code>null</code>.
 * @return A signed service metadata object. Never <code>null</code>.
 * @throws SMPClientException
 *         in case something goes wrong
 * @throws SMPClientUnauthorizedException
 *         A HTTP Forbidden was received, should not happen.
 * @throws SMPClientNotFoundException
 *         The service group id or document type did not exist.
 * @throws SMPClientBadRequestException
 *         The request was not well formed.
 * @see #getServiceMetadataOrNull(IParticipantIdentifier,
 *      IDocumentTypeIdentifier)
 * @since v8.0.0
 */
@Nonnull
public SignedServiceMetadataType getServiceMetadata(@Nonnull final IParticipantIdentifier aServiceGroupID, @Nonnull final IDocumentTypeIdentifier aDocumentTypeID) throws SMPClientException {
    ValueEnforcer.notNull(aServiceGroupID, "ServiceGroupID");
    ValueEnforcer.notNull(aDocumentTypeID, "DocumentTypeID");
    final String sURI = getSMPHostURI() + aServiceGroupID.getURIPercentEncoded() + "/" + URL_PART_SERVICES + "/" + aDocumentTypeID.getURIPercentEncoded();
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("BDXRClient getServiceRegistration@" + sURI);
    final boolean bXSDValidation = isXMLSchemaValidation();
    final boolean bVerifySignature = isVerifySignature();
    final KeyStore aTrustStore = getTrustStore();
    HttpGet aRequest = new HttpGet(sURI);
    BDXR1MarshallerSignedServiceMetadataType aMarshaller = new BDXR1MarshallerSignedServiceMetadataType(bXSDValidation);
    customizeMarshaller(aMarshaller);
    SignedServiceMetadataType aMetadata = executeGenericRequest(aRequest, new SMPHttpResponseHandlerSigned<>(aMarshaller, aTrustStore).setVerifySignature(bVerifySignature));
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Received response: " + aMetadata);
    // If the Redirect element is present, then follow 1 redirect.
    if (isFollowSMPRedirects()) {
        if (aMetadata.getServiceMetadata() != null && aMetadata.getServiceMetadata().getRedirect() != null) {
            final RedirectType aRedirect = aMetadata.getServiceMetadata().getRedirect();
            // Follow the redirect
            if (LOGGER.isInfoEnabled())
                LOGGER.info("Following a redirect from '" + sURI + "' to '" + aRedirect.getHref() + "'");
            aRequest = new HttpGet(aRedirect.getHref());
            // Create a new Marshaller to make sure customization is easy
            aMarshaller = new BDXR1MarshallerSignedServiceMetadataType(bXSDValidation);
            customizeMarshaller(aMarshaller);
            aMetadata = executeGenericRequest(aRequest, new SMPHttpResponseHandlerSigned<>(aMarshaller, aTrustStore).setVerifySignature(bVerifySignature));
            // Check that the certificateUID is correct
            boolean bCertificateSubjectFound = false;
            for (final Object aObj : aMetadata.getSignature().getKeyInfo().getContent()) {
                final Object aInfoValue = ((JAXBElement<?>) aObj).getValue();
                if (aInfoValue instanceof X509DataType) {
                    final X509DataType aX509Data = (X509DataType) aInfoValue;
                    if (containsRedirectSubject(aX509Data, aRedirect.getCertificateUID())) {
                        bCertificateSubjectFound = true;
                        break;
                    }
                }
            }
            if (!bCertificateSubjectFound)
                throw new SMPClientException("The X509 certificate did not contain a certificate subject.");
        }
    } else {
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("Following SMP redirects is disabled");
    }
    return aMetadata;
}
Also used : SMPHttpResponseHandlerSigned(com.helger.smpclient.httpclient.SMPHttpResponseHandlerSigned) X509DataType(com.helger.xsds.xmldsig.X509DataType) HttpGet(org.apache.http.client.methods.HttpGet) SignedServiceMetadataType(com.helger.xsds.bdxr.smp1.SignedServiceMetadataType) BDXR1MarshallerSignedServiceMetadataType(com.helger.smpclient.bdxr1.marshal.BDXR1MarshallerSignedServiceMetadataType) JAXBElement(javax.xml.bind.JAXBElement) KeyStore(java.security.KeyStore) RedirectType(com.helger.xsds.bdxr.smp1.RedirectType) BDXR1MarshallerSignedServiceMetadataType(com.helger.smpclient.bdxr1.marshal.BDXR1MarshallerSignedServiceMetadataType) SMPClientException(com.helger.smpclient.exception.SMPClientException) Nonnull(javax.annotation.Nonnull)

Example 20 with SignedServiceMetadataType

use of com.helger.xsds.bdxr.smp1.SignedServiceMetadataType in project peppol-commons by phax.

the class IBDXRServiceMetadataProvider method getEndpoint.

/**
 * Retrieve the service metadata from the provided service group ID and
 * document type ID. Than find the matching endpoint from the process ID and
 * transport profile.<br>
 * This is a specification compliant method.
 *
 * @param aServiceGroupID
 *        The service group id of the service metadata to get. May not be
 *        <code>null</code>.
 * @param aDocumentTypeID
 *        The document type of the service metadata to get. May not be
 *        <code>null</code>.
 * @param aProcessID
 *        The process ID of the service metadata to get. May not be
 *        <code>null</code>.
 * @param aTransportProfile
 *        The transport profile of the service metadata to get. May not be
 *        <code>null</code>.
 * @return The endpoint from the signed service metadata object or
 *         <code>null</code> if no such registration is present.
 * @throws SMPClientException
 *         in case something goes wrong
 * @throws SMPClientUnauthorizedException
 *         A HTTP Forbidden was received, should not happen.
 * @throws SMPClientBadRequestException
 *         The request was not well formed.
 * @see #getServiceMetadataOrNull(IParticipantIdentifier,IDocumentTypeIdentifier)
 */
@Nullable
default EndpointType getEndpoint(@Nonnull final IParticipantIdentifier aServiceGroupID, @Nonnull final IDocumentTypeIdentifier aDocumentTypeID, @Nonnull final IProcessIdentifier aProcessID, @Nonnull final ISMPTransportProfile aTransportProfile) throws SMPClientException {
    ValueEnforcer.notNull(aServiceGroupID, "ServiceGroupID");
    ValueEnforcer.notNull(aDocumentTypeID, "DocumentTypeID");
    ValueEnforcer.notNull(aProcessID, "ProcessID");
    ValueEnforcer.notNull(aTransportProfile, "TransportProfile");
    // Get meta data for participant/documentType
    final SignedServiceMetadataType aSignedServiceMetadata = getServiceMetadataOrNull(aServiceGroupID, aDocumentTypeID);
    return aSignedServiceMetadata == null ? null : BDXRClientReadOnly.getEndpoint(aSignedServiceMetadata, aProcessID, aTransportProfile);
}
Also used : SignedServiceMetadataType(com.helger.xsds.bdxr.smp1.SignedServiceMetadataType) Nullable(javax.annotation.Nullable)

Aggregations

SignedServiceMetadataType (com.helger.xsds.peppol.smp1.SignedServiceMetadataType)13 Test (org.junit.Test)13 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)11 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)10 SignedServiceMetadataType (com.helger.xsds.bdxr.smp1.SignedServiceMetadataType)7 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)4 IgnoredNaptrTest (com.helger.smpclient.IgnoredNaptrTest)4 SMPMarshallerSignedServiceMetadataType (com.helger.smpclient.peppol.marshal.SMPMarshallerSignedServiceMetadataType)4 Nonnull (javax.annotation.Nonnull)4 Ignore (org.junit.Ignore)4 ESuccess (com.helger.commons.state.ESuccess)3 LoggingValidationEventHandler (com.helger.jaxb.validation.LoggingValidationEventHandler)3 ISMLInfo (com.helger.peppol.sml.ISMLInfo)3 SMLInfo (com.helger.peppol.sml.SMLInfo)3 TrustStoreBasedX509KeySelector (com.helger.smpclient.security.TrustStoreBasedX509KeySelector)3 KeyStore (java.security.KeyStore)3 Document (org.w3c.dom.Document)3 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)2 ISMPRedirect (com.helger.phoss.smp.domain.redirect.ISMPRedirect)2 ISMPRedirectManager (com.helger.phoss.smp.domain.redirect.ISMPRedirectManager)2