Search in sources :

Example 31 with HCNodeList

use of com.helger.html.hc.impl.HCNodeList in project peppol-practical by phax.

the class PagePublicToolsSMPSML method fillContent.

@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final FormErrorList aFormErrors = new FormErrorList();
    final boolean bShowInput = true;
    aNodeList.addChild(warn("Note: as of ").addChild(new HCA(new SimpleURL("https://github.com/phax/phoss-smp")).addChild("phoss SMP server 5.0.0 beta 1")).addChild(" this registration feature is contained directly in the SMP software! So you don't need to send your certificates over the Internet anymore!"));
    if (aWPEC.hasAction(CPageParam.ACTION_PERFORM)) {
        if (aWPEC.hasSubAction(SUBACTION_SMP_REGISTER))
            _registerSMPtoSML(aWPEC, aFormErrors);
        else if (aWPEC.hasSubAction(SUBACTION_SMP_UPDATE))
            _updateSMPatSML(aWPEC, aFormErrors);
        else if (aWPEC.hasSubAction(SUBACTION_SMP_DELETE))
            _deleteSMPfromSML(aWPEC, aFormErrors);
        else if (aWPEC.hasSubAction(SUBACTION_SMP_UPDATE_CERT))
            _updateSMPCertAtSML(aWPEC, aFormErrors);
    }
    if (bShowInput) {
        final int nLeft = 3;
        final BootstrapTabBox aTabBox = new BootstrapTabBox();
        // Register SMP at SML
        {
            final BootstrapForm aForm = getUIHandler().createFormSelf(aWPEC);
            aForm.setEncTypeFileUpload().setLeft(nLeft);
            aForm.addChild(info("Register a new SMP to the SML. This must only be done once per SMP!"));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("SML").setCtrl(new SMLConfigurationSelect(new RequestField(FIELD_SML_ID), false)).setErrorList(aFormErrors.getListOfField(FIELD_SML_ID)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("SMP ID").setCtrl(new HCEdit(new RequestField(FIELD_SMP_ID)).setPlaceholder("Your SMP ID")).setHelpText(HELPTEXT_SMP_ID).setErrorList(aFormErrors.getListOfField(FIELD_SMP_ID)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Physical address").setCtrl(new HCEdit(new RequestField(FIELD_PHYSICAL_ADDRESS)).setPlaceholder("The IPv4 address of your SMP. E.g. 1.2.3.4")).setHelpText(HELPTEXT_PHYSICAL_ADDRESS).setErrorList(aFormErrors.getListOfField(FIELD_PHYSICAL_ADDRESS)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Logical address").setCtrl(new HCEdit(new RequestField(FIELD_LOGICAL_ADDRESS)).setPlaceholder("The domain name of your SMP server. E.g. http://smp.example.org")).setHelpText(HELPTEXT_LOGICAL_ADDRESS).setErrorList(aFormErrors.getListOfField(FIELD_LOGICAL_ADDRESS)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("SMP key store").setCtrl(new BootstrapFileUpload(FIELD_KEYSTORE, aDisplayLocale)).setHelpText(HELPTEXT_KEYSTORE).setErrorList(aFormErrors.getListOfField(FIELD_KEYSTORE)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabel("SMP key store password").setCtrl(new HCEditPassword(FIELD_KEYSTORE_PW).setPlaceholder("The password for the SMP keystore. May be empty.")).setHelpText(HELPTEXT_KEYSTORE_PW).setErrorList(aFormErrors.getListOfField(FIELD_KEYSTORE_PW)));
            final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(new BootstrapButtonToolbar(aWPEC));
            aToolbar.addHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM);
            aToolbar.addHiddenField(CPageParam.PARAM_SUBACTION, SUBACTION_SMP_REGISTER);
            aToolbar.addSubmitButton("Register SMP at SML");
            aTabBox.addTab("register", "Register SMP to SML", aForm, aWPEC.hasSubAction(SUBACTION_SMP_REGISTER));
        }
        // Update SMP at SML
        {
            final BootstrapForm aForm = getUIHandler().createFormSelf(aWPEC);
            aForm.setEncTypeFileUpload().setLeft(nLeft);
            aForm.addChild(info("Update an existing SMP at the SML. This must only be done when either the IP address or the host name of the SMP changed!"));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("SML").setCtrl(new SMLConfigurationSelect(new RequestField(FIELD_SML_ID), false)).setErrorList(aFormErrors.getListOfField(FIELD_SML_ID)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("SMP ID").setCtrl(new HCEdit(new RequestField(FIELD_SMP_ID)).setPlaceholder("Your SMP ID")).setHelpText(HELPTEXT_SMP_ID).setErrorList(aFormErrors.getListOfField(FIELD_SMP_ID)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Physical address").setCtrl(new HCEdit(new RequestField(FIELD_PHYSICAL_ADDRESS)).setPlaceholder("The IPv4 address of your SMP. E.g. 1.2.3.4")).setHelpText(HELPTEXT_PHYSICAL_ADDRESS).setErrorList(aFormErrors.getListOfField(FIELD_PHYSICAL_ADDRESS)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Logical address").setCtrl(new HCEdit(new RequestField(FIELD_LOGICAL_ADDRESS)).setPlaceholder("The domain name of your SMP server. E.g. http://smp.example.org")).setHelpText(HELPTEXT_LOGICAL_ADDRESS).setErrorList(aFormErrors.getListOfField(FIELD_LOGICAL_ADDRESS)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("SMP key store").setCtrl(new BootstrapFileUpload(FIELD_KEYSTORE, aDisplayLocale)).setHelpText(HELPTEXT_KEYSTORE).setErrorList(aFormErrors.getListOfField(FIELD_KEYSTORE)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabel("SMP key store password").setCtrl(new HCEditPassword(FIELD_KEYSTORE_PW).setPlaceholder("The password for the SMP keystore. May be empty.")).setHelpText(HELPTEXT_KEYSTORE_PW).setErrorList(aFormErrors.getListOfField(FIELD_KEYSTORE_PW)));
            final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(new BootstrapButtonToolbar(aWPEC));
            aToolbar.addHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM);
            aToolbar.addHiddenField(CPageParam.PARAM_SUBACTION, SUBACTION_SMP_UPDATE);
            aToolbar.addSubmitButton("Update SMP at SML");
            aTabBox.addTab("update", "Update SMP at SML", aForm, aWPEC.hasSubAction(SUBACTION_SMP_UPDATE));
        }
        // Delete SMP from SML
        {
            final BootstrapForm aForm = getUIHandler().createFormFileUploadSelf(aWPEC);
            aForm.setLeft(nLeft);
            aForm.addChild(info("Delete an existing SMP from the SML."));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("SML").setCtrl(new SMLConfigurationSelect(new RequestField(FIELD_SML_ID), false)).setErrorList(aFormErrors.getListOfField(FIELD_SML_ID)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("SMP ID").setCtrl(new HCEdit(new RequestField(FIELD_SMP_ID)).setPlaceholder("Your SMP ID")).setHelpText(HELPTEXT_SMP_ID).setErrorList(aFormErrors.getListOfField(FIELD_SMP_ID)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("SMP key store").setCtrl(new BootstrapFileUpload(FIELD_KEYSTORE, aDisplayLocale)).setHelpText(HELPTEXT_KEYSTORE).setErrorList(aFormErrors.getListOfField(FIELD_KEYSTORE)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabel("SMP key store password").setCtrl(new HCEditPassword(FIELD_KEYSTORE_PW).setPlaceholder("The password for the SMP keystore. May be empty.")).setHelpText(HELPTEXT_KEYSTORE_PW).setErrorList(aFormErrors.getListOfField(FIELD_KEYSTORE_PW)));
            final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(new BootstrapButtonToolbar(aWPEC));
            aToolbar.addHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM);
            aToolbar.addHiddenField(CPageParam.PARAM_SUBACTION, SUBACTION_SMP_DELETE);
            aToolbar.addSubmitButton("Delete SMP from SML");
            aTabBox.addTab("delete", "Delete SMP from SML", aForm, aWPEC.hasSubAction(SUBACTION_SMP_DELETE));
        }
        // Update SMP certificate in SML
        {
            final BootstrapForm aForm = getUIHandler().createFormFileUploadSelf(aWPEC);
            aForm.setLeft(nLeft);
            aForm.addChild(info().addChildren(div("Prepare the update of your Peppol SMP certificate in the future."), div("This works only if your SMP certificate is NOT expired yet." + " If your SMP certificate is already expired contact CEF-EDELIVERY-SUPPORT@ec.europa.eu with your SMP ID, the new certificate and the requested exchange date!"), div("Note: this is a custom extension that only works with the CEF SML instances!")));
            aForm.addChild(warn("It is your responsibility to update the Peppol certificate in your SMP at the specified time!"));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("SML").setCtrl(new SMLConfigurationSelect(new RequestField(FIELD_SML_ID), false)).setErrorList(aFormErrors.getListOfField(FIELD_SML_ID)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Existing/old SMP key store").setCtrl(new BootstrapFileUpload(FIELD_KEYSTORE, aDisplayLocale)).setHelpText(HELPTEXT_KEYSTORE).setErrorList(aFormErrors.getListOfField(FIELD_KEYSTORE)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabel("Existing/old SMP key store password").setCtrl(new HCEditPassword(FIELD_KEYSTORE_PW).setPlaceholder("The password for the existing SMP keystore. May be empty.")).setHelpText(HELPTEXT_KEYSTORE_PW).setErrorList(aFormErrors.getListOfField(FIELD_KEYSTORE_PW)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabel("Certificate migration date").setCtrl(BootstrapDateTimePicker.create(FIELD_PM_MIGRATION_DATE, aDisplayLocale, EBootstrap4DateTimePickerMode.DATE).setMinDate(PDTFactory.getCurrentLocalDate().plusDays(1))).setHelpText("The SML will replace the certificate at this date." + " It must be in the future and within the validity period of the provided new public certificate." + " If not provided, the 'valid from' part of the certificate is used.").setErrorList(aFormErrors.getListOfField(FIELD_PM_MIGRATION_DATE)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("New public certificate").setCtrl(new HCTextAreaAutosize(new RequestField(FIELD_PM_PUBLIC_CERT)).setRows(5)).setHelpText(span("Paste the public part of your new certificate here (using PEM encoding)." + " Do NOT paste your new private key here." + " Must start with ").addChild(code(CertificateHelper.BEGIN_CERTIFICATE)).addChild(" and end with ").addChild(code(CertificateHelper.END_CERTIFICATE))).setErrorList(aFormErrors.getListOfField(FIELD_PM_PUBLIC_CERT)));
            final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(new BootstrapButtonToolbar(aWPEC));
            aToolbar.addHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM);
            aToolbar.addHiddenField(CPageParam.PARAM_SUBACTION, SUBACTION_SMP_UPDATE_CERT);
            aToolbar.addSubmitButton("Prepare certificate update");
            aTabBox.addTab("updatecert", "Update SMP certificate at SML", aForm, aWPEC.hasSubAction(SUBACTION_SMP_UPDATE_CERT));
        }
        aNodeList.addChild(aTabBox);
    }
}
Also used : Locale(java.util.Locale) HCNodeList(com.helger.html.hc.impl.HCNodeList) HCTextAreaAutosize(com.helger.photon.uictrls.autosize.HCTextAreaAutosize) HCA(com.helger.html.hc.html.textlevel.HCA) FormErrorList(com.helger.photon.core.form.FormErrorList) HCEdit(com.helger.html.hc.html.forms.HCEdit) HCEditPassword(com.helger.html.hc.html.forms.HCEditPassword) SMLConfigurationSelect(com.helger.peppol.ui.select.SMLConfigurationSelect) BootstrapTabBox(com.helger.photon.bootstrap4.nav.BootstrapTabBox) SimpleURL(com.helger.commons.url.SimpleURL) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) BootstrapFileUpload(com.helger.photon.bootstrap4.uictrls.ext.BootstrapFileUpload) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) RequestField(com.helger.photon.core.form.RequestField)

