Search in sources :

Example 11 with ISMLInfo

use of com.helger.peppol.sml.ISMLInfo in project phoss-smp by phax.

the class PageSecureSMLRegistration method _deleteSMPfromSML.

private void _deleteSMPfromSML(@Nonnull final WebPageExecutionContext aWPEC, @Nonnull final FormErrorList aFormErrors) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final String sSMLID = aWPEC.params().getAsString(FIELD_SML_ID);
    final ISMLInfo aSMLInfo = SMPMetaManager.getSMLInfoMgr().getSMLInfoOfID(sSMLID);
    if (aSMLInfo == null)
        aFormErrors.addFieldError(FIELD_SML_ID, "A valid SML must be selected!");
    if (aFormErrors.isEmpty()) {
        final String sSMPID = SMPServerConfiguration.getSMLSMPID();
        try {
            final SSLSocketFactory aSocketFactory = SMPKeyManager.getInstance().createSSLContext().getSocketFactory();
            final ManageServiceMetadataServiceCaller aCaller = _create(aSMLInfo, 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(SMPCommonUI.getTechnicalDetailsUI(ex)));
            AuditHelper.onAuditExecuteFailure("smp-sml-delete", sSMPID, aSMLInfo.getManagementServiceURL(), ex.getClass(), ex.getMessage());
        }
    } else
        aNodeList.addChild(BootstrapWebPageUIHandler.INSTANCE.createIncorrectInputBox(aWPEC));
}
Also used : HCNodeList(com.helger.html.hc.impl.HCNodeList) ManageServiceMetadataServiceCaller(com.helger.peppol.smlclient.ManageServiceMetadataServiceCaller) ISMLInfo(com.helger.peppol.sml.ISMLInfo) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) UnknownHostException(java.net.UnknownHostException)

Example 12 with ISMLInfo

use of com.helger.peppol.sml.ISMLInfo in project phoss-smp by phax.

the class PageSecureTasksProblems method _checkSMLConfiguration.

private void _checkSMLConfiguration(@Nonnull final HCOL aOL) {
    final ISMPSettings aSMPSettings = SMPMetaManager.getSettings();
    final String sSMPID = SMPServerConfiguration.getSMLSMPID();
    if (aSMPSettings.isSMLEnabled()) {
        final ISMLInfo aSMLInfo = aSMPSettings.getSMLInfo();
        if (aSMLInfo == null) {
            aOL.addItem(_createError("No SML is selected in the SMP settings."), div("All creations and deletions of service groups needs to be repeated when the SML connection is active!"));
        } else {
            // Check if this SMP is already registered
            final String sPublisherDNSName = sSMPID + "." + aSMLInfo.getPublisherDNSZone();
            try {
                InetAddress.getByName(sPublisherDNSName);
            // On success, ignore
            } catch (final UnknownHostException ex) {
                // continue
                aOL.addItem(_createWarning("It seems like this SMP was not yet registered to the SML."), div("This is a one-time action that should be performed once. It requires a valid SMP certificate to work."), div("The registration check was performed with the URL ").addChild(new HCA().setHref(new SimpleURL("http://" + sPublisherDNSName)).setTargetBlank().addChild(code(sPublisherDNSName))));
            }
        }
    } else {
        if (aSMPSettings.isSMLRequired())
            aOL.addItem(_createError("The connection to the SML is not enabled."), div("All creations and deletions of service groups needs to be repeated when the SML connection is active!"));
    }
}
Also used : ISMPSettings(com.helger.phoss.smp.settings.ISMPSettings) UnknownHostException(java.net.UnknownHostException) ISMLInfo(com.helger.peppol.sml.ISMLInfo) HCA(com.helger.html.hc.html.textlevel.HCA) PDTToString(com.helger.commons.datetime.PDTToString) SimpleURL(com.helger.commons.url.SimpleURL)

Example 13 with ISMLInfo

use of com.helger.peppol.sml.ISMLInfo in project phoss-smp by phax.

the class RegistrationHookWriteToSML method _createSMLCaller.

