Search in sources :

Example 66 with ISMPServiceGroupManager

use of com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager in project phoss-smp by phax.

the class PageSecureTasksProblems method fillContent.

@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
    final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
    final OffsetDateTime aNowDT = PDTFactory.getCurrentOffsetDateTime();
    final OffsetDateTime aNowPlusDT = aNowDT.plusMonths(3);
    aNodeList.addChild(info("This page tries to identify upcoming tasks and potential problems in the SMP configuration. It is meant to highlight immediate and upcoming action items as well as potential misconfiguration."));
    final HCOL aOL = new HCOL();
    // Check for default password
    if (PhotonSecurityManager.getUserMgr().areUserIDAndPasswordValid(CSecurity.USER_ADMINISTRATOR_ID, CSecurity.USER_ADMINISTRATOR_PASSWORD)) {
        aOL.addItem(_createError("Please change the password of the default user " + CSecurity.USER_ADMINISTRATOR_EMAIL + "!"), div("This is a severe security risk"));
    }
    _checkSettings(aOL);
    // check keystore configuration
    _checkKeyStore(aWPEC, aOL, aNowDT, aNowPlusDT);
    // Check truststore configuration
    _checkTrustStore(aWPEC, aOL, aNowDT, aNowPlusDT);
    // Check SML configuration
    _checkSMLConfiguration(aOL);
    // Check Directory configuration
    _checkDirectoryConfig(aWPEC, aOL, aNowDT, aNowPlusDT);
    // check service groups and redirects
    {
        final ICommonsList<ISMPServiceGroup> aServiceGroups = aServiceGroupMgr.getAllSMPServiceGroups();
        if (aServiceGroups.isEmpty()) {
            aOL.addItem(_createWarning("No service group is configured. This SMP is currently empty."));
        } else {
            // For all service groups
            for (final ISMPServiceGroup aServiceGroup : CollectionHelper.getSorted(aServiceGroups, ISMPServiceGroup.comparator())) {
                final HCUL aULPerSG = new HCUL();
                final ICommonsList<ISMPServiceInformation> aServiceInfos = aServiceInfoMgr.getAllSMPServiceInformationOfServiceGroup(aServiceGroup);
                if (aServiceInfos.isEmpty()) {
                    // This is merely a warning or an error
                    aULPerSG.addItem(_createInfo("No endpoint is configured for this service group."));
                } else {
                    for (final ISMPServiceInformation aServiceInfo : aServiceInfos) {
                        final HCUL aULPerDocType = new HCUL();
                        final ICommonsList<ISMPProcess> aProcesses = aServiceInfo.getAllProcesses();
                        for (final ISMPProcess aProcess : aProcesses) {
                            final HCUL aULPerProcess = new HCUL();
                            final ICommonsList<ISMPEndpoint> aEndpoints = aProcess.getAllEndpoints();
                            for (final ISMPEndpoint aEndpoint : aEndpoints) {
                                final HCUL aULPerEndpoint = new HCUL();
                                final ESMPTransportProfile eTransportProfile = ESMPTransportProfile.getFromIDOrNull(aEndpoint.getTransportProfile());
                                if (eTransportProfile == null)
                                    aULPerEndpoint.addItem(_createWarning("The endpoint uses the non-standard transport profile '" + aEndpoint.getTransportProfile() + "'."));
                                if (aEndpoint.getServiceActivationDateTime() != null) {
                                    if (aEndpoint.getServiceActivationDateTime().isAfter(XMLOffsetDateTime.of(aNowDT)))
                                        aULPerEndpoint.addItem(_createWarning("The endpoint is not yet active."), div("It will be active from " + PDTToString.getAsString(aEndpoint.getServiceActivationDateTime(), aDisplayLocale) + "."));
                                }
                                if (aEndpoint.getServiceExpirationDateTime() != null) {
                                    if (aEndpoint.getServiceExpirationDateTime().isBefore(XMLOffsetDateTime.of(aNowDT)))
                                        aULPerEndpoint.addItem(_createError("The endpoint is no longer active."), div("It was valid until " + PDTToString.getAsString(aEndpoint.getServiceExpirationDateTime(), aDisplayLocale) + "."));
                                    else if (aEndpoint.getServiceExpirationDateTime().isBefore(XMLOffsetDateTime.of(aNowPlusDT)))
                                        aULPerEndpoint.addItem(_createWarning("The endpoint will be inactive soon."), div("It is only valid until " + PDTToString.getAsString(aEndpoint.getServiceExpirationDateTime(), aDisplayLocale) + "."));
                                }
                                X509Certificate aX509Cert = null;
                                try {
                                    aX509Cert = CertificateHelper.convertStringToCertficate(aEndpoint.getCertificate());
                                } catch (final CertificateException ex) {
                                // Ignore
                                }
                                if (aX509Cert == null)
                                    aULPerEndpoint.addItem(_createError("The X.509 certificate configured at the endpoint is invalid and could not be interpreted as a certificate."));
                                else {
                                    final OffsetDateTime aNotBefore = PDTFactory.createOffsetDateTime(aX509Cert.getNotBefore());
                                    if (aNowDT.isBefore(aNotBefore))
                                        aULPerEndpoint.addItem(_createError("The endpoint certificate is not yet active."), div("It will be valid from " + PDTToString.getAsString(aNotBefore, aDisplayLocale) + "."));
                                    final OffsetDateTime aNotAfter = PDTFactory.createOffsetDateTime(aX509Cert.getNotAfter());
                                    if (aNowDT.isAfter(aNotAfter))
                                        aULPerEndpoint.addItem(_createError("The endpoint certificate is already expired."), div("It was valid until " + PDTToString.getAsString(aNotAfter, aDisplayLocale) + "."));
                                    else if (aNowPlusDT.isAfter(aNotAfter))
                                        aULPerEndpoint.addItem(_createWarning("The endpoint certificate will expire soon."), div("It is only valid until " + PDTToString.getAsString(aNotAfter, aDisplayLocale) + "."));
                                }
                                // Show per endpoint errors
                                if (aULPerEndpoint.hasChildren())
                                    aULPerProcess.addItem(div("Transport profile ").addChild(code(aEndpoint.getTransportProfile())), aULPerEndpoint);
                            }
                            // Show per process errors
                            if (aULPerProcess.hasChildren())
                                aULPerDocType.addItem(div("Process ").addChild(code(aProcess.getProcessIdentifier().getURIEncoded()).addClass(CUICoreCSS.CSS_CLASS_NOWRAP)), aULPerProcess);
                        }
                        // Show per document type errors
                        if (aULPerDocType.hasChildren())
                            aULPerSG.addItem(div("Document type ").addChild(code(aServiceInfo.getDocumentTypeIdentifier().getURIEncoded()).addClass(CUICoreCSS.CSS_CLASS_NOWRAP)), aULPerDocType);
                    }
                }
                // Show per service group errors
                if (aULPerSG.hasChildren())
                    aOL.addItem(div("Service group ").addChild(code(aServiceGroup.getParticipantIdentifier().getURIEncoded())), aULPerSG);
            }
        }
    }
    // Show results
    if (aOL.hasChildren()) {
        aNodeList.addChild(warn("The following list of tasks and problems were identified:"));
        aNodeList.addChild(aOL);
    } else
        aNodeList.addChild(success("Great job, no tasks or problems identified!"));
}
Also used : Locale(java.util.Locale) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ICommonsList(com.helger.commons.collection.impl.ICommonsList) HCNodeList(com.helger.html.hc.impl.HCNodeList) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) ESMPTransportProfile(com.helger.peppol.smp.ESMPTransportProfile) CertificateException(java.security.cert.CertificateException) ISMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) X509Certificate(java.security.cert.X509Certificate) HCUL(com.helger.html.hc.html.grouping.HCUL) XMLOffsetDateTime(com.helger.commons.datetime.XMLOffsetDateTime) OffsetDateTime(java.time.OffsetDateTime) HCOL(com.helger.html.hc.html.grouping.HCOL) ISMPProcess(com.helger.phoss.smp.domain.serviceinfo.ISMPProcess)

