Search in sources :

Example 11 with SignedServiceMetadataType

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

the class SMPClientReadOnly 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("SMPClient getServiceRegistration@" + sURI);
    final boolean bXSDValidation = isXMLSchemaValidation();
    final boolean bVerifySignature = isVerifySignature();
    final KeyStore aTrustStore = getTrustStore();
    HttpGet aRequest = new HttpGet(sURI);
    SMPMarshallerSignedServiceMetadataType aMarshaller = new SMPMarshallerSignedServiceMetadataType(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 ensure customization is simple
            aMarshaller = new SMPMarshallerSignedServiceMetadataType(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.peppol.smp1.SignedServiceMetadataType) SMPMarshallerSignedServiceMetadataType(com.helger.smpclient.peppol.marshal.SMPMarshallerSignedServiceMetadataType) JAXBElement(javax.xml.bind.JAXBElement) KeyStore(java.security.KeyStore) RedirectType(com.helger.xsds.peppol.smp1.RedirectType) SMPClientException(com.helger.smpclient.exception.SMPClientException) SMPMarshallerSignedServiceMetadataType(com.helger.smpclient.peppol.marshal.SMPMarshallerSignedServiceMetadataType) Nonnull(javax.annotation.Nonnull)

Example 12 with SignedServiceMetadataType

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

the class SMPClientReadOnlyTest method testIssue2303.

@Test
@Ignore("Failed with timeout on 2021-05-02")
public void testIssue2303() throws Exception {
    final IParticipantIdentifier aPI = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9925:be0887290276");
    // PEPPOL URL provider
    final SMPClientReadOnly aSMPClient = new SMPClientReadOnly(PeppolURLProvider.INSTANCE, aPI, ESML.DIGIT_PRODUCTION);
    assertEquals("http://B-c9f280672264cdb82eac528c265ed029.iso6523-actorid-upis.edelivery.tech.ec.europa.eu/", aSMPClient.getSMPHostURI());
    aSMPClient.setXMLSchemaValidation(true);
    final SignedServiceMetadataType aSM = aSMPClient.getServiceMetadataOrNull(aPI, EPredefinedDocumentTypeIdentifier.INVOICE_EN16931_PEPPOL_V30);
    assertNotNull(aSM);
}
Also used : SignedServiceMetadataType(com.helger.xsds.peppol.smp1.SignedServiceMetadataType) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Ignore(org.junit.Ignore) IgnoredNaptrTest(com.helger.smpclient.IgnoredNaptrTest) Test(org.junit.Test)

Example 13 with SignedServiceMetadataType

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

the class SMPClientWithDNSFuncTest method testRedirect.

@Test
public void testRedirect() throws Exception {
    final String sParticipantID = "0088:5798000009997";
    final String sDocumentID = "urn:oasis:names:specification:ubl:schema:xsd:SubmitCatalogue-2::SubmitCatalogue##UBL-2.0";
    final IParticipantIdentifier aServiceGroupID = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme(sParticipantID);
    final IDocumentTypeIdentifier aDocumentTypeID = PeppolIdentifierFactory.INSTANCE.createDocumentTypeIdentifierWithDefaultScheme(sDocumentID);
    final SignedServiceMetadataType aMetadata = SMPClientReadOnly.getServiceRegistrationByDNS(URL_PROVIDER, SML_INFO, aServiceGroupID, aDocumentTypeID);
    assertNotNull(aMetadata);
}
Also used : IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) SignedServiceMetadataType(com.helger.xsds.peppol.smp1.SignedServiceMetadataType) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Example 14 with SignedServiceMetadataType

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

the class SignedServiceMetadataTypeFuncTest method testReadInvalid.

@Test
public void testReadInvalid() throws Exception {
    final SMPMarshallerSignedServiceMetadataType aMarshaller = new SMPMarshallerSignedServiceMetadataType(true);
    aMarshaller.setValidationEventHandlerFactory(x -> new LoggingValidationEventHandler());
    final byte[] aBytes = StreamHelper.getAllBytes(new ClassPathResource("smp/signed-service-metadata1.xml"));
    assertNotNull(aBytes);
    final SignedServiceMetadataType aSSM = aMarshaller.read(aBytes);
    assertNotNull(aSSM);
    final Document aDocument = DOMReader.readXMLDOM(aBytes);
    assertNotNull(aDocument);
    final TrustStoreBasedX509KeySelector aKeySelector = new TrustStoreBasedX509KeySelector(SMPClientConfiguration.loadTrustStore());
    // Certificate expired 2021-03-01
    aKeySelector.setValidationDateTime(PDTFactory.createLocalDateTime(2021, Month.JANUARY, 1));
    final ESuccess eSuccess = SMPHttpResponseHandlerSigned.checkSignature(aDocument, aKeySelector);
    assertTrue(eSuccess.isFailure());
}
Also used : ESuccess(com.helger.commons.state.ESuccess) SMPMarshallerSignedServiceMetadataType(com.helger.smpclient.peppol.marshal.SMPMarshallerSignedServiceMetadataType) SignedServiceMetadataType(com.helger.xsds.peppol.smp1.SignedServiceMetadataType) TrustStoreBasedX509KeySelector(com.helger.smpclient.security.TrustStoreBasedX509KeySelector) LoggingValidationEventHandler(com.helger.jaxb.validation.LoggingValidationEventHandler) Document(org.w3c.dom.Document) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) SMPMarshallerSignedServiceMetadataType(com.helger.smpclient.peppol.marshal.SMPMarshallerSignedServiceMetadataType) Test(org.junit.Test)

Example 15 with SignedServiceMetadataType

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

the class MainSMPServiceRegistrationList method main.

public static void main(final String[] args) throws Exception {
    final URI SMP_URI = MockSMPClientConfig.getSMPURI();
    final IParticipantIdentifier PARTICIPANT_ID = MockSMPClientConfig.getParticipantID();
    final IDocumentTypeIdentifier DOCUMENT_ID = MockSMPClientConfig.getDocumentTypeID();
    // The main SMP client
    final SMPClient aClient = new SMPClient(SMP_URI);
    // Get the service group reference list
    final SignedServiceMetadataType aSignedServiceMetadata = aClient.getServiceMetadataOrNull(PARTICIPANT_ID, DOCUMENT_ID);
    if (aSignedServiceMetadata == null)
        LOGGER.error("Failed to get service registration for " + PARTICIPANT_ID + " and " + DOCUMENT_ID);
    else
        LOGGER.info(SMPDebugHelper.getAsString(aSignedServiceMetadata.getServiceMetadata()));
    LOGGER.info("Done");
}
Also used : SMPClient(com.helger.smpclient.peppol.SMPClient) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) SignedServiceMetadataType(com.helger.xsds.peppol.smp1.SignedServiceMetadataType) URI(java.net.URI) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

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