@Nonnull
private static ManageParticipantIdentifierServiceCaller _createSMLCaller() {
    // SML endpoint (incl. the service name)
    final ISMLInfo aSMLInfo = SMPMetaManager.getSettings().getSMLInfo();
    if (aSMLInfo == null)
        throw new IllegalStateException("Failed to get SML manage participant endpoint URL");
    final URL aSMLEndpointURL = aSMLInfo.getManageParticipantIdentifierEndpointAddress();
    final String sEndpointURL = aSMLEndpointURL.toExternalForm();
    final String sLowerURL = sEndpointURL.toLowerCase(Locale.US);
    if (LOGGER.isInfoEnabled())
        LOGGER.info("Performing SML query to '" + sEndpointURL + "'");
    // SSL socket factory
    final SSLSocketFactory aSocketFactory;
    if (sLowerURL.startsWith("https://")) {
        // https connection
        if (!SMPKeyManager.isKeyStoreValid())
            throw new InitializationException("Cannot init registration hook to SML, because private key/certificate setup has errors: " + SMPKeyManager.getInitializationError());
        try {
            aSocketFactory = SMPKeyManager.getInstance().createSSLContext().getSocketFactory();
        } catch (final Exception ex) {
            throw new IllegalStateException("Failed to init SSLContext for SML access", ex);
        }
    } else {
        // Local, http only access - no socket factory
        aSocketFactory = null;
    }
    // Hostname verifier
    final HostnameVerifier aHostnameVerifier;
    if (sLowerURL.contains("//localhost") || sLowerURL.contains("//127.0.0.1")) {
        // Accept all hostnames
        aHostnameVerifier = new HostnameVerifierVerifyAll(false);
    } else
        aHostnameVerifier = null;
    // Build WS client
    final ManageParticipantIdentifierServiceCaller ret = new ManageParticipantIdentifierServiceCaller(aSMLEndpointURL);
    ret.setSSLSocketFactory(aSocketFactory);
    ret.setHostnameVerifier(aHostnameVerifier);
    final Integer aConnectionTimeoutMS = SMPServerConfiguration.getSMLConnectionTimeoutMS();
    if (aConnectionTimeoutMS != null)
        ret.setConnectionTimeoutMS(aConnectionTimeoutMS.intValue());
    final int nRequestTimeoutMS = SMPServerConfiguration.getSMLRequestTimeoutMS();
    if (nRequestTimeoutMS >= 0)
        ret.setRequestTimeoutMS(nRequestTimeoutMS);
    return ret;
}
Also used : HostnameVerifierVerifyAll(com.helger.commons.ws.HostnameVerifierVerifyAll) ISMLInfo(com.helger.peppol.sml.ISMLInfo) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) InitializationException(com.helger.commons.exception.InitializationException) URL(java.net.URL) InitializationException(com.helger.commons.exception.InitializationException) ManageParticipantIdentifierServiceCaller(com.helger.peppol.smlclient.ManageParticipantIdentifierServiceCaller) HostnameVerifier(javax.net.ssl.HostnameVerifier) Nonnull(javax.annotation.Nonnull)

Example 14 with ISMLInfo

use of com.helger.peppol.sml.ISMLInfo in project phoss-smp by phax.

the class SMPSettings method initFromSettings.

@Nonnull
EChange initFromSettings(@Nonnull final ISettings aSettings) {
    ValueEnforcer.notNull(aSettings, "settings");
    final EChange ret = m_aSettings.setAll(aSettings);
    // Soft migration 5.0.7
    if (!m_aSettings.containsKey(KEY_SML_INFO_ID)) {
        // Get old String (includes "/manageparticipantidentifier")
        final String sOldSMLURL = m_aSettings.getAsString("sml.url");
        if (StringHelper.hasText(sOldSMLURL)) {
            // Check if any SML item matches
            final ISMLInfo aSMLInfo = SMPMetaManager.getSMLInfoMgr().findFirstWithManageParticipantIdentifierEndpointAddress(sOldSMLURL);
            if (aSMLInfo != null)
                m_aSettings.put(KEY_SML_INFO_ID, aSMLInfo.getID());
        }
    }
    return ret;
}
Also used : ISMLInfo(com.helger.peppol.sml.ISMLInfo) EChange(com.helger.commons.state.EChange) Nonnull(javax.annotation.Nonnull)

Example 15 with ISMLInfo

use of com.helger.peppol.sml.ISMLInfo in project phoss-directory by phax.

the class PageSecureIndexManually method fillContent.

