Skip to content

Commit

Permalink
Added check for invalid public URLs; #237
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Mar 17, 2023
1 parent 9cf170f commit 894d077
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.helger.commons.lang.priviledged.IPrivilegedAction;
import com.helger.commons.regex.RegExHelper;
import com.helger.commons.string.StringHelper;
import com.helger.commons.url.URLHelper;
import com.helger.network.proxy.ProxySelectorProxySettingsManager;
import com.helger.network.proxy.settings.IProxySettings;
import com.helger.network.proxy.settings.IProxySettingsProvider;
Expand Down Expand Up @@ -101,18 +102,21 @@ public static OffsetDateTime getStartupDateTime ()
}

@Override
@Nullable
protected String getInitParameterDebug (@Nonnull final ServletContext aSC)
{
return SMPWebAppConfiguration.getGlobalDebug ();
}

@Override
@Nullable
protected String getInitParameterProduction (@Nonnull final ServletContext aSC)
{
return SMPWebAppConfiguration.getGlobalProduction ();
}

@Override
@Nullable
protected String getDataPath (@Nonnull final ServletContext aSC)
{
return SMPWebAppConfiguration.getDataPath ();
Expand All @@ -125,10 +129,22 @@ protected boolean shouldCheckFileAccess (@Nonnull final ServletContext aSC)
}

@Override
@Nullable
protected String getInitParameterServerURL (@Nonnull final ServletContext aSC, final boolean bProductionMode)
{
// This is internally set in "StaticServerInfo" class
return SMPServerConfiguration.getPublicServerURL ();
final String sPublicURL = SMPServerConfiguration.getPublicServerURL ();
if (StringHelper.hasText (sPublicURL))
{
// Check validity (see #237)
if (URLHelper.getAsURL (sPublicURL, false) != null)
return sPublicURL;

final String sErrorMsg = "The configured public URL '" + sPublicURL + "' is not a valid URL!";
LOGGER.error (sErrorMsg);
throw new InitializationException (sErrorMsg);
}
return null;
}

private static void _initTimeZone ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.helger.commons.lang.ClassHelper;
import com.helger.commons.string.StringHelper;
import com.helger.commons.url.SimpleURL;
import com.helger.commons.url.URLHelper;
import com.helger.html.hc.IHCNode;
import com.helger.html.hc.html.grouping.HCOL;
import com.helger.html.hc.html.grouping.HCUL;
Expand Down Expand Up @@ -99,12 +100,22 @@ private IHCNode _createError (@Nonnull final String sMsg)
private void _checkSettings (@Nonnull final HCOL aOL)
{
// Check that public URL is set
if (StringHelper.hasNoText (SMPServerConfiguration.getPublicServerURL ()))

final String sPublicUrl = SMPServerConfiguration.getPublicServerURL ();
if (StringHelper.hasNoText (sPublicUrl))
{
aOL.addItem (_createWarning ("The public server URL is not configured"),
div ("The configuration file property ").addChild (code (SMPServerConfiguration.KEY_SMP_PUBLIC_URL))
.addChild (" is not set. This property is usually required to create valid Internet-URLs."));
}
else
if (URLHelper.getAsURL (sPublicUrl, false) == null)
{
aOL.addItem (_createError ("The public server URL configuration is invalid."),
div ("The configuration file property ").addChild (code (SMPServerConfiguration.KEY_SMP_PUBLIC_URL))
.addChild (" is not a valid URL: ")
.addChild (code (sPublicUrl)));
}

// Check that the global debug setting is off
if (GlobalDebug.isDebugMode ())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class PageSecureTransportProfiles extends AbstractSMPWebPageForm <ISMPTra
private static final ICommonsSet <String> DEFAULT_PROFILE_IDS;
static
{
// Use all non-deprecated ones
// Use all active ones
DEFAULT_PROFILES.addAll (ESMPTransportProfile.values (), x -> x.getState () == ESMPTransportProfileState.ACTIVE);
DEFAULT_PROFILE_IDS = new CommonsHashSet <> (DEFAULT_PROFILES, ESMPTransportProfile::getID);
}
Expand Down Expand Up @@ -127,7 +127,7 @@ public EShowList handleAction (@Nonnull final WebPageExecutionContext aWPEC,
{
if (aTransportProfileMgr.createSMPTransportProfile (eTP.getID (),
eTP.getName (),
eTP.isDeprecated ()) != null)
eTP.getState () == ESMPTransportProfileState.DEPRECATED) != null)
{
aSuccessBox.addChild (div ("Successfully created the transport profile '" +
eTP.getName () +
Expand Down Expand Up @@ -202,7 +202,7 @@ protected void showSelectedObject (@Nonnull final WebPageExecutionContext aWPEC,
aForm.addFormGroup (new BootstrapFormGroup ().setLabel ("ID").setCtrl (aSelectedObject.getID ()));
aForm.addFormGroup (new BootstrapFormGroup ().setLabel ("Name").setCtrl (aSelectedObject.getName ()));
aForm.addFormGroup (new BootstrapFormGroup ().setLabel ("Deprecated?")
.setCtrl (EPhotonCoreText.getYesOrNo (aSelectedObject.isDeprecated (),
.setCtrl (EPhotonCoreText.getYesOrNo (aSelectedObject.getState () == ESMPTransportProfileState.DEPRECATED,
aDisplayLocale)));

aNodeList.addChild (aForm);
Expand Down Expand Up @@ -239,7 +239,7 @@ protected void showInputForm (@Nonnull final WebPageExecutionContext aWPEC,

aForm.addFormGroup (new BootstrapFormGroup ().setLabel ("Deprecated?")
.setCtrl (new HCCheckBox (new RequestFieldBoolean (FIELD_DEPRECATED,
aSelectedObject != null ? aSelectedObject.isDeprecated ()
aSelectedObject != null ? aSelectedObject.getState () == ESMPTransportProfileState.DEPRECATED
: DEFAULT_DEPRECATED)))
.setHelpText ("Is the transport profile deprecated?")
.setErrorList (aFormErrors.getListOfField (FIELD_DEPRECATED)));
Expand Down Expand Up @@ -330,7 +330,8 @@ protected void showListOfExistingObjects (@Nonnull final WebPageExecutionContext
final HCRow aRow = aTable.addBodyRow ();
aRow.addCell (new HCA (aViewLink).addChild (aCurObject.getID ()));
aRow.addCell (aCurObject.getName ());
aRow.addCell (EPhotonCoreText.getYesOrNo (aCurObject.isDeprecated (), aDisplayLocale));
aRow.addCell (EPhotonCoreText.getYesOrNo (aCurObject.getState () == ESMPTransportProfileState.DEPRECATED,
aDisplayLocale));

aRow.addCell (createEditLink (aWPEC, aCurObject, "Edit " + aCurObject.getID ()),
new HCTextNode (" "),
Expand Down

0 comments on commit 894d077

Please sign in to comment.