use of com.helger.xsds.peppol.smp1.RedirectType in project peppol-commons by phax.
the class SMPDebugHelper method getAsString.
@Nonnull
public static String getAsString(@Nonnull final ServiceMetadataType aServiceMetadata) {
final StringBuilder aSB = new StringBuilder();
aSB.append("Service meta data:\n");
final ServiceInformationType aServiceInformation = aServiceMetadata.getServiceInformation();
if (aServiceInformation != null) {
aSB.append(" Service information:\n");
aSB.append(" Participant: ").append(CIdentifier.getURIEncoded(aServiceInformation.getParticipantIdentifier())).append('\n');
aSB.append(" Document type: ").append(CIdentifier.getURIEncoded(aServiceInformation.getDocumentIdentifier())).append('\n');
for (final ProcessType aProcess : aServiceInformation.getProcessList().getProcess()) {
aSB.append(" Process: ").append(CIdentifier.getURIEncoded(aProcess.getProcessIdentifier())).append('\n');
for (final EndpointType aEndpoint : aProcess.getServiceEndpointList().getEndpoint()) {
aSB.append(" Endpoint: ").append(W3CEndpointReferenceHelper.getAddress(aEndpoint.getEndpointReference())).append('\n');
aSB.append(" Transport profile: ").append(aEndpoint.getTransportProfile()).append('\n');
aSB.append(" Business level signature: ").append(aEndpoint.isRequireBusinessLevelSignature()).append('\n');
aSB.append(" Min auth level: ").append(aEndpoint.getMinimumAuthenticationLevel()).append('\n');
if (aEndpoint.getServiceActivationDate() != null)
aSB.append(" Valid from: ").append(aEndpoint.getServiceActivationDate()).append('\n');
if (aEndpoint.getServiceExpirationDate() != null)
aSB.append(" Valid to: ").append(aEndpoint.getServiceExpirationDate()).append('\n');
aSB.append(" Certficiate string: ").append(aEndpoint.getCertificate()).append('\n');
aSB.append(" Service description: ").append(aEndpoint.getServiceDescription()).append('\n');
aSB.append(" Contact URL: ").append(aEndpoint.getTechnicalContactUrl()).append('\n');
aSB.append(" Info URL: ").append(aEndpoint.getTechnicalInformationUrl()).append('\n');
}
}
}
final RedirectType aRedirect = aServiceMetadata.getRedirect();
if (aRedirect != null) {
aSB.append(" Service redirect:\n");
aSB.append(" Certificate UID: ").append(aRedirect.getCertificateUID()).append('\n');
aSB.append(" Href: ").append(aRedirect.getHref()).append('\n');
}
return aSB.toString();
}
use of com.helger.xsds.peppol.smp1.RedirectType 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;
}
Aggregations