Example 67 with ISMPServiceGroupManager

use of com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager in project phoss-smp by phax.

the class PageSecureServiceGroupExport method fillContent.

@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final IRequestWebScopeWithoutResponse aRequestScope = aWPEC.getRequestScope();
    final ISMPSettings aSettings = SMPMetaManager.getSettings();
    final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
    final long nServiceGroupCount = aServiceGroupMgr.getSMPServiceGroupCount();
    final boolean bHandleBusinessCards = aSettings.isDirectoryIntegrationEnabled();
    if (nServiceGroupCount < 0)
        aNodeList.addChild(error("The number of service groups is unknown, hence nothing can be exported!"));
    else if (nServiceGroupCount == 0)
        aNodeList.addChild(warn("Since no service group is present, nothing can be exported!"));
    else {
        aNodeList.addChild(info("Export " + (nServiceGroupCount == 1 ? "service group" : "all " + nServiceGroupCount + " service groups") + (bHandleBusinessCards ? " and business card" + (nServiceGroupCount == 1 ? "" : "s") : "") + " to an XML file."));
    }
    // The main export logic happens in the AJAX handler
    final BootstrapButtonToolbar aToolbar = aNodeList.addAndReturnChild(getUIHandler().createToolbar(aWPEC));
    aToolbar.addChild(new BootstrapButton().addChild("Export all Service Groups").setIcon(EDefaultIcon.SAVE_ALL).setOnClick(AJAX_EXPORT_SG.getInvocationURL(aRequestScope)).setDisabled(nServiceGroupCount <= 0));
}
Also used : IRequestWebScopeWithoutResponse(com.helger.web.scope.IRequestWebScopeWithoutResponse) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) HCNodeList(com.helger.html.hc.impl.HCNodeList) ISMPSettings(com.helger.phoss.smp.settings.ISMPSettings) BootstrapButton(com.helger.photon.bootstrap4.button.BootstrapButton) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar)

Aggregations

ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)67 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)47 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)45 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)35 IUser (com.helger.photon.security.user.IUser)25 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)23 SMPServerException (com.helger.phoss.smp.exception.SMPServerException)22 Nonnull (javax.annotation.Nonnull)22 ISMPServiceInformationManager (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager)21 Test (org.junit.Test)19 ISMPRedirectManager (com.helger.phoss.smp.domain.redirect.ISMPRedirectManager)16 HCNodeList (com.helger.html.hc.impl.HCNodeList)15 ISMPServiceInformation (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation)15 IMicroDocument (com.helger.xml.microdom.IMicroDocument)12 ServiceGroupType (com.helger.xsds.peppol.smp1.ServiceGroupType)12 ServiceMetadataReferenceCollectionType (com.helger.xsds.peppol.smp1.ServiceMetadataReferenceCollectionType)12 SMPNotFoundException (com.helger.phoss.smp.exception.SMPNotFoundException)11 ISMPSettings (com.helger.phoss.smp.settings.ISMPSettings)11 ICommonsList (com.helger.commons.collection.impl.ICommonsList)10 SimpleParticipantIdentifier (com.helger.peppolid.simple.participant.SimpleParticipantIdentifier)10