use of com.helger.peppol.app.mgr.ISMLConfigurationManager in project peppol-practical by phax.
the class PagePublicToolsSMPSML method _deleteSMPfromSML.
private void _deleteSMPfromSML(@Nonnull final WebPageExecutionContext aWPEC, @Nonnull final FormErrorList aFormErrors) {
final HCNodeList aNodeList = aWPEC.getNodeList();
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
final ISMLConfigurationManager aSMLConfigurationMgr = PPMetaManager.getSMLConfigurationMgr();
final String sSMLID = aWPEC.params().getAsString(FIELD_SML_ID);
final ISMLConfiguration aSMLInfo = aSMLConfigurationMgr.getSMLInfoOfID(sSMLID);
final String sSMPID = aWPEC.params().getAsString(FIELD_SMP_ID);
final IFileItem aKeyStoreFile = aWPEC.params().getAsFileItem(FIELD_KEYSTORE);
final String sKeyStorePassword = aWPEC.params().getAsString(FIELD_KEYSTORE_PW);
if (aSMLInfo == null)
aFormErrors.addFieldError(FIELD_SML_ID, "A valid SML must be selected!");
if (StringHelper.hasNoText(sSMPID))
aFormErrors.addFieldError(FIELD_SMP_ID, "A non-empty SMP ID must be provided!");
else if (!RegExHelper.stringMatchesPattern(CPPApp.PATTERN_SMP_ID, sSMPID))
aFormErrors.addFieldError(FIELD_SMP_ID, "The provided SMP ID contains invalid characters. It must match the following regular expression: " + CPPApp.PATTERN_SMP_ID);
final SSLSocketFactory aSocketFactory = _loadKeyStoreAndCreateSSLSocketFactory(EKeyStoreType.JKS, SECURITY_PROVIDER, aKeyStoreFile, sKeyStorePassword, aFormErrors, aDisplayLocale);
if (aFormErrors.isEmpty()) {
try {
final ManageServiceMetadataServiceCaller aCaller = _create(aSMLInfo.getSMLInfo(), aSocketFactory);
aCaller.delete(sSMPID);
final String sMsg = "Successfully deleted SMP '" + sSMPID + "' from the SML '" + aSMLInfo.getManagementServiceURL() + "'.";
LOGGER.info(sMsg);
aNodeList.addChild(success(sMsg));
AuditHelper.onAuditExecuteSuccess("smp-sml-delete", sSMPID, aSMLInfo.getManagementServiceURL());
} catch (final Exception ex) {
final String sMsg = "Error deleting SMP '" + sSMPID + "' from the SML '" + aSMLInfo.getManagementServiceURL() + "'.";
aNodeList.addChild(error(sMsg).addChild(AppCommonUI.getTechnicalDetailsUI(ex, true)));
AuditHelper.onAuditExecuteFailure("smp-sml-delete", sSMPID, aSMLInfo.getManagementServiceURL(), ex.getClass(), ex.getMessage());
}
} else
aNodeList.addChild(BootstrapWebPageUIHandler.INSTANCE.createIncorrectInputBox(aWPEC));
}
use of com.helger.peppol.app.mgr.ISMLConfigurationManager in project peppol-practical by phax.
the class PagePublicToolsSMPSML method _updateSMPatSML.
private void _updateSMPatSML(@Nonnull final WebPageExecutionContext aWPEC, @Nonnull final FormErrorList aFormErrors) {
final HCNodeList aNodeList = aWPEC.getNodeList();
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
final ISMLConfigurationManager aSMLConfigurationMgr = PPMetaManager.getSMLConfigurationMgr();
final String sSMLID = aWPEC.params().getAsString(FIELD_SML_ID);
final ISMLConfiguration aSMLInfo = aSMLConfigurationMgr.getSMLInfoOfID(sSMLID);
final String sSMPID = aWPEC.params().getAsString(FIELD_SMP_ID);
final String sPhysicalAddress = aWPEC.params().getAsString(FIELD_PHYSICAL_ADDRESS);
final String sLogicalAddress = aWPEC.params().getAsString(FIELD_LOGICAL_ADDRESS);
final IFileItem aKeyStoreFile = aWPEC.params().getAsFileItem(FIELD_KEYSTORE);
final String sKeyStorePassword = aWPEC.params().getAsString(FIELD_KEYSTORE_PW);
final boolean bIsPeppol = aSMLInfo != null && aSMLInfo.getSMPAPIType() == ESMPAPIType.PEPPOL;
if (aSMLInfo == null)
aFormErrors.addFieldError(FIELD_SML_ID, "A valid SML must be selected!");
if (StringHelper.hasNoText(sSMPID))
aFormErrors.addFieldError(FIELD_SMP_ID, "A non-empty SMP ID must be provided!");
else if (!RegExHelper.stringMatchesPattern(CPPApp.PATTERN_SMP_ID, sSMPID))
aFormErrors.addFieldError(FIELD_SMP_ID, "The provided SMP ID contains invalid characters. It must match the following regular expression: " + CPPApp.PATTERN_SMP_ID);
if (StringHelper.hasNoText(sPhysicalAddress))
aFormErrors.addFieldError(FIELD_PHYSICAL_ADDRESS, "A physical address must be provided!");
else if (!RegExHelper.stringMatchesPattern(IPV4Addr.PATTERN_IPV4, sPhysicalAddress))
aFormErrors.addFieldError(FIELD_PHYSICAL_ADDRESS, "The provided physical address does not seem to be an IPv4 address!");
else {
final String[] aParts = StringHelper.getExplodedArray('.', sPhysicalAddress, 4);
final byte[] aBytes = new byte[] { (byte) StringParser.parseInt(aParts[0], -1), (byte) StringParser.parseInt(aParts[1], -1), (byte) StringParser.parseInt(aParts[2], -1), (byte) StringParser.parseInt(aParts[3], -1) };
try {
InetAddress.getByAddress(aBytes);
} catch (final Exception ex) {
aFormErrors.addFieldError(FIELD_PHYSICAL_ADDRESS, "The provided IP address does not resolve to a valid host. " + AppCommonUI.getTechnicalDetailsString(ex, false));
}
}
if (StringHelper.hasNoText(sLogicalAddress))
aFormErrors.addFieldError(FIELD_LOGICAL_ADDRESS, "A logical address must be provided in the form 'http://smp.example.org'!");
else {
final URL aURL = URLHelper.getAsURL(sLogicalAddress);
if (aURL == null)
aFormErrors.addFieldError(FIELD_LOGICAL_ADDRESS, "The provided logical address seems not be a URL! Please use the form 'http://smp.example.org'");
else {
if (bIsPeppol) {
if (!"http".equals(aURL.getProtocol()))
aFormErrors.addFieldError(FIELD_LOGICAL_ADDRESS, "The provided logical address must use the 'http' protocol and may not use the '" + aURL.getProtocol() + "' protocol. According to the Peppol SMP specification, no other protocols than 'http' are allowed!");
// -1 means default port
if (aURL.getPort() != 80 && aURL.getPort() != -1)
aFormErrors.addFieldError(FIELD_LOGICAL_ADDRESS, "The provided logical address must use the default http port 80 and not port " + aURL.getPort() + ". According to the Peppol SMP specification, no other ports are allowed!");
if (StringHelper.hasText(aURL.getPath()) && !"/".equals(aURL.getPath()))
aFormErrors.addFieldError(FIELD_LOGICAL_ADDRESS, "The provided logical address may not contain a path (" + aURL.getPath() + ") because according to the Peppol SMP specifications it must run in the root (/) path!");
}
}
}
final SSLSocketFactory aSocketFactory = _loadKeyStoreAndCreateSSLSocketFactory(EKeyStoreType.JKS, SECURITY_PROVIDER, aKeyStoreFile, sKeyStorePassword, aFormErrors, aDisplayLocale);
if (aFormErrors.isEmpty()) {
try {
final ManageServiceMetadataServiceCaller aCaller = _create(aSMLInfo.getSMLInfo(), aSocketFactory);
aCaller.update(sSMPID, sPhysicalAddress, sLogicalAddress);
final String sMsg = "Successfully updated SMP '" + sSMPID + "' with physical address '" + sPhysicalAddress + "' and logical address '" + sLogicalAddress + "' at the SML '" + aSMLInfo.getManagementServiceURL() + "'.";
LOGGER.info(sMsg);
aNodeList.addChild(success(sMsg));
AuditHelper.onAuditExecuteSuccess("smp-sml-update", sSMPID, sPhysicalAddress, sLogicalAddress, aSMLInfo.getManagementServiceURL());
} catch (final Exception ex) {
final String sMsg = "Error updating SMP '" + sSMPID + "' with physical address '" + sPhysicalAddress + "' and logical address '" + sLogicalAddress + "' to the SML '" + aSMLInfo.getManagementServiceURL() + "'.";
aNodeList.addChild(error(sMsg).addChild(AppCommonUI.getTechnicalDetailsUI(ex, true)));
AuditHelper.onAuditExecuteFailure("smp-sml-update", sSMPID, sPhysicalAddress, sLogicalAddress, aSMLInfo.getManagementServiceURL(), ex.getClass(), ex.getMessage());
}
} else
aNodeList.addChild(BootstrapWebPageUIHandler.INSTANCE.createIncorrectInputBox(aWPEC));
}
use of com.helger.peppol.app.mgr.ISMLConfigurationManager in project peppol-practical by phax.
the class PagePublicToolsTestEndpoints method validateAndSaveInputParameters.
@Override
protected void validateAndSaveInputParameters(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final TestEndpoint aSelectedObject, @Nonnull final FormErrorList aFormErrors, @Nonnull final EWebPageFormAction eFormAction) {
final TestEndpointManager aTestEndpointMgr = PPMetaManager.getTestEndpointMgr();
final ISMLConfigurationManager aSMLConfigurationMgr = PPMetaManager.getSMLConfigurationMgr();
final String sCompanyName = aWPEC.params().getAsString(FIELD_COMPANY_NAME);
final String sContactPerson = aWPEC.params().getAsString(FIELD_CONTACT_PERSON);
final String sParticipantIDIssuer = aWPEC.params().getAsString(FIELD_PARTICIPANT_ID_ISSUER);
final EPredefinedParticipantIdentifierScheme eScheme = AppHelper.getParticipantIdentifierSchemeOfID(sParticipantIDIssuer);
final String sParticipantIDValue = aWPEC.params().getAsString(FIELD_PARTICIPANT_ID_VALUE);
final String sTransportProfile = aWPEC.params().getAsString(FIELD_TRANSPORT_PROFILE);
final ESMPTransportProfile eTransportProfile = ESMPTransportProfile.getFromIDOrNull(sTransportProfile);
final String sTransportProfileName = AppHelper.getSMPTransportProfileShortName(eTransportProfile);
final String sSMLID = aWPEC.params().getAsString(FIELD_SML);
final ISMLConfiguration aSML = aSMLConfigurationMgr.getSMLInfoOfID(sSMLID);
if (StringHelper.hasNoText(sCompanyName))
aFormErrors.addFieldError(FIELD_COMPANY_NAME, "Please provide the company name");
if (StringHelper.hasNoText(sParticipantIDIssuer))
aFormErrors.addFieldError(FIELD_PARTICIPANT_ID_ISSUER, "Please select a participant identifier issuing agency");
else if (eScheme == null)
aFormErrors.addFieldError(FIELD_PARTICIPANT_ID_ISSUER, "Please select a valid participant identifier issuing agency");
if (StringHelper.hasNoText(sParticipantIDValue))
aFormErrors.addFieldError(FIELD_PARTICIPANT_ID_VALUE, "Please provide a participant identifier value");
if (eTransportProfile == null)
aFormErrors.addFieldError(FIELD_TRANSPORT_PROFILE, "Please select a transport profile");
if (aSML == null)
aFormErrors.addFieldError(FIELD_SML, "Please select an SML where the participant is registered");
if (aFormErrors.isEmpty()) {
// Check if participant ID and transport profile are already registered
final TestEndpoint aSameIDTestEndpoint = aTestEndpointMgr.getTestEndpoint(sParticipantIDIssuer, sParticipantIDValue, eTransportProfile);
if (aSameIDTestEndpoint != null && !aSameIDTestEndpoint.equals(aSelectedObject))
aFormErrors.addFieldError(FIELD_TRANSPORT_PROFILE, "Another test endpoint for " + sParticipantIDIssuer + ":" + sParticipantIDValue + " and transport profile " + sTransportProfileName + " is already registered!");
}
if (aFormErrors.isEmpty()) {
if (eFormAction.isEdit()) {
aTestEndpointMgr.updateTestEndpoint(aSelectedObject.getID(), sCompanyName, sContactPerson, sParticipantIDIssuer, sParticipantIDValue, eTransportProfile, aSML);
aWPEC.postRedirectGetInternal(success("Successfully edited the test endpoint for " + sParticipantIDIssuer + ":" + sParticipantIDValue + " with transport profile " + sTransportProfileName));
} else {
aTestEndpointMgr.createTestEndpoint(sCompanyName, sContactPerson, sParticipantIDIssuer, sParticipantIDValue, eTransportProfile, aSML);
aWPEC.postRedirectGetInternal(success("Successfully added the new test endpoint for " + sParticipantIDIssuer + ":" + sParticipantIDValue + " with transport profile " + sTransportProfileName));
}
}
}
use of com.helger.peppol.app.mgr.ISMLConfigurationManager in project peppol-practical by phax.
the class PageSecureSMLConfiguration method showListOfExistingObjects.
@Override
protected void showListOfExistingObjects(@Nonnull final WebPageExecutionContext aWPEC) {
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
final HCNodeList aNodeList = aWPEC.getNodeList();
final ISMLConfigurationManager aSMLConfigurationMgr = PPMetaManager.getSMLConfigurationMgr();
aNodeList.addChild(info("This page lets you create custom SML configurations that can be used for registration."));
final BootstrapButtonToolbar aToolbar = new BootstrapButtonToolbar(aWPEC);
aToolbar.addButton("Create new SML configuration", createCreateURL(aWPEC), EDefaultIcon.NEW);
aNodeList.addChild(aToolbar);
final HCTable aTable = new HCTable(new DTCol("ID"), new DTCol("Name").setInitialSorting(ESortOrder.ASCENDING), new DTCol("DNS Zone"), new DTCol("Management Service URL"), new DTCol("Client Cert?"), new DTCol("SMP API type"), new DTCol("SMP ID type"), new DTCol("Production?"), new BootstrapDTColAction(aDisplayLocale)).setID(getID());
for (final ISMLConfiguration aCurObject : aSMLConfigurationMgr.getAll()) {
final ISimpleURL aViewLink = createViewURL(aWPEC, aCurObject);
final HCRow aRow = aTable.addBodyRow();
aRow.addCell(aCurObject.getID());
aRow.addCell(new HCA(aViewLink).addChild(aCurObject.getDisplayName()));
aRow.addCell(aCurObject.getDNSZone());
aRow.addCell(aCurObject.getManagementServiceURL());
aRow.addCell(EPhotonCoreText.getYesOrNo(aCurObject.isClientCertificateRequired(), aDisplayLocale));
aRow.addCell(aCurObject.getSMPAPIType().getDisplayName());
aRow.addCell(aCurObject.getSMPIdentifierType().getDisplayName());
aRow.addCell(EPhotonCoreText.getYesOrNo(aCurObject.isProduction(), aDisplayLocale));
aRow.addCell(createEditLink(aWPEC, aCurObject, "Edit " + aCurObject.getID()), new HCTextNode(" "), createCopyLink(aWPEC, aCurObject, "Copy " + aCurObject.getID()), new HCTextNode(" "), isActionAllowed(aWPEC, EWebPageFormAction.DELETE, aCurObject) ? createDeleteLink(aWPEC, aCurObject, "Delete " + aCurObject.getDisplayName()) : createEmptyAction());
}
final DataTables aDataTables = BootstrapDataTables.createDefaultDataTables(aWPEC, aTable);
aNodeList.addChild(aTable).addChild(aDataTables);
}
use of com.helger.peppol.app.mgr.ISMLConfigurationManager in project peppol-practical by phax.
the class PageSecureSMLConfiguration method validateAndSaveInputParameters.
@Override
protected void validateAndSaveInputParameters(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMLConfiguration aSelectedObject, @Nonnull final FormErrorList aFormErrors, @Nonnull final EWebPageFormAction eFormAction) {
final boolean bEdit = eFormAction.isEdit();
final ISMLConfigurationManager aSMLConfigurationMgr = PPMetaManager.getSMLConfigurationMgr();
final String sID = aWPEC.params().getAsString(FIELD_ID);
final String sDisplayName = aWPEC.params().getAsString(FIELD_DISPLAY_NAME);
final String sDNSZone = aWPEC.params().getAsString(FIELD_DNS_ZONE);
final String sManagementAddressURL = aWPEC.params().getAsString(FIELD_MANAGEMENT_ADDRESS_URL);
final boolean bClientCertificateRequired = aWPEC.params().isCheckBoxChecked(FIELD_CLIENT_CERTIFICATE_REQUIRED, DEFAULT_CLIENT_CERTIFICATE_REQUIRED);
final String sSMPAPIType = aWPEC.params().getAsString(FIELD_SMP_API_TYPE);
final ESMPAPIType eSMPAPIType = ESMPAPIType.getFromIDOrNull(sSMPAPIType);
final String sSMPIdentifierType = aWPEC.params().getAsString(FIELD_SMP_ID_TYPE);
final ESMPIdentifierType eSMPIdentifierType = ESMPIdentifierType.getFromIDOrNull(sSMPIdentifierType);
final boolean bProduction = aWPEC.params().isCheckBoxChecked(FIELD_PRODUCTION, false);
// validations
if (StringHelper.hasNoText(sID))
aFormErrors.addFieldError(FIELD_ID, "The SML configuration ID must not be empty!");
else if (ISMLConfigurationManager.ID_AUTO_DETECT.equals(sID))
aFormErrors.addFieldError(FIELD_ID, "This SML configuration ID is reserved!");
else {
final ISMLConfiguration aExisting = aSMLConfigurationMgr.getSMLInfoOfID(sID);
if (bEdit) {
// Expect aExistring == aSelectedObject
if (aExisting == null)
aFormErrors.addFieldError(FIELD_ID, "Invalid SML configuration ID provided!");
else if (aExisting != aSelectedObject)
aFormErrors.addFieldError(FIELD_ID, "Another SML configuration with the same ID already exists!");
} else {
if (aExisting != null)
aFormErrors.addFieldError(FIELD_ID, "Another SML configuration with the same ID already exists!");
}
}
if (StringHelper.hasNoText(sDisplayName))
aFormErrors.addFieldError(FIELD_DISPLAY_NAME, "The SML configuration name must not be empty!");
if (StringHelper.hasNoText(sDNSZone))
aFormErrors.addFieldError(FIELD_DNS_ZONE, "The DNS Zone must not be empty!");
if (StringHelper.hasNoText(sManagementAddressURL))
aFormErrors.addFieldError(FIELD_MANAGEMENT_ADDRESS_URL, "The Management Address URL must not be empty!");
else {
final URL aURL = URLHelper.getAsURL(sManagementAddressURL);
if (aURL == null)
aFormErrors.addFieldError(FIELD_MANAGEMENT_ADDRESS_URL, "The Management Address URL is not a valid URL!");
else if (!"https".equals(aURL.getProtocol()) && !"http".equals(aURL.getProtocol()))
aFormErrors.addFieldError(FIELD_MANAGEMENT_ADDRESS_URL, "The Management Address URL should only be use the 'http' or the 'https' protocol!");
}
if (StringHelper.hasNoText(sSMPAPIType))
aFormErrors.addFieldError(FIELD_SMP_API_TYPE, "An SMP API type must be selected!");
else if (eSMPAPIType == null)
aFormErrors.addFieldError(FIELD_SMP_API_TYPE, "A valid SMP API type must be selected!");
if (StringHelper.hasNoText(sSMPIdentifierType))
aFormErrors.addFieldError(FIELD_SMP_ID_TYPE, "An SMP identifier type must be selected!");
else if (eSMPIdentifierType == null)
aFormErrors.addFieldError(FIELD_SMP_ID_TYPE, "A valid SMP identifier type must be selected!");
if (aFormErrors.isEmpty()) {
// Lowercase with the US locale - not display locale specific
final String sDNSZoneLC = sDNSZone.toLowerCase(Locale.US);
if (bEdit) {
aSMLConfigurationMgr.updateSMLInfo(aSelectedObject.getID(), sDisplayName, sDNSZoneLC, sManagementAddressURL, bClientCertificateRequired, eSMPAPIType, eSMPIdentifierType, bProduction);
aWPEC.postRedirectGetInternal(success("The SML configuration '" + sDisplayName + "' was successfully edited."));
} else {
aSMLConfigurationMgr.createSMLInfo(sID, sDisplayName, sDNSZoneLC, sManagementAddressURL, bClientCertificateRequired, eSMPAPIType, eSMPIdentifierType, bProduction);
aWPEC.postRedirectGetInternal(success("The new SML configuration '" + sDisplayName + "' was successfully created."));
}
}
}
Aggregations