Search in sources :

Example 1 with BootstrapDateTimePicker

use of com.helger.photon.bootstrap4.uictrls.datetimepicker.BootstrapDateTimePicker in project phoss-smp by phax.

the class PageSecureSMLCertificateUpdate 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();
    aNodeList.addChild(info().addChildren(div("Prepare the update of your SMP certificate in the future."), div("Note: this is a custom SML extension that only works with the CEF SML instances!")));
    // check for expired certificate
    boolean bShowForm = true;
    {
        final X509Certificate aEntry = SMPKeyManager.getInstance().getPrivateKeyCertificate();
        if (aEntry != null) {
            try {
                aEntry.checkValidity();
                aNodeList.addChild(info("Your SMP certificate is still valid until " + PDTToString.getAsString(PDTFactory.createLocalDateTime(aEntry.getNotAfter()), aDisplayLocale) + "."));
            } catch (final CertificateExpiredException ex) {
                aNodeList.addChild(error("Your SMP certificate is already expired." + " This functionality works only if your SMP certificate is NOT expired yet." + " Please contact CEF-EDELIVERY-SUPPORT@ec.europa.eu with your SMP ID, the new certificate and the requested exchange date!"));
                bShowForm = false;
            } catch (final CertificateNotYetValidException ex) {
                aNodeList.addChild(warn("Your SMP certificate is not valid yet." + " For this page to work you need to have your old certificate (the one that will expire soon) configured." + " Most likely the certificate change will not work."));
            }
        }
    }
    if (aWPEC.hasAction(CPageParam.ACTION_PERFORM)) {
        if (aWPEC.hasSubAction(SUBACTION_SMP_UPDATE_CERT))
            _updateSMPCertAtSML(aWPEC, aFormErrors);
    }
    // Update SMP certificate in SML
    if (bShowForm) {
        final BootstrapForm aForm = getUIHandler().createFormFileUploadSelf(aWPEC);
        aForm.setLeft(3);
        aForm.addChild(warn("It is your responsibility to actually perform the update of the certificate in this SMP at the specified time! This does NOT happen automatically."));
        final BootstrapDateTimePicker aDTP = BootstrapDateTimePicker.create(FIELD_PM_MIGRATION_DATE, (LocalDate) null, aDisplayLocale);
        aDTP.setMinDate(PDTFactory.getCurrentLocalDate().plusDays(1));
        aForm.addFormGroup(new BootstrapFormGroup().setLabel("Certificate migration date").setCtrl(aDTP).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 new certificate is used.").setErrorList(aFormErrors.getListOfField(FIELD_PM_MIGRATION_DATE)));
        aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("New public certificate").setCtrl(new HCTextArea(new RequestField(FIELD_PM_PUBLIC_CERT)).setRows(10)).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");
        aNodeList.addChild(aForm);
    }
}
Also used : Locale(java.util.Locale) CertificateNotYetValidException(java.security.cert.CertificateNotYetValidException) HCNodeList(com.helger.html.hc.impl.HCNodeList) CertificateExpiredException(java.security.cert.CertificateExpiredException) HCTextArea(com.helger.html.hc.html.forms.HCTextArea) FormErrorList(com.helger.photon.core.form.FormErrorList) BootstrapDateTimePicker(com.helger.photon.bootstrap4.uictrls.datetimepicker.BootstrapDateTimePicker) X509Certificate(java.security.cert.X509Certificate) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) RequestField(com.helger.photon.core.form.RequestField)

Aggregations

HCTextArea (com.helger.html.hc.html.forms.HCTextArea)1 HCNodeList (com.helger.html.hc.impl.HCNodeList)1 BootstrapButtonToolbar (com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar)1 BootstrapForm (com.helger.photon.bootstrap4.form.BootstrapForm)1 BootstrapFormGroup (com.helger.photon.bootstrap4.form.BootstrapFormGroup)1 BootstrapDateTimePicker (com.helger.photon.bootstrap4.uictrls.datetimepicker.BootstrapDateTimePicker)1 FormErrorList (com.helger.photon.core.form.FormErrorList)1 RequestField (com.helger.photon.core.form.RequestField)1 CertificateExpiredException (java.security.cert.CertificateExpiredException)1 CertificateNotYetValidException (java.security.cert.CertificateNotYetValidException)1 X509Certificate (java.security.cert.X509Certificate)1 Locale (java.util.Locale)1