Example 32 with HCNodeList

use of com.helger.html.hc.impl.HCNodeList in project peppol-practical by phax.

the class PagePublicToolsSMPSML method _registerSMPtoSML.

private void _registerSMPtoSML(@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 UnknownHostException ex) {
            final String sMsg = "The provided IP address does not resolve to a valid host. ";
            aFormErrors.addFieldError(FIELD_PHYSICAL_ADDRESS, sMsg + 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()) && !"https".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.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(AppCommonUI.getTechnicalDetailsUI(ex, true)));
            AuditHelper.onAuditExecuteFailure("smp-sml-create", sSMPID, sPhysicalAddress, sLogicalAddress, aSMLInfo.getManagementServiceURL(), ex.getClass(), ex.getMessage());
        }
    } else
        aNodeList.addChild(BootstrapWebPageUIHandler.INSTANCE.createIncorrectInputBox(aWPEC));
}
Also used : Locale(java.util.Locale) ISMLConfigurationManager(com.helger.peppol.app.mgr.ISMLConfigurationManager) HCNodeList(com.helger.html.hc.impl.HCNodeList) ManageServiceMetadataServiceCaller(com.helger.peppol.smlclient.ManageServiceMetadataServiceCaller) UnknownHostException(java.net.UnknownHostException) ISMLConfiguration(com.helger.peppol.domain.ISMLConfiguration) IFileItem(com.helger.web.fileupload.IFileItem) PDTToString(com.helger.commons.datetime.PDTToString) PDTFromString(com.helger.commons.datetime.PDTFromString) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) URL(java.net.URL) SimpleURL(com.helger.commons.url.SimpleURL) CertificateExpiredException(java.security.cert.CertificateExpiredException) ClientTransportException(com.sun.xml.ws.client.ClientTransportException) CertificateNotYetValidException(java.security.cert.CertificateNotYetValidException) UnknownHostException(java.net.UnknownHostException)

