Search in sources :

Example 1 with ServiceMetadataType

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

the class SMPMarshallerServiceMetadataTypeTest method testIssue121.

@Test
public void testIssue121() {
    final String s = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<ServiceMetadata xmlns=\"http://busdox.org/serviceMetadata/publishing/1.0/\" xmlns:id=\"http://busdox.org/transport/identifiers/1.0/\">\r\n" + "  <ServiceInformation>\r\n" + "    <id:ParticipantIdentifier scheme=\"iso6523-actorid-upis\">0106:{KvK}</id:ParticipantIdentifier>\r\n" + "    <id: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</id:DocumentIdentifier>\r\n" + "    <ProcessList>\r\n" + "      <Process>\r\n" + "        <id:ProcessIdentifier scheme=\"cenbii-procid-ubl\">urn:www.cenbii.eu:profile:bii04:ver1.0</id:ProcessIdentifier>\r\n" + "        <ServiceEndpointList>\r\n" + "          <Endpoint transportProfile=\"busdox-transport-as2-ver1p0\">\r\n" + "            <EndpointReference xmlns=\"http://www.w3.org/2005/08/addressing\"><Address>https://example.org/as2</Address></EndpointReference>\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>{Certificate}</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>";
    final ServiceMetadataType aObj = new SMPMarshallerServiceMetadataType(true).read(s);
    assertNotNull(aObj);
}
Also used : ServiceMetadataType(com.helger.xsds.peppol.smp1.ServiceMetadataType) Test(org.junit.Test)

Example 2 with ServiceMetadataType

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

the class MainSMPServiceGroupCompleteList method main.

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

Example 3 with ServiceMetadataType

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

the class BDXR1MarshallerServiceMetadataTypeTest method testIssue121.

@Test
public void testIssue121() {
    final String s = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<ServiceMetadata xmlns=\"http://docs.oasis-open.org/bdxr/ns/SMP/2016/05\">\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>";
    final ServiceMetadataType aObj = new BDXR1MarshallerServiceMetadataType(true).read(s);
    assertNotNull(aObj);
}
Also used : ServiceMetadataType(com.helger.xsds.bdxr.smp1.ServiceMetadataType) Test(org.junit.Test)

Example 4 with ServiceMetadataType

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

the class BDXR2Client method saveServiceRedirect.

/**
 * Saves a redirect data object.
 *
 * @param aServiceGroupID
 *        The service group ID to use. May not be <code>null</code>.
 * @param aDocumentTypeID
 *        The document type ID to use. May not be <code>null</code>.
 * @param aRedirect
 *        The redirect to be saved. May not be <code>null</code>.
 * @param aCredentials
 *        The user name and password to use as credentials. May not be
 *        <code>null</code>.
 * @throws SMPClientException
 *         in case something goes wrong
 * @throws SMPClientUnauthorizedException
 *         The user name or password was not correct.
 * @throws SMPClientNotFoundException
 *         A HTTP Not Found was received. This can happen if the service was
 *         not found.
 * @throws SMPClientBadRequestException
 *         The request was not well formed.
 * @see #saveServiceEndpoints(ParticipantIDType, IDType, List,
 *      BasicAuthClientCredentials)
 */
public void saveServiceRedirect(@Nonnull final ParticipantIDType aServiceGroupID, @Nonnull final IDType aDocumentTypeID, @Nonnull final RedirectType aRedirect, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPClientException {
    ValueEnforcer.notNull(aServiceGroupID, "ServiceGroupID");
    ValueEnforcer.notNull(aDocumentTypeID, "DocumentTypeID");
    ValueEnforcer.notNull(aRedirect, "Redirect");
    ValueEnforcer.notNull(aCredentials, "Credentials");
    final ServiceMetadataType aServiceMetadata = new ServiceMetadataType();
    aServiceMetadata.setSMPVersionID("2.0");
    aServiceMetadata.setID(aDocumentTypeID);
    aServiceMetadata.setParticipantID(aServiceGroupID);
    final ProcessMetadataType aPM = new ProcessMetadataType();
    aPM.setRedirect(aRedirect);
    aServiceMetadata.addProcessMetadata(aPM);
    _saveServiceInformation(aServiceMetadata, aCredentials);
}
Also used : ServiceMetadataType(com.helger.xsds.bdxr.smp2.ServiceMetadataType) ProcessMetadataType(com.helger.xsds.bdxr.smp2.ac.ProcessMetadataType)

Example 5 with ServiceMetadataType

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

the class BDXR2ClientReadOnly 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)
 */
