use of com.helger.phoss.smp.settings.ISMPSettings in project phoss-smp by phax.
the class SMPWebAppListener method initManagers.
@Override
protected void initManagers() {
{
LOGGER.info("Init of ConfigurationFileManager");
final ConfigurationFileManager aCFM = ConfigurationFileManager.getInstance();
aCFM.registerConfigurationFile(new ConfigurationFile(new ClassPathResource("log4j2.xml")).setDescription("Log4J2 configuration").setSyntaxHighlightLanguage(EConfigurationFileSyntax.XML));
aCFM.registerConfigurationFile(new ConfigurationFile(SMPWebAppConfiguration.getSettingsResource()).setDescription("SMP web application configuration").setSyntaxHighlightLanguage(EConfigurationFileSyntax.PROPERTIES));
final IReadableResource aConfigRes = SMPServerConfiguration.getConfigFile().getReadResource();
if (aConfigRes != null) {
aCFM.registerConfigurationFile(new ConfigurationFile(aConfigRes).setDescription("SMP server configuration").setSyntaxHighlightLanguage(EConfigurationFileSyntax.PROPERTIES));
}
aCFM.registerAll(PDClientConfiguration.getConfig());
}
{
LOGGER.info("Init of Directory client stuff");
// If the SMP settings change, the PD client must be re-created
SMPMetaManager.getSettingsMgr().callbacks().add(x -> PDClientProvider.getInstance().resetPDClient());
// Callback on BusinessCard manager - if something happens, notify PD
// server
final ISMPBusinessCardManager aBusinessCardMgr = SMPMetaManager.getBusinessCardMgr();
if (aBusinessCardMgr != null) {
aBusinessCardMgr.bcCallbacks().add(new ISMPBusinessCardCallback() {
public void onSMPBusinessCardCreatedOrUpdated(@Nonnull final ISMPBusinessCard aBusinessCard) {
final ISMPSettings aSettings = SMPMetaManager.getSettings();
if (aSettings.isDirectoryIntegrationEnabled() && aSettings.isDirectoryIntegrationAutoUpdate()) {
// Notify PD server: add
PDClientProvider.getInstance().getPDClient().addServiceGroupToIndex(aBusinessCard.getParticipantIdentifier());
}
}
public void onSMPBusinessCardDeleted(@Nonnull final ISMPBusinessCard aBusinessCard) {
final ISMPSettings aSettings = SMPMetaManager.getSettings();
if (aSettings.isDirectoryIntegrationEnabled() && aSettings.isDirectoryIntegrationAutoUpdate()) {
// Notify PD server: delete
PDClientProvider.getInstance().getPDClient().deleteServiceGroupFromIndex(aBusinessCard.getParticipantIdentifier());
}
}
});
// If a service information is create, updated or deleted, also update
// Business Card at PD
SMPMetaManager.getServiceInformationMgr().serviceInformationCallbacks().add(new ISMPServiceInformationCallback() {
@Override
public void onSMPServiceInformationCreated(@Nonnull final ISMPServiceInformation aServiceInformation) {
final ISMPSettings aSettings = SMPMetaManager.getSettings();
if (aSettings.isDirectoryIntegrationEnabled() && aSettings.isDirectoryIntegrationAutoUpdate()) {
// Only if a business card is present
if (aBusinessCardMgr.containsSMPBusinessCardOfServiceGroup(aServiceInformation.getServiceGroup())) {
// Notify PD server: update
PDClientProvider.getInstance().getPDClient().addServiceGroupToIndex(aServiceInformation.getServiceGroup().getParticipantIdentifier());
}
}
}
@Override
public void onSMPServiceInformationUpdated(@Nonnull final ISMPServiceInformation aServiceInformation) {
onSMPServiceInformationCreated(aServiceInformation);
}
@Override
public void onSMPServiceInformationDeleted(@Nonnull final ISMPServiceInformation aServiceInformation) {
onSMPServiceInformationCreated(aServiceInformation);
}
});
}
}
{
LOGGER.info("Init of HTTP and Proxy settings");
// Register global proxy servers
ProxySelectorProxySettingsManager.setAsDefault(true);
final IProxySettings aProxyHttp = SMPServerConfiguration.getAsHttpProxySettings();
if (aProxyHttp != null) {
// Register a handler that returns the "http" proxy, if an "http" URL is
// requested
ProxySettingsManager.registerProvider((sProtocol, sHost, nPort) -> "http".equals(sProtocol) ? new CommonsArrayList<>(aProxyHttp) : null);
}
final IProxySettings aProxyHttps = SMPServerConfiguration.getAsHttpsProxySettings();
if (aProxyHttps != null) {
// Register a handler that returns the "https" proxy, if an "https" URL
// is
// requested
ProxySettingsManager.registerProvider((sProtocol, sHost, nPort) -> "https".equals(sProtocol) ? new CommonsArrayList<>(aProxyHttps) : null);
}
}
// Special http client config
BasePageUtilsHttpClient.HttpClientConfigRegistry.register(new HttpClientConfig("directoryclient", "Directory client settings", PDHttpClientSettings::new));
LOGGER.info("Finished init of managers");
}
use of com.helger.phoss.smp.settings.ISMPSettings in project phoss-smp by phax.
the class PageSecureServiceGroupMigrationOutbound method validateAndSaveInputParameters.
@Override
protected void validateAndSaveInputParameters(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMPParticipantMigration aSelectedObject, @Nonnull final FormErrorList aFormErrors, @Nonnull final EWebPageFormAction eFormAction) {
final ISMPParticipantMigrationManager aParticipantMigrationMgr = SMPMetaManager.getParticipantMigrationMgr();
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final ISMPSettings aSettings = SMPMetaManager.getSettings();
final String sParticipantID = aWPEC.params().getAsStringTrimmed(FIELD_PARTICIPANT_ID);
final IParticipantIdentifier aParticipantID = aIdentifierFactory.parseParticipantIdentifier(sParticipantID);
if (StringHelper.hasNoText(sParticipantID))
aFormErrors.addFieldError(FIELD_PARTICIPANT_ID, "A Service Group must be selected.");
else if (aParticipantID == null)
aFormErrors.addFieldError(FIELD_PARTICIPANT_ID, "The selected Service Group does not exist.");
else {
if (aParticipantMigrationMgr.containsOutboundMigrationInProgress(aParticipantID))
aFormErrors.addFieldError(FIELD_PARTICIPANT_ID, "The migration of the selected Service Group is already in progress.");
}
if (aFormErrors.isEmpty()) {
LOGGER.info("Starting migration of participant ID '" + aParticipantID.getURIEncoded() + "'");
// Lets take this to the SML
String sMigrationKey = null;
if (true) {
try {
final ManageParticipantIdentifierServiceCaller aCaller = new ManageParticipantIdentifierServiceCaller(aSettings.getSMLInfo());
aCaller.setSSLSocketFactory(SMPKeyManager.getInstance().createSSLContext().getSocketFactory());
// Create a random migration key,
// Than call SML
sMigrationKey = aCaller.prepareToMigrate(aParticipantID, SMPServerConfiguration.getSMLSMPID());
LOGGER.info("Successfully called prepareToMigrate on SML. Created migration key is '" + sMigrationKey + "'");
} catch (final Exception ex) {
LOGGER.error("Error invoking prepareToMigrate on SML", ex);
aWPEC.postRedirectGetInternal(error("Failed to prepare the migration for participant '" + aParticipantID.getURIEncoded() + "' in SML.").addChild(SMPCommonUI.getTechnicalDetailsUI(ex)));
}
} else {
// Dummy for testing only
sMigrationKey = ManageParticipantIdentifierServiceCaller.createRandomMigrationKey();
LOGGER.warn("Created migration key '" + sMigrationKey + "' was not send to SML!");
}
// Remember internally
if (aParticipantMigrationMgr.createOutboundParticipantMigration(aParticipantID, sMigrationKey) != null) {
aWPEC.postRedirectGetInternal(success().addChild(div("The participant migration for '" + aParticipantID.getURIEncoded() + "' was successfully created.")).addChild(div("The created migration key is ").addChild(code(sMigrationKey))));
} else {
aWPEC.postRedirectGetInternal(error().addChild(div("Failed to store the participant migration for '" + aParticipantID.getURIEncoded() + "'.")).addChild(div("The created migration key is ").addChild(code(sMigrationKey))).addChild(". Please note it down manually!"));
}
}
}
use of com.helger.phoss.smp.settings.ISMPSettings in project phoss-smp by phax.
the class PageSecureServiceGroupMigrationOutbound method isActionAllowed.
@Override
protected boolean isActionAllowed(@Nonnull final WebPageExecutionContext aWPEC, @Nonnull final EWebPageFormAction eFormAction, @Nullable final ISMPParticipantMigration aSelectedObject) {
if (eFormAction.isEdit())
return false;
if (eFormAction.isCreating()) {
final ISMPSettings aSettings = SMPMetaManager.getSettings();
if (aSettings.getSMLInfo() == null)
return false;
if (!aSettings.isSMLEnabled())
return false;
final ISMPServiceGroupManager aServiceGroupManager = SMPMetaManager.getServiceGroupMgr();
if (aServiceGroupManager.getSMPServiceGroupCount() <= 0)
return false;
}
return super.isActionAllowed(aWPEC, eFormAction, aSelectedObject);
}
use of com.helger.phoss.smp.settings.ISMPSettings in project phoss-smp by phax.
the class PageSecureServiceGroupMigrationOutbound method showListOfExistingObjects.
@Override
protected void showListOfExistingObjects(@Nonnull final WebPageExecutionContext aWPEC) {
final HCNodeList aNodeList = aWPEC.getNodeList();
final ISMPParticipantMigrationManager aParticipantMigrationMgr = SMPMetaManager.getParticipantMigrationMgr();
final ISMPSettings aSettings = SMPMetaManager.getSettings();
final ISMPServiceGroupManager aServiceGroupManager = SMPMetaManager.getServiceGroupMgr();
{
final HCOL aOL = new HCOL();
aOL.addItem("The migration is initiated on this SMP, and the SML is informed about the upcoming migration");
aOL.addItem("The other SMP, that is taking over the Service Group, must acknowledge the migration by providing the same migration code (created by this SMP) to the SML");
aOL.addItem("If the migration was successful, the Service Group must be deleted from this SMP, ideally a temporary redirect to the new SMP is created. If the migration was cancelled no action is needed.");
aNodeList.addChild(info().addChild(div("The process of migrating a Service Group to another SMP consists of multiple steps:")).addChild(aOL).addChild(div("Therefore each open Migration must either be finished (deleting the Service Group) or cancelled (no action taken)." + " If a Migration is cancelled, it can be retried later.")));
}
EValidity eCanStartMigration = EValidity.VALID;
if (aSettings.getSMLInfo() == null) {
final BootstrapWarnBox aWarn = aNodeList.addAndReturnChild(warn().addChild(div("No valid SML Configuration is selected hence no participant can be migrated.")).addChild(div(new BootstrapButton().addChild("Select SML Configuration in the Settings").setOnClick(aWPEC.getLinkToMenuItem(CMenuSecure.MENU_SMP_SETTINGS)).setIcon(EDefaultIcon.EDIT))));
if (aSettings.isSMLEnabled() || aSettings.isSMLRequired()) {
aWarn.addChild(div(new BootstrapButton().addChild("Create a new SML Configuration").setOnClick(createCreateURL(aWPEC, CMenuSecure.MENU_SML_CONFIGURATION)).setIcon(EDefaultIcon.YES)));
}
eCanStartMigration = EValidity.INVALID;
} else if (!aSettings.isSMLEnabled()) {
aNodeList.addChild(warn().addChild(div("SML Connection is not enabled hence no participant can be migrated.")).addChild(div(new BootstrapButton().addChild("Enable SML in the Settings").setOnClick(aWPEC.getLinkToMenuItem(CMenuSecure.MENU_SMP_SETTINGS)).setIcon(EDefaultIcon.EDIT))));
eCanStartMigration = EValidity.INVALID;
} else {
if (aServiceGroupManager.getSMPServiceGroupCount() <= 0) {
aNodeList.addChild(warn("No Service Group is present! At least one Service Group must be present to migrate it."));
// Note: makes no to allow to create a new Service Group here and than
// directly migrate it away
eCanStartMigration = EValidity.INVALID;
}
}
{
final BootstrapButtonToolbar aToolbar = new BootstrapButtonToolbar(aWPEC);
aToolbar.addButton("Refresh", aWPEC.getSelfHref(), EDefaultIcon.REFRESH);
aToolbar.addChild(new BootstrapButton().addChild("Start Participant Migration").setOnClick(createCreateURL(aWPEC)).setDisabled(eCanStartMigration.isInvalid()).setIcon(EDefaultIcon.NEW));
aNodeList.addChild(aToolbar);
}
final BootstrapTabBox aTabBox = aNodeList.addAndReturnChild(new BootstrapTabBox());
final ICommonsList<ISMPParticipantMigration> aAllMigs = aParticipantMigrationMgr.getAllOutboundParticipantMigrations(null);
for (final EParticipantMigrationState eState : EParticipantMigrationState.values()) if (eState.isOutboundState()) {
final ICommonsList<ISMPParticipantMigration> aMatchingMigs = aAllMigs.getAll(x -> x.getState() == eState);
aTabBox.addTab(eState.getID(), eState.getDisplayName() + " (" + aMatchingMigs.size() + ")", _createTable(aWPEC, aMatchingMigs, eState));
}
}
use of com.helger.phoss.smp.settings.ISMPSettings in project phoss-smp by phax.
the class PageSecureTasksProblems method _checkDirectoryConfig.
private void _checkDirectoryConfig(@Nonnull final WebPageExecutionContext aWPEC, @Nonnull final HCOL aOL, @Nonnull final OffsetDateTime aNowDT, @Nonnull final OffsetDateTime aNowPlusDT) {
final ISMPSettings aSMPSettings = SMPMetaManager.getSettings();
final String sDirectoryName = SMPWebAppConfiguration.getDirectoryName();
if (aSMPSettings.isDirectoryIntegrationEnabled()) {
if (StringHelper.hasNoText(aSMPSettings.getDirectoryHostName()))
aOL.addItem(_createError("An empty " + sDirectoryName + " hostname is provided"), div("A connection to the " + sDirectoryName + " server cannot be establised!"));
// Check key store
final LoadedKeyStore aLoadedKeyStore = PDClientConfiguration.loadKeyStore();
if (aLoadedKeyStore.isFailure()) {
aOL.addItem(_createError("The " + sDirectoryName + " client key store configuration is invalid."), div(PeppolKeyStoreHelper.getLoadError(aLoadedKeyStore)));
} else {
final KeyStore aKeyStore = aLoadedKeyStore.getKeyStore();
final LoadedKey<KeyStore.PrivateKeyEntry> aLoadedKey = PDClientConfiguration.loadPrivateKey(aKeyStore);
if (aLoadedKey.isFailure()) {
aOL.addItem(_createError("The " + sDirectoryName + " client key store could be read, but the private key configuration is invalid."), div(PeppolKeyStoreHelper.getLoadError(aLoadedKey)));
} else {
_checkPrivateKey(aWPEC, aOL, aNowDT, aNowPlusDT, aLoadedKey.getKeyEntry());
}
}
// Check trust store
final LoadedKeyStore aLoadedTrustStore = PDClientConfiguration.loadTrustStore();
if (aLoadedTrustStore.isFailure()) {
aOL.addItem(_createError("The " + sDirectoryName + " client trust store configuration is invalid."), div(PeppolKeyStoreHelper.getLoadError(aLoadedTrustStore)));
} else {
final KeyStore aTrustStore = aLoadedTrustStore.getKeyStore();
_iterateTrustStore(aWPEC, aOL, aNowDT, aNowPlusDT, aTrustStore);
}
} else {
// Warn only if Directory is required
if (aSMPSettings.isDirectoryIntegrationRequired())
aOL.addItem(_createError("The connection to " + sDirectoryName + " is not enabled."));
}
}
Aggregations