Example 33 with HCNodeList

use of com.helger.html.hc.impl.HCNodeList in project peppol-practical by phax.

the class PagePublicToolsSMPSML method _updateSMPCertAtSML.

private void _updateSMPCertAtSML(@Nonnull final WebPageExecutionContext aWPEC, @Nonnull final FormErrorList aFormErrors) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final ISMLConfigurationManager aSMLConfigurationMgr = PPMetaManager.getSMLConfigurationMgr();
    final LocalDate aNow = PDTFactory.getCurrentLocalDate();
    final String sSMLID = aWPEC.params().getAsString(FIELD_SML_ID);
    final ISMLConfiguration aSML = aSMLConfigurationMgr.getSMLInfoOfID(sSMLID);
    final IFileItem aKeyStoreFile = aWPEC.params().getAsFileItem(FIELD_KEYSTORE);
    final String sKeyStorePassword = aWPEC.params().getAsString(FIELD_KEYSTORE_PW);
    final String sMigrationDate = aWPEC.params().getAsString(FIELD_PM_MIGRATION_DATE);
    final LocalDate aMigrationDate = PDTFromString.getLocalDateFromString(sMigrationDate, aDisplayLocale);
    final String sMigrationPublicCert = aWPEC.params().getAsStringTrimmed(FIELD_PM_PUBLIC_CERT);
    X509Certificate aMigrationPublicCert = null;
    if (aSML == null)
        aFormErrors.addFieldError(FIELD_SML_ID, "A valid SML must be selected!");
    if (StringHelper.hasText(sMigrationDate)) {
        if (aMigrationDate == null)
            aFormErrors.addFieldError(FIELD_PM_MIGRATION_DATE, "The provided certificate migration date '" + sMigrationDate + "' is invalid!");
        else if (aMigrationDate.compareTo(aNow) <= 0)
            aFormErrors.addFieldError(FIELD_PM_MIGRATION_DATE, "The certificate migration date must be in the future!");
    }
    if (StringHelper.hasNoText(sMigrationPublicCert)) {
        aFormErrors.addFieldError(FIELD_PM_PUBLIC_CERT, "A new public certificate must be provided.");
    } else {
        try {
            aMigrationPublicCert = CertificateHelper.convertStringToCertficate(sMigrationPublicCert);
        } catch (final Exception ex) {
        // Fall through
        }
        if (aMigrationPublicCert == null)
            aFormErrors.addFieldError(FIELD_PM_PUBLIC_CERT, "The provided public certificate cannot be parsed as a X.509 certificate.");
        else {
            try {
                aMigrationPublicCert.checkValidity();
            } catch (final CertificateExpiredException ex) {
                aFormErrors.addFieldError(FIELD_PM_PUBLIC_CERT, "The provided public certificate is already expired!");
                aMigrationPublicCert = null;
            } catch (final CertificateNotYetValidException ex) {
            // That's okay
            }
            if (!sMigrationPublicCert.startsWith(CertificateHelper.BEGIN_CERTIFICATE))
                aFormErrors.addFieldError(FIELD_PM_PUBLIC_CERT, "The provided value must start with '" + CertificateHelper.BEGIN_CERTIFICATE + "' (without the quotes)");
            if (!sMigrationPublicCert.endsWith(CertificateHelper.END_CERTIFICATE))
                aFormErrors.addFieldError(FIELD_PM_PUBLIC_CERT, "The provided value must end with '" + CertificateHelper.END_CERTIFICATE + "' (without the quotes)");
        }
    }
    if (aMigrationPublicCert != null) {
        final LocalDate aNotBefore = PDTFactory.createLocalDate(aMigrationPublicCert.getNotBefore());
        final LocalDate aNotAfter = PDTFactory.createLocalDate(aMigrationPublicCert.getNotAfter());
        if (aMigrationDate != null) {
            if (aMigrationDate.isBefore(aNotBefore))
                aFormErrors.addFieldError(FIELD_PM_MIGRATION_DATE, "The provided certificate migration date " + PDTToString.getAsString(aMigrationDate, aDisplayLocale) + " must not be before the certificate NotBefore date " + PDTToString.getAsString(aNotBefore, aDisplayLocale) + "!");
            if (aMigrationDate.isAfter(aNotAfter))
                aFormErrors.addFieldError(FIELD_PM_MIGRATION_DATE, "The provided certificate migration date " + PDTToString.getAsString(aMigrationDate, aDisplayLocale) + " must not be after the certificate NotAfter date " + PDTToString.getAsString(aNotAfter, aDisplayLocale) + "!");
        } else {
            if (aNotBefore.compareTo(aNow) <= 0)
                aFormErrors.addFieldError(FIELD_PM_PUBLIC_CERT, "The effective certificate migration date (" + PDTToString.getAsString(aNotBefore, aDisplayLocale) + " - taken from the new public certificate) must be in the future!");
        }
    }
    final SSLSocketFactory aSocketFactory = _loadKeyStoreAndCreateSSLSocketFactory(EKeyStoreType.JKS, SECURITY_PROVIDER, aKeyStoreFile, sKeyStorePassword, aFormErrors, aDisplayLocale);
    if (aFormErrors.isEmpty()) {
        final BDMSLClient aCaller = new BDMSLClient(aSML.getSMLInfo());
        aCaller.setSSLSocketFactory(aSocketFactory);
        try {
            aCaller.prepareChangeCertificate(sMigrationPublicCert, aMigrationDate);
            final LocalDateTime aNotBefore = PDTFactory.createLocalDateTime(aMigrationPublicCert.getNotBefore());
            final LocalDateTime aNotAfter = PDTFactory.createLocalDateTime(aMigrationPublicCert.getNotAfter());
            final LocalDate aEffectiveMigrationDate = aMigrationDate != null ? aMigrationDate : aNotBefore.toLocalDate();
            final String sMsg = "Successfully prepared migration of SMP certificate at SML '" + aSML.getManagementServiceURL() + "'" + " to be exchanged at " + PDTToString.getAsString(aEffectiveMigrationDate, aDisplayLocale) + ".";
            LOGGER.info(sMsg);
            aNodeList.addChild(success().addChildren(div(sMsg), div("Issuer: " + aMigrationPublicCert.getIssuerX500Principal().getName()), div("Subject: " + aMigrationPublicCert.getSubjectX500Principal().getName()), div("Not before: " + PDTToString.getAsString(aNotBefore, aDisplayLocale)), div("Not after: " + PDTToString.getAsString(aNotAfter, aDisplayLocale))));
            AuditHelper.onAuditExecuteSuccess("smp-sml-update-cert", aSML.getManagementServiceURL(), sMigrationPublicCert, aMigrationDate);
        } catch (final com.helger.peppol.smlclient.bdmsl.BadRequestFault | com.helger.peppol.smlclient.bdmsl.InternalErrorFault | com.helger.peppol.smlclient.bdmsl.NotFoundFault | com.helger.peppol.smlclient.bdmsl.UnauthorizedFault | ClientTransportException ex) {
            final String sMsg = "Error preparing migration of SMP certificate at SML '" + aSML.getManagementServiceURL() + "'.";
            aNodeList.addChild(error(sMsg).addChild(AppCommonUI.getTechnicalDetailsUI(ex, true)));
            AuditHelper.onAuditExecuteFailure("smp-sml-update-cert", aSML.getManagementServiceURL(), sMigrationPublicCert, aMigrationDate, ex.getClass(), ex.getMessage());
        }
    } else
        aNodeList.addChild(BootstrapWebPageUIHandler.INSTANCE.createIncorrectInputBox(aWPEC));
}
Also used : Locale(java.util.Locale) LocalDateTime(java.time.LocalDateTime) ClientTransportException(com.sun.xml.ws.client.ClientTransportException) CertificateNotYetValidException(java.security.cert.CertificateNotYetValidException) HCNodeList(com.helger.html.hc.impl.HCNodeList) CertificateExpiredException(java.security.cert.CertificateExpiredException) ISMLConfiguration(com.helger.peppol.domain.ISMLConfiguration) PDTToString(com.helger.commons.datetime.PDTToString) PDTFromString(com.helger.commons.datetime.PDTFromString) LocalDate(java.time.LocalDate) X509Certificate(java.security.cert.X509Certificate) CertificateExpiredException(java.security.cert.CertificateExpiredException) ClientTransportException(com.sun.xml.ws.client.ClientTransportException) CertificateNotYetValidException(java.security.cert.CertificateNotYetValidException) UnknownHostException(java.net.UnknownHostException) BDMSLClient(com.helger.peppol.smlclient.BDMSLClient) ISMLConfigurationManager(com.helger.peppol.app.mgr.ISMLConfigurationManager) IFileItem(com.helger.web.fileupload.IFileItem) SSLSocketFactory(javax.net.ssl.SSLSocketFactory)

