use of com.helger.xsds.bdxr.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;
}
use of com.helger.xsds.bdxr.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);
}
use of com.helger.xsds.bdxr.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);
}
use of com.helger.xsds.bdxr.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());
}
use of com.helger.xsds.bdxr.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");
}
Aggregations