Skip to content

Commit

Permalink
Make sure to trim all path parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Oct 29, 2024
1 parent b60b575 commit 64740d4
Show file tree
Hide file tree
Showing 21 changed files with 48 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import com.helger.commons.annotation.Nonempty;
import com.helger.commons.http.CHttp;
import com.helger.commons.string.StringHelper;
import com.helger.phoss.smp.app.SMPWebAppConfiguration;
import com.helger.phoss.smp.domain.SMPMetaManager;
import com.helger.phoss.smp.exception.SMPPreconditionFailedException;
Expand All @@ -40,7 +41,7 @@ public void invokeAPI (@Nonnull final IAPIDescriptor aAPIDescriptor,
@Nonnull final IRequestWebScopeWithoutResponse aRequestScope,
@Nonnull final UnifiedResponse aUnifiedResponse) throws Exception
{
final String sServiceGroupID = aPathVariables.get (SMPRestFilter.PARAM_SERVICE_GROUP_ID);
final String sServiceGroupID = StringHelper.trim (aPathVariables.get (SMPRestFilter.PARAM_SERVICE_GROUP_ID));
final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider (aRequestScope, sServiceGroupID);

// Is the writable API disabled?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import com.helger.commons.annotation.Nonempty;
import com.helger.commons.mime.CMimeType;
import com.helger.commons.string.StringHelper;
import com.helger.peppol.businesscard.v3.PD3BusinessCardMarshaller;
import com.helger.peppol.businesscard.v3.PD3BusinessCardType;
import com.helger.phoss.smp.app.SMPWebAppConfiguration;
Expand All @@ -42,7 +43,7 @@ public void invokeAPI (@Nonnull final IAPIDescriptor aAPIDescriptor,
@Nonnull final IRequestWebScopeWithoutResponse aRequestScope,
@Nonnull final UnifiedResponse aUnifiedResponse) throws Exception
{
final String sServiceGroupID = aPathVariables.get (SMPRestFilter.PARAM_SERVICE_GROUP_ID);
final String sServiceGroupID = StringHelper.trim (aPathVariables.get (SMPRestFilter.PARAM_SERVICE_GROUP_ID));
final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider (aRequestScope, sServiceGroupID);

if (!SMPMetaManager.getSettings ().isDirectoryIntegrationEnabled ())
Expand All @@ -58,6 +59,8 @@ public void invokeAPI (@Nonnull final IAPIDescriptor aAPIDescriptor,
final PD3BusinessCardType ret = new BusinessCardServerAPI (aDataProvider).getBusinessCard (sServiceGroupID);
final byte [] aBytes = new PD3BusinessCardMarshaller ().getAsBytes (ret);

aUnifiedResponse.setContent (aBytes).setMimeType (CMimeType.TEXT_XML).setCharset (XMLWriterSettings.DEFAULT_XML_CHARSET_OBJ);
aUnifiedResponse.setContent (aBytes)
.setMimeType (CMimeType.TEXT_XML)
.setCharset (XMLWriterSettings.DEFAULT_XML_CHARSET_OBJ);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import com.helger.commons.annotation.Nonempty;
import com.helger.commons.http.CHttp;
import com.helger.commons.string.StringHelper;
import com.helger.peppolid.IParticipantIdentifier;
import com.helger.peppolid.factory.IIdentifierFactory;
import com.helger.phoss.smp.app.PDClientProvider;
Expand Down Expand Up @@ -106,7 +107,7 @@ public void invokeAPI (@Nonnull final IAPIDescriptor aAPIDescriptor,
@Nonnull final IRequestWebScopeWithoutResponse aRequestScope,
@Nonnull final UnifiedResponse aUnifiedResponse) throws Exception
{
final String sServiceGroupID = aPathVariables.get (SMPRestFilter.PARAM_SERVICE_GROUP_ID);
final String sServiceGroupID = StringHelper.trim (aPathVariables.get (SMPRestFilter.PARAM_SERVICE_GROUP_ID));
final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider (aRequestScope, sServiceGroupID);

if (!SMPMetaManager.getSettings ().isDirectoryIntegrationEnabled ())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.helger.commons.http.CHttp;
import com.helger.commons.io.stream.StreamHelper;
import com.helger.commons.state.ESuccess;
import com.helger.commons.string.StringHelper;
import com.helger.peppol.businesscard.generic.PDBusinessCard;
import com.helger.peppol.businesscard.helper.PDBusinessCardHelper;
import com.helger.phoss.smp.app.SMPWebAppConfiguration;
Expand All @@ -46,7 +47,7 @@ public void invokeAPI (@Nonnull final IAPIDescriptor aAPIDescriptor,
@Nonnull final IRequestWebScopeWithoutResponse aRequestScope,
@Nonnull final UnifiedResponse aUnifiedResponse) throws Exception
{
final String sServiceGroupID = aPathVariables.get (SMPRestFilter.PARAM_SERVICE_GROUP_ID);
final String sServiceGroupID = StringHelper.trim (aPathVariables.get (SMPRestFilter.PARAM_SERVICE_GROUP_ID));
final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider (aRequestScope, sServiceGroupID);

// Is the writable API disabled?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.helger.commons.collection.impl.ICommonsList;
import com.helger.commons.mime.CMimeType;
import com.helger.commons.mime.MimeType;
import com.helger.commons.string.StringHelper;
import com.helger.phoss.smp.domain.SMPMetaManager;
import com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup;
import com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager;
Expand Down Expand Up @@ -63,7 +64,7 @@ public void invokeAPI (@Nonnull final IAPIDescriptor aAPIDescriptor,
@Nonnull final IRequestWebScopeWithoutResponse aRequestScope,
@Nonnull final UnifiedResponse aUnifiedResponse) throws Exception
{
final String sPathUserLoginName = aPathVariables.get (SMPRestFilter.PARAM_USER_ID);
final String sPathUserLoginName = StringHelper.trim (aPathVariables.get (SMPRestFilter.PARAM_USER_ID));

final String sLogPrefix = "[REST API Export-ByOwner-XML-V1] ";
LOGGER.info (sLogPrefix + "Starting Export for all of owner '" + sPathUserLoginName + "'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.helger.commons.collection.impl.CommonsArrayList;
import com.helger.commons.mime.CMimeType;
import com.helger.commons.mime.MimeType;
import com.helger.commons.string.StringHelper;
import com.helger.peppolid.IParticipantIdentifier;
import com.helger.peppolid.factory.IIdentifierFactory;
import com.helger.phoss.smp.domain.SMPMetaManager;
Expand Down Expand Up @@ -65,7 +66,7 @@ public void invokeAPI (@Nonnull final IAPIDescriptor aAPIDescriptor,
@Nonnull final IRequestWebScopeWithoutResponse aRequestScope,
@Nonnull final UnifiedResponse aUnifiedResponse) throws Exception
{
final String sPathServiceGroupID = aPathVariables.get (SMPRestFilter.PARAM_SERVICE_GROUP_ID);
final String sPathServiceGroupID = StringHelper.trim (aPathVariables.get (SMPRestFilter.PARAM_SERVICE_GROUP_ID));

final String sLogPrefix = "[REST API Export-Specific-XML-V1] ";
LOGGER.info (sLogPrefix + "Starting Export of '" + sPathServiceGroupID + "'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import com.helger.commons.annotation.Nonempty;
import com.helger.commons.http.CHttp;
import com.helger.commons.string.StringHelper;
import com.helger.peppolid.IParticipantIdentifier;
import com.helger.peppolid.factory.IIdentifierFactory;
import com.helger.phoss.smp.domain.SMPMetaManager;
Expand Down Expand Up @@ -57,7 +58,7 @@ public void invokeAPI (@Nonnull final IAPIDescriptor aAPIDescriptor,
@Nonnull final IRequestWebScopeWithoutResponse aRequestScope,
@Nonnull final UnifiedResponse aUnifiedResponse) throws Exception
{
final String sServiceGroupID = aPathVariables.get (SMPRestFilter.PARAM_SERVICE_GROUP_ID);
final String sServiceGroupID = StringHelper.trim (aPathVariables.get (SMPRestFilter.PARAM_SERVICE_GROUP_ID));
final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider (aRequestScope, sServiceGroupID);

// Is the writable API disabled?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import com.helger.commons.annotation.Nonempty;
import com.helger.commons.http.CHttp;
import com.helger.commons.string.StringHelper;
import com.helger.peppolid.IParticipantIdentifier;
import com.helger.peppolid.factory.IIdentifierFactory;
import com.helger.phoss.smp.domain.SMPMetaManager;
Expand Down Expand Up @@ -60,7 +61,7 @@ public void invokeAPI (@Nonnull final IAPIDescriptor aAPIDescriptor,
@Nonnull final IRequestWebScopeWithoutResponse aRequestScope,
@Nonnull final UnifiedResponse aUnifiedResponse) throws Exception
{
final String sServiceGroupID = aPathVariables.get (SMPRestFilter.PARAM_SERVICE_GROUP_ID);
final String sServiceGroupID = StringHelper.trim (aPathVariables.get (SMPRestFilter.PARAM_SERVICE_GROUP_ID));
final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider (aRequestScope, sServiceGroupID);

// Is the writable API disabled?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.helger.commons.annotation.Nonempty;
import com.helger.commons.mime.CMimeType;
import com.helger.commons.mime.MimeType;
import com.helger.commons.string.StringHelper;
import com.helger.peppol.sml.ISMLInfo;
import com.helger.peppol.smlclient.ManageParticipantIdentifierServiceCaller;
import com.helger.peppol.smlclient.participant.BadRequestFault;
Expand Down Expand Up @@ -77,7 +78,7 @@ public void invokeAPI (@Nonnull final IAPIDescriptor aAPIDescriptor,
@Nonnull final IRequestWebScopeWithoutResponse aRequestScope,
@Nonnull final UnifiedResponse aUnifiedResponse) throws Exception
{
final String sServiceGroupID = aPathVariables.get (SMPRestFilter.PARAM_SERVICE_GROUP_ID);
final String sServiceGroupID = StringHelper.trim (aPathVariables.get (SMPRestFilter.PARAM_SERVICE_GROUP_ID));
final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider (aRequestScope, sServiceGroupID);

// Is the writable API disabled?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.helger.commons.datetime.PDTFactory;
import com.helger.commons.http.CHttp;
import com.helger.commons.mime.CMimeType;
import com.helger.commons.string.StringHelper;
import com.helger.commons.timing.StopWatch;
import com.helger.httpclient.HttpClientManager;
import com.helger.httpclient.response.ResponseHandlerByteArray;
Expand Down Expand Up @@ -68,7 +69,7 @@ public void invokeAPI (@Nonnull final IAPIDescriptor aAPIDescriptor,
@Nonnull final IRequestWebScopeWithoutResponse aRequestScope,
@Nonnull final UnifiedResponse aUnifiedResponse) throws Exception
{
final String sPathServiceGroupID = aPathVariables.get (SMPRestFilter.PARAM_SERVICE_GROUP_ID);
final String sPathServiceGroupID = StringHelper.trim (aPathVariables.get (SMPRestFilter.PARAM_SERVICE_GROUP_ID));
final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider (aRequestScope, sPathServiceGroupID);

// Is the remote query API disabled?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.helger.commons.datetime.PDTFactory;
import com.helger.commons.http.CHttp;
import com.helger.commons.mime.CMimeType;
import com.helger.commons.string.StringHelper;
import com.helger.commons.timing.StopWatch;
import com.helger.httpclient.HttpClientManager;
import com.helger.httpclient.response.ResponseHandlerByteArray;
Expand Down Expand Up @@ -71,7 +72,7 @@ public void invokeAPI (@Nonnull final IAPIDescriptor aAPIDescriptor,
@Nonnull final IRequestWebScopeWithoutResponse aRequestScope,
@Nonnull final UnifiedResponse aUnifiedResponse) throws Exception
{
final String sPathServiceGroupID = aPathVariables.get (SMPRestFilter.PARAM_SERVICE_GROUP_ID);
final String sPathServiceGroupID = StringHelper.trim (aPathVariables.get (SMPRestFilter.PARAM_SERVICE_GROUP_ID));
final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider (aRequestScope, sPathServiceGroupID);

// Is the remote query API disabled?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,22 @@
import org.slf4j.LoggerFactory;

import com.helger.commons.CGlobal;
import com.helger.commons.ValueEnforcer;
import com.helger.commons.annotation.Nonempty;
import com.helger.commons.base64.Base64;
import com.helger.commons.datetime.OffsetDate;
import com.helger.commons.datetime.PDTFactory;
import com.helger.commons.datetime.XMLOffsetDate;
import com.helger.commons.http.CHttp;
import com.helger.commons.mime.CMimeType;
import com.helger.commons.string.StringHelper;
import com.helger.commons.timing.StopWatch;
import com.helger.json.IJsonArray;
import com.helger.json.IJsonObject;
import com.helger.json.JsonArray;
import com.helger.json.JsonObject;
import com.helger.json.JsonValue;
import com.helger.json.serialize.JsonWriter;
import com.helger.json.serialize.JsonWriterSettings;
import com.helger.peppol.sml.ESMPAPIType;
import com.helger.peppolid.CIdentifier;
import com.helger.peppolid.IDocumentTypeIdentifier;
import com.helger.peppolid.IParticipantIdentifier;
import com.helger.peppolid.factory.IIdentifierFactory;
Expand All @@ -63,8 +61,6 @@
import com.helger.smpclient.peppol.SMPClientReadOnly;
import com.helger.web.scope.IRequestWebScopeWithoutResponse;
import com.helger.xsds.bdxr.smp2.ac.CertificateType;
import com.helger.xsds.bdxr.smp2.ac.ProcessMetadataType;
import com.helger.xsds.bdxr.smp2.ac.ProcessType;

public final class APIExecutorQueryGetServiceMetadata extends AbstractSMPAPIExecutorQuery
{
Expand Down Expand Up @@ -112,110 +108,13 @@ static IJsonObject convertEndpoint (@Nonnull final com.helger.xsds.bdxr.smp2.ac.
return ret;
}

// TODO use SMPJsonResponse version in peppol-commons>8.8.0
@Nonnull
static IJsonObject convert (@Nonnull final IParticipantIdentifier aParticipantID,
@Nonnull final IDocumentTypeIdentifier aDocTypeID,
@Nonnull final com.helger.xsds.bdxr.smp2.ServiceMetadataType aSM)
{
ValueEnforcer.notNull (aParticipantID, "ParticipantID");
ValueEnforcer.notNull (aDocTypeID, "DocTypeID");
ValueEnforcer.notNull (aSM, "SM");

final IJsonObject ret = new JsonObject ();
ret.add (SMPJsonResponse.JSON_SMPTYPE, ESMPAPIType.OASIS_BDXR_V2.getID ());
ret.add (SMPJsonResponse.JSON_PARTICIPANT_ID, aParticipantID.getURIEncoded ());
ret.add (SMPJsonResponse.JSON_DOCUMENT_TYPE_ID, aDocTypeID.getURIEncoded ());

for (final ProcessMetadataType aPM : aSM.getProcessMetadata ())
{
final IJsonObject aJsonProcessMetadata = new JsonObject ();

{
final SMPExtensionList aExts = SMPExtensionList.ofBDXR2 (aPM.getSMPExtensions ());
if (aExts != null)
aJsonProcessMetadata.addIfNotNull (SMPJsonResponse.JSON_EXTENSION, aExts.getExtensionsAsJsonString ());
}

{
// Convert all process IDs
final IJsonArray aJsonProcesses = new JsonArray ();
for (final ProcessType aProc : aPM.getProcess ())
{
final IJsonObject aJsonProc = new JsonObject ().add ("id",
CIdentifier.getURIEncodedBDXR2 (aProc.getID ()
.getSchemeID (),
aProc.getID ()
.getValue ()));
if (aProc.hasRoleIDEntries ())
{
aJsonProc.add ("roleids",
new JsonArray ().addAllMapped (aProc.getRoleID (),
x -> JsonValue.create (CIdentifier.getURIEncodedBDXR2 (x.getSchemeID (),
x.getValue ()))));
}

final SMPExtensionList aExts = SMPExtensionList.ofBDXR2 (aProc.getSMPExtensions ());
if (aExts != null)
aJsonProc.addIfNotNull (SMPJsonResponse.JSON_EXTENSION, aExts.getExtensionsAsJsonString ());

aJsonProcesses.add (aJsonProc);
}
aJsonProcessMetadata.add ("processes", aJsonProcesses);
}

final com.helger.xsds.bdxr.smp2.ac.RedirectType aRedirect = aPM.getRedirect ();
if (aRedirect != null)
{
final IJsonObject aJsonRedirect = new JsonObject ().add (SMPJsonResponse.JSON_HREF,
aRedirect.getPublisherURIValue ());

// Add all certificates
final IJsonArray aJsonCerts = new JsonArray ();
for (final CertificateType aCert : aRedirect.getCertificate ())
{
final IJsonObject aJsonCert = new JsonObject ();
SMPJsonResponse.convertCertificate (aJsonCert, Base64.encodeBytes (aCert.getContentBinaryObjectValue ()));
aJsonCerts.add (aJsonCert);
}
aJsonRedirect.addJson ("certificates", aJsonCerts);

final SMPExtensionList aExts = SMPExtensionList.ofBDXR2 (aRedirect.getSMPExtensions ());
if (aExts != null)
{
// It's okay to add as string
aJsonRedirect.addIfNotNull (SMPJsonResponse.JSON_EXTENSION, aExts.getExtensionsAsJsonString ());
}
aJsonProcessMetadata.addJson (SMPJsonResponse.JSON_REDIRECT, aJsonRedirect);
}
else
{
final IJsonArray aJsonEPs = new JsonArray ();
// For all endpoints
for (final com.helger.xsds.bdxr.smp2.ac.EndpointType aEndpoint : aPM.getEndpoint ())
{
aJsonEPs.add (convertEndpoint (aEndpoint));
}
aJsonProcessMetadata.addJson (SMPJsonResponse.JSON_ENDPOINTS, aJsonEPs);
}
}

final SMPExtensionList aExts = SMPExtensionList.ofBDXR2 (aSM.getSMPExtensions ());
if (aExts != null)
{
// It's okay to add as string
ret.addIfNotNull (SMPJsonResponse.JSON_EXTENSION, aExts.getExtensionsAsJsonString ());
}
return ret;
}

public void invokeAPI (@Nonnull final IAPIDescriptor aAPIDescriptor,
@Nonnull @Nonempty final String sPath,
@Nonnull final Map <String, String> aPathVariables,
@Nonnull final IRequestWebScopeWithoutResponse aRequestScope,
@Nonnull final UnifiedResponse aUnifiedResponse) throws Exception
{
final String sPathServiceGroupID = aPathVariables.get (SMPRestFilter.PARAM_SERVICE_GROUP_ID);
final String sPathServiceGroupID = StringHelper.trim (aPathVariables.get (SMPRestFilter.PARAM_SERVICE_GROUP_ID));
final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider (aRequestScope, sPathServiceGroupID);

// Is the remote query API disabled?
Expand Down Expand Up @@ -305,7 +204,7 @@ public void invokeAPI (@Nonnull final IAPIDescriptor aAPIDescriptor,
aDocTypeID);
if (aSM != null)
{
aJson = convert (aParticipantID, aDocTypeID, aSM);
aJson = SMPJsonResponse.convert (aParticipantID, aDocTypeID, aSM);
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import com.helger.commons.annotation.Nonempty;
import com.helger.commons.mime.CMimeType;
import com.helger.commons.string.StringHelper;
import com.helger.phoss.smp.config.SMPServerConfiguration;
import com.helger.phoss.smp.exception.SMPInternalErrorException;
import com.helger.phoss.smp.restapi.BDXR1ServerAPI;
Expand All @@ -42,7 +43,7 @@ public void invokeAPI (@Nonnull final IAPIDescriptor aAPIDescriptor,
@Nonnull final IRequestWebScopeWithoutResponse aRequestScope,
@Nonnull final UnifiedResponse aUnifiedResponse) throws Exception
{
final String sPathServiceGroupID = aPathVariables.get (SMPRestFilter.PARAM_SERVICE_GROUP_ID);
final String sPathServiceGroupID = StringHelper.trim (aPathVariables.get (SMPRestFilter.PARAM_SERVICE_GROUP_ID));
final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider (aRequestScope, sPathServiceGroupID);

final byte [] aBytes;
Expand Down
Loading

0 comments on commit 64740d4

Please sign in to comment.