Example 34 with HCNodeList

use of com.helger.html.hc.impl.HCNodeList in project peppol-practical by phax.

the class LayoutAreaContentProviderSecure method _getNavbar.

@Nonnull
private static IHCNode _getNavbar(@Nonnull final LayoutExecutionContext aLEC) {
    final Locale aDisplayLocale = aLEC.getDisplayLocale();
    final IRequestWebScopeWithoutResponse aRequestScope = aLEC.getRequestScope();
    final ISimpleURL aLinkToStartPage = aLEC.getLinkToMenuItem(aLEC.getMenuTree().getDefaultMenuItemID());
    final BootstrapNavbar aNavbar = new BootstrapNavbar();
    aNavbar.addBrand(new HCNodeList().addChild(new HCSpan().addClass(AppCommonUI.CSS_CLASS_LOGO1).addChild(AppHelper.getApplicationTitle())).addChild(new HCSpan().addClass(AppCommonUI.CSS_CLASS_LOGO2).addChild(" Administration")), aLinkToStartPage);
    final BootstrapNavbarToggleable aToggleable = aNavbar.addAndReturnToggleable();
    final IUser aUser = LoggedInUserManager.getInstance().getCurrentUser();
    aToggleable.addAndReturnText().addClass(CBootstrapCSS.ML_AUTO).addClass(CBootstrapCSS.MX_2).addChild("Welcome ").addChild(new HCStrong().addChild(SecurityHelper.getUserDisplayName(aUser, aDisplayLocale)));
    aToggleable.addChild(new BootstrapButton().setOnClick(LinkHelper.getURLWithContext(AbstractPublicApplicationServlet.SERVLET_DEFAULT_PATH)).addChild("Public area").addClass(CBootstrapCSS.MX_2));
    aToggleable.addChild(new BootstrapButton().setOnClick(LinkHelper.getURLWithContext(aRequestScope, LogoutServlet.SERVLET_DEFAULT_PATH)).addChild(EPhotonCoreText.LOGIN_LOGOUT.getDisplayText(aDisplayLocale)).addClass(CBootstrapCSS.MX_2));
    return aNavbar;
}
Also used : Locale(java.util.Locale) IRequestWebScopeWithoutResponse(com.helger.web.scope.IRequestWebScopeWithoutResponse) HCSpan(com.helger.html.hc.html.textlevel.HCSpan) HCStrong(com.helger.html.hc.html.textlevel.HCStrong) HCNodeList(com.helger.html.hc.impl.HCNodeList) BootstrapNavbar(com.helger.photon.bootstrap4.navbar.BootstrapNavbar) ISimpleURL(com.helger.commons.url.ISimpleURL) BootstrapNavbarToggleable(com.helger.photon.bootstrap4.navbar.BootstrapNavbarToggleable) IUser(com.helger.photon.security.user.IUser) BootstrapButton(com.helger.photon.bootstrap4.button.BootstrapButton) Nonnull(javax.annotation.Nonnull)

