use of com.helger.peppol.sml.ISMLInfo in project phoss-smp by phax.
the class APIExecutorMigrationOutboundStartPut method invokeAPI.
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 sServiceGroupID = aPathVariables.get(SMPRestFilter.PARAM_SERVICE_GROUP_ID);
final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider(aRequestScope, sServiceGroupID);
// Is the writable API disabled?
if (SMPMetaManager.getSettings().isRESTWritableAPIDisabled()) {
throw new SMPPreconditionFailedException("The writable REST API is disabled. migrationOutboundStart will not be executed", aDataProvider.getCurrentURI());
}
final String sLogPrefix = "[REST API Migration-Outbound-Start] ";
LOGGER.info(sLogPrefix + "Starting outbound migration for Service Group ID '" + sServiceGroupID + "'");
// Only authenticated user may do so
final BasicAuthClientCredentials aBasicAuth = getMandatoryAuth(aRequestScope.headers());
SMPUserManagerPhoton.validateUserCredentials(aBasicAuth);
final ISMPSettings aSettings = SMPMetaManager.getSettings();
final ISMLInfo aSMLInfo = aSettings.getSMLInfo();
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPParticipantMigrationManager aParticipantMigrationMgr = SMPMetaManager.getParticipantMigrationMgr();
if (aSMLInfo == null) {
throw new SMPPreconditionFailedException("Currently no SML is available. Please select it in the UI at the 'SMP Settings' page", aDataProvider.getCurrentURI());
}
if (!aSettings.isSMLEnabled()) {
throw new SMPPreconditionFailedException("SML Connection is not enabled hence no participant can be migrated", aDataProvider.getCurrentURI());
}
final IParticipantIdentifier aServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID);
if (aServiceGroupID == null) {
// Invalid identifier
throw SMPBadRequestException.failedToParseSG(sServiceGroupID, aDataProvider.getCurrentURI());
}
// Check that service group exists
if (!aServiceGroupMgr.containsSMPServiceGroupWithID(aServiceGroupID)) {
throw new SMPBadRequestException("The Service Group '" + sServiceGroupID + "' does not exist", aDataProvider.getCurrentURI());
}
// Ensure no existing migration is in process
if (aParticipantMigrationMgr.containsOutboundMigrationInProgress(aServiceGroupID)) {
throw new SMPBadRequestException("The outbound Participant Migration of the Service Group '" + sServiceGroupID + "' is already in progress", aDataProvider.getCurrentURI());
}
String sMigrationKey = null;
try {
final ManageParticipantIdentifierServiceCaller aCaller = new ManageParticipantIdentifierServiceCaller(aSMLInfo);
aCaller.setSSLSocketFactory(SMPKeyManager.getInstance().createSSLContext().getSocketFactory());
// Create a random migration key,
// Than call SML
sMigrationKey = aCaller.prepareToMigrate(aServiceGroupID, SMPServerConfiguration.getSMLSMPID());
LOGGER.info(sLogPrefix + "Successfully called prepareToMigrate on SML. Created migration key is '" + sMigrationKey + "'");
} catch (final BadRequestFault | InternalErrorFault | NotFoundFault | UnauthorizedFault | ClientTransportException ex) {
throw new SMPSMLException("Failed to call prepareToMigrate on SML for Service Group '" + sServiceGroupID + "'", ex);
}
// Remember internally
final ISMPParticipantMigration aMigration = aParticipantMigrationMgr.createOutboundParticipantMigration(aServiceGroupID, sMigrationKey);
if (aMigration == null) {
throw new SMPInternalErrorException("Failed to create outbound Participant Migration for '" + sServiceGroupID + "' internally");
}
LOGGER.info(sLogPrefix + "Successfully created outbound Participant Migration with ID '" + aMigration.getID() + "' internally.");
// Build result
final IMicroDocument aResponseDoc = new MicroDocument();
final IMicroElement eRoot = aResponseDoc.appendElement("migrationOutboundResponse");
eRoot.setAttribute("success", true);
eRoot.appendElement(XML_ELEMENT_PARTICIPANT_ID).appendText(sServiceGroupID);
eRoot.appendElement(XML_ELEMENT_MIGRATION_KEY).appendText(sMigrationKey);
final XMLWriterSettings aXWS = new XMLWriterSettings().setIndent(EXMLSerializeIndent.INDENT_AND_ALIGN);
aUnifiedResponse.setContentAndCharset(MicroWriter.getNodeAsString(aResponseDoc, aXWS), aXWS.getCharset()).setMimeType(new MimeType(CMimeType.APPLICATION_XML).addParameter(CMimeType.PARAMETER_NAME_CHARSET, aXWS.getCharset().name())).disableCaching();
}
use of com.helger.peppol.sml.ISMLInfo in project phoss-smp by phax.
the class SMPStatusProvider method getDefaultStatusData.
@Nonnull
@ReturnsMutableCopy
public static IJsonObject getDefaultStatusData(final boolean bDisableLongRunningOperations) {
if (LOGGER.isDebugEnabled())
LOGGER.debug("Building status data");
final StopWatch aSW = StopWatch.createdStarted();
final ISMPSettings aSettings = SMPMetaManager.getSettings();
final LocalDateTime aNow = PDTFactory.getCurrentLocalDateTime();
final ISMLInfo aSMLInfo = aSettings.getSMLInfo();
final IJsonObject aStatusData = new JsonObject();
// Since 5.0.7
aStatusData.add("build.timestamp", CSMPServer.getBuildTimestamp());
// Since 5.3.3
aStatusData.addIfNotNull("startup.datetime", PDTWebDateHelper.getAsStringXSD(SMPWebAppListener.getStartupDateTime()));
aStatusData.add("status.datetime", PDTWebDateHelper.getAsStringXSD(PDTFactory.getCurrentOffsetDateTimeUTC()));
aStatusData.add("version.smp", CSMPServer.getVersionNumber());
aStatusData.add("version.java", SystemProperties.getJavaVersion());
aStatusData.add("global.debug", GlobalDebug.isDebugMode());
aStatusData.add("global.production", GlobalDebug.isProductionMode());
aStatusData.add("smp.backend", SMPServerConfiguration.getBackend());
aStatusData.add("smp.mode", SMPWebAppConfiguration.isTestVersion() ? "test" : "production");
aStatusData.add("smp.resttype", SMPServerConfiguration.getRESTType().getID());
aStatusData.add("smp.identifiertype", SMPServerConfiguration.getIdentifierType().getID());
aStatusData.add("smp.id", SMPServerConfiguration.getSMLSMPID());
aStatusData.add("smp.writable-rest-api.enabled", !aSettings.isRESTWritableAPIDisabled());
// New in 5.1.0
aStatusData.add("smp.publicurl", SMPServerConfiguration.getPublicServerURL());
// New in 5.1.0
aStatusData.add("smp.forceroot", SMPServerConfiguration.isForceRoot());
// New in 5.2.0
aStatusData.add("smp.rest.log-exceptions", SMPServerConfiguration.isRESTLogExceptions());
// New in 5.2.1
aStatusData.add("smp.rest.payload-on-error", SMPServerConfiguration.isRESTPayloadOnError());
// SML information
aStatusData.add("smp.sml.enabled", aSettings.isSMLEnabled());
aStatusData.add("smp.sml.needed", aSettings.isSMLRequired());
if (aSMLInfo != null) {
aStatusData.add("smp.sml.url", aSMLInfo.getManagementServiceURL());
aStatusData.add("smp.sml.dnszone", aSMLInfo.getDNSZone());
}
aStatusData.addIfNotNull("smp.sml.connection-timeout-ms", SMPServerConfiguration.getSMLConnectionTimeoutMS());
aStatusData.add("smp.sml.request-timeout-ms", SMPServerConfiguration.getSMLRequestTimeoutMS());
// Directory information
aStatusData.add("smp.pd.enabled", aSettings.isDirectoryIntegrationEnabled());
// New in 5.1.0
aStatusData.add("smp.pd.needed", aSettings.isDirectoryIntegrationRequired());
aStatusData.add("smp.pd.auto-update", aSettings.isDirectoryIntegrationAutoUpdate());
aStatusData.add("smp.pd.hostname", aSettings.getDirectoryHostName());
// Certificate information
final boolean bCertConfigOk = SMPKeyManager.isKeyStoreValid();
aStatusData.add("smp.certificate.configuration-valid", bCertConfigOk);
if (bCertConfigOk) {
final SMPKeyManager aKeyMgr = SMPKeyManager.getInstance();
final PrivateKeyEntry aKeyEntry = aKeyMgr.getPrivateKeyEntry();
if (aKeyEntry != null) {
final Certificate[] aChain = aKeyEntry.getCertificateChain();
if (aChain.length > 0 && aChain[0] instanceof X509Certificate) {
final X509Certificate aX509Cert = (X509Certificate) aChain[0];
aStatusData.add("smp.certificate.issuer", aX509Cert.getIssuerX500Principal().getName());
aStatusData.add("smp.certificate.subject", aX509Cert.getSubjectX500Principal().getName());
final LocalDateTime aNotAfter = PDTFactory.createLocalDateTime(aX509Cert.getNotAfter());
final boolean bIsExpired = aNow.isAfter(aNotAfter);
aStatusData.add("smp.certificate.expired", bIsExpired);
}
}
}
// Proxy configuration (since 5.2.0)
aStatusData.add("proxy.http.configured", SMPServerConfiguration.getAsHttpProxySettings() != null);
aStatusData.add("proxy.https.configured", SMPServerConfiguration.getAsHttpsProxySettings() != null);
aStatusData.add("proxy.username.configured", StringHelper.hasText(SMPServerConfiguration.getProxyUsername()));
// CSP configuration (since 5.2.6)
aStatusData.add("csp.enabled", SMPWebAppConfiguration.isCSPEnabled());
aStatusData.add("csp.reporting.only", SMPWebAppConfiguration.isCSPReportingOnly());
aStatusData.add("csp.reporting.enabled", SMPWebAppConfiguration.isCSPReportingEnabled());
// Add SPI data as well
for (final ISMPStatusProviderExtensionSPI aImpl : LIST) {
final ICommonsOrderedMap<String, ?> aMap = aImpl.getAdditionalStatusData(bDisableLongRunningOperations);
aStatusData.addAll(aMap);
}
final long nMillis = aSW.stopAndGetMillis();
if (nMillis > 100)
LOGGER.info("Finished building status data after " + nMillis + " milliseconds which is considered to be too long");
else if (LOGGER.isDebugEnabled())
LOGGER.debug("Finished building status data");
return aStatusData;
}
use of com.helger.peppol.sml.ISMLInfo in project phoss-smp by phax.
the class PageSecureSMPSettings method validateAndSaveInputParameters.
@Override
protected void validateAndSaveInputParameters(@Nonnull final WebPageExecutionContext aWPEC, @Nonnull final ISMPSettings aObject, @Nonnull final FormErrorList aFormErrors, @Nonnull final EWebPageSimpleFormAction eSimpleFormAction) {
final String sDirectoryName = SMPWebAppConfiguration.getDirectoryName();
final boolean bRESTWritableAPIDisabled = aWPEC.params().isCheckBoxChecked(FIELD_SMP_REST_WRITABLE_API_DISABLED, SMPServerConfiguration.DEFAULT_SMP_REST_WRITABLE_API_DISABLED);
final boolean bSMLActive = aWPEC.params().isCheckBoxChecked(FIELD_SML_ACTIVE, SMPServerConfiguration.DEFAULT_SML_ENABLED);
final boolean bSMLRequired = aWPEC.params().isCheckBoxChecked(FIELD_SML_REQUIRED, SMPServerConfiguration.DEFAULT_SML_REQUIRED);
final String sSMLInfoID = aWPEC.params().getAsString(FIELD_SML_INFO);
final ISMLInfo aSMLInfo = SMPMetaManager.getSMLInfoMgr().getSMLInfoOfID(sSMLInfoID);
final boolean bDirectoryIntegrationEnabled = aWPEC.params().isCheckBoxChecked(FIELD_SMP_DIRECTORY_INTEGRATION_ENABLED, SMPServerConfiguration.DEFAULT_SMP_DIRECTORY_INTEGRATION_ENABLED);
final boolean bDirectoryIntegrationRequired = aWPEC.params().isCheckBoxChecked(FIELD_SML_DIRECTORY_INTEGRATION_REQUIRED, SMPServerConfiguration.DEFAULT_SMP_DIRECTORY_INTEGRATION_REQUIRED);
final boolean bDirectoryIntegrationAutoUpdate = aWPEC.params().isCheckBoxChecked(FIELD_SMP_DIRECTORY_INTEGRATION_AUTO_UPDATE, SMPServerConfiguration.DEFAULT_SMP_DIRECTORY_INTEGRATION_AUTO_UPDATE);
final String sDirectoryHostName = aWPEC.params().getAsString(FIELD_SMP_DIRECTORY_HOSTNAME);
if (bSMLActive && !SMPKeyManager.isKeyStoreValid())
aFormErrors.addFieldError(FIELD_SML_ACTIVE, "SML connection cannot be activated, because the configured keystore is invalid!");
if (aSMLInfo == null) {
if (bSMLActive)
aFormErrors.addFieldError(FIELD_SML_INFO, "An SML configuration must be selected if SML is active.");
}
if (StringHelper.hasNoText(sDirectoryHostName)) {
if (bDirectoryIntegrationEnabled)
aFormErrors.addFieldError(FIELD_SMP_DIRECTORY_HOSTNAME, sDirectoryName + " hostname may not be empty if " + sDirectoryName + " intergration is enabled.");
} else if (!URLValidator.isValid(sDirectoryHostName))
aFormErrors.addFieldError(FIELD_SMP_DIRECTORY_HOSTNAME, sDirectoryName + " hostname must be a valid URL.");
if (aFormErrors.isEmpty()) {
SMPMetaManager.getSettingsMgr().updateSettings(bRESTWritableAPIDisabled, bDirectoryIntegrationEnabled, bDirectoryIntegrationRequired, bDirectoryIntegrationAutoUpdate, sDirectoryHostName, bSMLActive, bSMLRequired, aSMLInfo == null ? null : aSMLInfo.getID());
aWPEC.postRedirectGetInternal(success("The SMP settings were successfully saved."));
}
}
use of com.helger.peppol.sml.ISMLInfo in project phoss-smp 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 ISMLInfoManager aSMLInfoMgr = SMPMetaManager.getSMLInfoMgr();
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("Name").setInitialSorting(ESortOrder.ASCENDING), new DTCol("DNS Zone"), new DTCol("Management Service URL"), new DTCol("Client Cert?"), new BootstrapDTColAction(aDisplayLocale)).setID(getID());
for (final ISMLInfo aCurObject : aSMLInfoMgr.getAllSMLInfos()) {
final ISimpleURL aViewLink = createViewURL(aWPEC, aCurObject);
final HCRow aRow = aTable.addBodyRow();
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(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.sml.ISMLInfo in project phoss-smp by phax.
the class PageSecureSMLRegistration method _registerSMPtoSML.
private void _registerSMPtoSML(@Nonnull final WebPageExecutionContext aWPEC, @Nonnull final FormErrorList aFormErrors) {
final HCNodeList aNodeList = aWPEC.getNodeList();
final ESMPRESTType eRESTType = SMPServerConfiguration.getRESTType();
final boolean bUsePeppolConstraints = eRESTType.isPeppol();
final boolean bUsePathConstraints = eRESTType.isPathConstraint();
final String sSMLID = aWPEC.params().getAsString(FIELD_SML_ID);
final ISMLInfo aSMLInfo = SMPMetaManager.getSMLInfoMgr().getSMLInfoOfID(sSMLID);
final String sPhysicalAddress = aWPEC.params().getAsString(FIELD_PHYSICAL_ADDRESS);
final String sLogicalAddress = aWPEC.params().getAsString(FIELD_LOGICAL_ADDRESS);
if (aSMLInfo == null)
aFormErrors.addFieldError(FIELD_SML_ID, "A valid SML must be selected!");
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 UnknownHostException ex) {
aFormErrors.addFieldError(FIELD_PHYSICAL_ADDRESS, "The provided IP address does not resolve to a valid host. " + SMPCommonUI.getTechnicalDetailsString(ex));
}
}
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 (!"http".equals(aURL.getProtocol())) {
if (bUsePeppolConstraints || !"https".equals(aURL.getProtocol()))
aFormErrors.addFieldError(FIELD_LOGICAL_ADDRESS, "The provided logical address must use the 'http'" + (bUsePeppolConstraints ? "" : " or the 'https'") + " protocol and may not use the '" + aURL.getProtocol() + "' protocol." + (bUsePeppolConstraints ? " According to the Peppol SMP specification, no other protocols than 'http' are allowed!" : ""));
}
if (bUsePeppolConstraints) {
// -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 (bUsePathConstraints) {
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 SMP specifications it must run in the root (/) path!");
}
}
}
if (aFormErrors.isEmpty()) {
final String sSMPID = SMPServerConfiguration.getSMLSMPID();
try {
final SSLSocketFactory aSocketFactory = SMPKeyManager.getInstance().createSSLContext().getSocketFactory();
final ManageServiceMetadataServiceCaller aCaller = _create(aSMLInfo, aSocketFactory);
aCaller.create(sSMPID, sPhysicalAddress, sLogicalAddress);
final String sMsg = "Successfully registered SMP '" + sSMPID + "' with physical address '" + sPhysicalAddress + "' and logical address '" + sLogicalAddress + "' to the SML '" + aSMLInfo.getManagementServiceURL() + "'.";
LOGGER.info(sMsg);
aNodeList.addChild(success(sMsg));
AuditHelper.onAuditExecuteSuccess("smp-sml-create", sSMPID, sPhysicalAddress, sLogicalAddress, aSMLInfo.getManagementServiceURL());
} catch (final Exception ex) {
final String sMsg = "Error registering SMP '" + sSMPID + "' with physical address '" + sPhysicalAddress + "' and logical address '" + sLogicalAddress + "' to the SML '" + aSMLInfo.getManagementServiceURL() + "'.";
aNodeList.addChild(error(sMsg).addChild(SMPCommonUI.getTechnicalDetailsUI(ex)));
AuditHelper.onAuditExecuteFailure("smp-sml-create", sSMPID, sPhysicalAddress, sLogicalAddress, aSMLInfo.getManagementServiceURL(), ex.getClass(), ex.getMessage());
}
} else
aNodeList.addChild(BootstrapWebPageUIHandler.INSTANCE.createIncorrectInputBox(aWPEC));
}
Aggregations