@Nonnull
public ServiceMetadataType getServiceMetadata(@Nonnull final IParticipantIdentifier aServiceGroupID, @Nonnull final IDocumentTypeIdentifier aDocumentTypeID) throws SMPClientException {
    ValueEnforcer.notNull(aServiceGroupID, "ServiceGroupID");
    ValueEnforcer.notNull(aDocumentTypeID, "DocumentTypeID");
    final String sURI = getSMPHostURI() + PATH_OASIS_BDXR_SMP_2 + aServiceGroupID.getURIPercentEncoded() + "/" + URL_PART_SERVICES + "/" + aDocumentTypeID.getURIPercentEncoded();
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("BDXR2Client getServiceRegistration@" + sURI);
    final boolean bXSDValidation = isXMLSchemaValidation();
    final boolean bVerifySignature = isVerifySignature();
    final KeyStore aTrustStore = getTrustStore();
    HttpGet aRequest = new HttpGet(sURI);
    BDXR2ServiceMetadataMarshaller aMarshaller = new BDXR2ServiceMetadataMarshaller(bXSDValidation);
    customizeMarshaller(aMarshaller);
    ServiceMetadataType aMetadata = executeGenericRequest(aRequest, new SMPHttpResponseHandlerSigned<>(aMarshaller, aTrustStore).setVerifySignature(bVerifySignature));
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Received response: " + aMetadata);
    if (!SimpleDocumentTypeIdentifier.wrap(aMetadata.getID()).equals(aDocumentTypeID)) {
        // Inconsistency between request and response
        throw new SMPClientException("Requested document type '" + aDocumentTypeID.getURIEncoded() + "' and received '" + CIdentifier.getURIEncoded(aMetadata.getID()) + "' - mismatch. Ignoring request.");
    }
    // If the Redirect element is present, then follow 1 redirect.
    if (isFollowSMPRedirects()) {
        for (final ProcessMetadataType aPM : aMetadata.getProcessMetadata()) {
            final RedirectType aRedirect = aPM.getRedirect();
            if (aRedirect != null) {
                // Follow the redirect
                if (LOGGER.isInfoEnabled())
                    LOGGER.info("Following a redirect from '" + sURI + "' to '" + aRedirect.getPublisherURIValue() + "'");
                aRequest = new HttpGet(aRedirect.getPublisherURIValue());
                // Create a new Marshaller to make sure customization is easy
                aMarshaller = new BDXR2ServiceMetadataMarshaller(bXSDValidation);
                customizeMarshaller(aMarshaller);
                aMetadata = executeGenericRequest(aRequest, new SMPHttpResponseHandlerSigned<>(new BDXR2ServiceMetadataMarshaller(bXSDValidation), aTrustStore).setVerifySignature(bVerifySignature));
                // Check that the certificateUID is correct.
                boolean bCertificateSubjectFound = false;
                if (aMetadata.hasSignatureEntries())
                    outer: for (final Object aObj : aMetadata.getSignatureAtIndex(0).getKeyInfo().getContent()) {
                        final Object aInfoValue = ((JAXBElement<?>) aObj).getValue();
                        if (aInfoValue instanceof X509DataType) {
                            final X509DataType aX509Data = (X509DataType) aInfoValue;
                            for (final Object aX509Obj : aX509Data.getX509IssuerSerialOrX509SKIOrX509SubjectName()) {
                                final JAXBElement<?> aX509element = (JAXBElement<?>) aX509Obj;
                                // Find the first subject (of type string)
                                if (aX509element.getValue() instanceof X509Certificate) {
                                    final X509Certificate aSecondCert = (X509Certificate) aX509element.getValue();
                                    // Check all certs of the source redirect
                                    boolean bFound = false;
                                    final ICommonsList<X509Certificate> aAllRedirectCerts = new CommonsArrayList<>();
                                    for (final CertificateType aCT : aRedirect.getCertificate()) {
                                        try {
                                            final X509Certificate aRedirectCert = CertificateHelper.convertByteArrayToCertficate(aCT.getContentBinaryObjectValue());
                                            if (aRedirectCert != null) {
                                                aAllRedirectCerts.add(aRedirectCert);
                                                // Certificate match?
                                                if (aRedirectCert.equals(aSecondCert)) {
                                                    bFound = true;
                                                    break;
                                                }
                                            }
                                        } catch (final CertificateException ex) {
                                            // Error in certificate in SMP response
                                            LOGGER.error("SMP Redirect contains an invalid certificate", ex);
                                        }
                                    }
                                    if (!bFound)
                                        throw new SMPClientException("No certificate of the redirect matched the provided certificate. Retrieved certificate is '" + aSecondCert + "'. Allowed certificates according to the redirect are: " + aAllRedirectCerts);
                                    bCertificateSubjectFound = true;
                                    break outer;
                                }
                            }
                        }
                    }
                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) CertificateException(java.security.cert.CertificateException) JAXBElement(javax.xml.bind.JAXBElement) KeyStore(java.security.KeyStore) ProcessMetadataType(com.helger.xsds.bdxr.smp2.ac.ProcessMetadataType) X509Certificate(java.security.cert.X509Certificate) RedirectType(com.helger.xsds.bdxr.smp2.ac.RedirectType) CertificateType(com.helger.xsds.bdxr.smp2.ac.CertificateType) SMPClientException(com.helger.smpclient.exception.SMPClientException) ServiceMetadataType(com.helger.xsds.bdxr.smp2.ServiceMetadataType) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) BDXR2ServiceMetadataMarshaller(com.helger.smpclient.bdxr2.marshal.BDXR2ServiceMetadataMarshaller) Nonnull(javax.annotation.Nonnull)

Aggregations

ServiceMetadataType (com.helger.xsds.peppol.smp1.ServiceMetadataType)11 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)9 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)8 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)7 Nonnull (javax.annotation.Nonnull)7 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)6 ISMPServiceInformationManager (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager)6 EndpointType (com.helger.xsds.peppol.smp1.EndpointType)6 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)5 SimpleParticipantIdentifier (com.helger.peppolid.simple.participant.SimpleParticipantIdentifier)5 ISMPRedirectManager (com.helger.phoss.smp.domain.redirect.ISMPRedirectManager)5 ISMPServiceInformation (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation)5 SMPNotFoundException (com.helger.phoss.smp.exception.SMPNotFoundException)5 SMPServerException (com.helger.phoss.smp.exception.SMPServerException)5 ServiceMetadataType (com.helger.xsds.bdxr.smp1.ServiceMetadataType)5 ProcessType (com.helger.xsds.peppol.smp1.ProcessType)5 ServiceInformationType (com.helger.xsds.peppol.smp1.ServiceInformationType)5 Response (javax.ws.rs.core.Response)5 Test (org.junit.Test)5 ProcessListType (com.helger.xsds.peppol.smp1.ProcessListType)4