Example 35 with HCNodeList

use of com.helger.html.hc.impl.HCNodeList in project peppol-practical by phax.

the class LayoutAreaContentProviderSecure method getContent.

@Nonnull
public static IHCNode getContent(@Nonnull final LayoutExecutionContext aLEC) {
    final HCNodeList ret = new HCNodeList();
    // Header
    ret.addChild(_getNavbar(aLEC));
    final BootstrapContainer aOuterContainer = ret.addAndReturnChild(new BootstrapContainer().setFluid(true));
    // Breadcrumbs
    {
        final BootstrapBreadcrumb aBreadcrumbs = BootstrapBreadcrumbProvider.createBreadcrumb(aLEC);
        aBreadcrumbs.addClasses(CBootstrapCSS.D_NONE, CBootstrapCSS.D_SM_BLOCK);
        aOuterContainer.addChild(aBreadcrumbs);
    }
    // Content
    {
        final HCDiv aRow = aOuterContainer.addAndReturnChild(new HCDiv().addClass(CBootstrapCSS.D_MD_FLEX));
        final HCDiv aCol1 = aRow.addAndReturnChild(new HCDiv().addClass(CBootstrapCSS.D_MD_FLEX).addClass(CBootstrapCSS.MR_2));
        final HCDiv aCol2 = aRow.addAndReturnChild(new HCDiv().addClass(CBootstrapCSS.FLEX_FILL));
        // left
        // We need a wrapper span for easy AJAX content replacement
        aCol1.addClass(CBootstrapCSS.D_PRINT_NONE).addChild(new HCSpan().setID(CLayout.LAYOUT_AREAID_MENU).addChild(getMenuContent(aLEC)));
        aCol1.addChild(new HCDiv().setID(CLayout.LAYOUT_AREAID_SPECIAL));
        // content - determine is exactly same as for view
        aCol2.addChild(LayoutAreaContentProviderPublic.getPageContent(aLEC));
    }
    return ret;
}
Also used : HCDiv(com.helger.html.hc.html.grouping.HCDiv) HCSpan(com.helger.html.hc.html.textlevel.HCSpan) HCNodeList(com.helger.html.hc.impl.HCNodeList) BootstrapContainer(com.helger.photon.bootstrap4.layout.BootstrapContainer) BootstrapBreadcrumb(com.helger.photon.bootstrap4.breadcrumb.BootstrapBreadcrumb) Nonnull(javax.annotation.Nonnull)