@Override
protected void fillContent(final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final IIdentifierFactory aIdentifierFactory = PDMetaManager.getIdentifierFactory();
    final FormErrorList aFormErrors = new FormErrorList();
    {
        final IPDBusinessCardProvider aBCProv = PDMetaManager.getBusinessCardProvider();
        if (aBCProv instanceof SMPBusinessCardProvider) {
            final SMPBusinessCardProvider aSMPBCProv = (SMPBusinessCardProvider) aBCProv;
            if (aSMPBCProv.isFixedSMP()) {
                aNodeList.addChild(info("Fixed SMP URI " + aSMPBCProv.getFixedSMPURI() + " is used."));
            } else {
                aNodeList.addChild(info("The following SMLs are crawled for entries: " + StringHelper.getImplodedMapped(", ", aSMPBCProv.getAllSMLsToUse(), ISMLInfo::getDisplayName)));
            }
        }
    }
    if (aWPEC.hasAction(CPageParam.ACTION_PERFORM)) {
        final String sParticipantID = aWPEC.params().getAsString(FIELD_PARTICIPANT_ID);
        final IParticipantIdentifier aParticipantID = aIdentifierFactory.parseParticipantIdentifier(sParticipantID);
        if (StringHelper.hasNoText(sParticipantID))
            aFormErrors.addFieldError(FIELD_PARTICIPANT_ID, "A participant ID must be provided.");
        else if (aParticipantID == null)
            aFormErrors.addFieldError(FIELD_PARTICIPANT_ID, "The provided participant ID is syntactically invalid.");
        if (aFormErrors.isEmpty()) {
            if (PDMetaManager.getIndexerMgr().queueWorkItem(aParticipantID, EIndexerWorkItemType.CREATE_UPDATE, "manually-triggered", PDIndexerManager.HOST_LOCALHOST).isChanged()) {
                aWPEC.postRedirectGetInternal(success("The indexing of participant ID '" + sParticipantID + "' was successfully triggered!"));
            } else {
                aWPEC.postRedirectGetInternal(warn("Participant ID '" + sParticipantID + "' is already in the indexing queue!"));
            }
        }
    }
    final BootstrapForm aForm = aNodeList.addAndReturnChild(getUIHandler().createFormSelf(aWPEC));
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Participant ID").setCtrl(new HCEdit(new RequestField(FIELD_PARTICIPANT_ID, PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME + CIdentifier.URL_SCHEME_VALUE_SEPARATOR))).setHelpText(span().addChild("Enter the fully qualified Peppol participant ID (including the scheme) you want to index.\nExample identifier layout: ").addChild(code(aIdentifierFactory.createParticipantIdentifier(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, "9999:test").getURIEncoded()))).setErrorList(aFormErrors.getListOfField(FIELD_PARTICIPANT_ID)));
    final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(new BootstrapButtonToolbar(aWPEC));
    aToolbar.addHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM);
    aToolbar.addSubmitButton("Add to queue", EDefaultIcon.YES);
}
Also used : SMPBusinessCardProvider(com.helger.pd.indexer.businesscard.SMPBusinessCardProvider) HCNodeList(com.helger.html.hc.impl.HCNodeList) ISMLInfo(com.helger.peppol.sml.ISMLInfo) FormErrorList(com.helger.photon.core.form.FormErrorList) HCEdit(com.helger.html.hc.html.forms.HCEdit) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) IPDBusinessCardProvider(com.helger.pd.indexer.businesscard.IPDBusinessCardProvider) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) RequestField(com.helger.photon.core.form.RequestField)

Aggregations

ISMLInfo (com.helger.peppol.sml.ISMLInfo)29 HCNodeList (com.helger.html.hc.impl.HCNodeList)11 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)9 SMLInfo (com.helger.peppol.sml.SMLInfo)7 Locale (java.util.Locale)7 Nonnull (javax.annotation.Nonnull)6 Test (org.junit.Test)6 ISMPSettings (com.helger.phoss.smp.settings.ISMPSettings)5 BootstrapButtonToolbar (com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar)5 BootstrapFormGroup (com.helger.photon.bootstrap4.form.BootstrapFormGroup)5 UnknownHostException (java.net.UnknownHostException)5 ManageParticipantIdentifierServiceCaller (com.helger.peppol.smlclient.ManageParticipantIdentifierServiceCaller)4 PDTToString (com.helger.commons.datetime.PDTToString)3 HCA (com.helger.html.hc.html.textlevel.HCA)3 ManageServiceMetadataServiceCaller (com.helger.peppol.smlclient.ManageServiceMetadataServiceCaller)3 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)3 BootstrapForm (com.helger.photon.bootstrap4.form.BootstrapForm)3 FormErrorList (com.helger.photon.core.form.FormErrorList)3 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)3 CMimeType (com.helger.commons.mime.CMimeType)2