Aggregations

HCNodeList (com.helger.html.hc.impl.HCNodeList)123 Locale (java.util.Locale)74 BootstrapFormGroup (com.helger.photon.bootstrap4.form.BootstrapFormGroup)42 Nonnull (javax.annotation.Nonnull)41 BootstrapButtonToolbar (com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar)40 HCA (com.helger.html.hc.html.textlevel.HCA)35 PDTToString (com.helger.commons.datetime.PDTToString)28 ISimpleURL (com.helger.commons.url.ISimpleURL)27 HCRow (com.helger.html.hc.html.tabular.HCRow)26 BootstrapButton (com.helger.photon.bootstrap4.button.BootstrapButton)24 RequestField (com.helger.photon.core.form.RequestField)24 DTCol (com.helger.photon.uictrls.datatables.column.DTCol)24 HCTable (com.helger.html.hc.html.tabular.HCTable)23 BootstrapViewForm (com.helger.photon.bootstrap4.form.BootstrapViewForm)23 BootstrapForm (com.helger.photon.bootstrap4.form.BootstrapForm)21 BootstrapDTColAction (com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDTColAction)21 FormErrorList (com.helger.photon.core.form.FormErrorList)21 BootstrapDataTables (com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDataTables)20 HCTextNode (com.helger.html.hc.impl.HCTextNode)19 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)19