Search in sources :

Example 1 with ESMPRESTType

use of com.helger.phoss.smp.ESMPRESTType in project phoss-smp by phax.

the class PageSecureServiceGroup method showListOfExistingObjects.

@Override
protected void showListOfExistingObjects(@Nonnull final WebPageExecutionContext aWPEC) {
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
    final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
    final ISMPBusinessCardManager aBCMgr = SMPMetaManager.getBusinessCardMgr();
    final ISMPSettings aSettings = SMPMetaManager.getSettings();
    final ESMPRESTType eRESTType = SMPServerConfiguration.getRESTType();
    final boolean bShowExtensionDetails = SMPWebAppConfiguration.isServiceGroupsExtensionsShow();
    final boolean bShowBusinessCardName = CSMP.ENABLE_ISSUE_56 && aSettings.isDirectoryIntegrationEnabled();
    final ICommonsList<ISMPServiceGroup> aAllServiceGroups = aServiceGroupMgr.getAllSMPServiceGroups();
    final BootstrapButtonToolbar aToolbar = new BootstrapButtonToolbar(aWPEC);
    aToolbar.addButton("Create new Service group", createCreateURL(aWPEC), EDefaultIcon.NEW);
    aToolbar.addButton("Refresh", aWPEC.getSelfHref(), EDefaultIcon.REFRESH);
    if (aSettings.isSMLRequired() || aSettings.isSMLEnabled()) {
        // Disable button if no SML URL is configured
        // Disable button if no service group is present
        aToolbar.addAndReturnButton("Check DNS state", aWPEC.getSelfHref().add(CPageParam.PARAM_ACTION, ACTION_CHECK_DNS), EDefaultIcon.MAGNIFIER).setDisabled(aSettings.getSMLDNSZone() == null || aAllServiceGroups.isEmpty() || !aSettings.isSMLEnabled());
    }
    aNodeList.addChild(aToolbar);
    final boolean bShowDetails = aAllServiceGroups.size() <= 1000;
    final HCTable aTable = new HCTable(new DTCol("Participant ID").setInitialSorting(ESortOrder.ASCENDING), new DTCol("Owner"), bShowBusinessCardName ? new DTCol("Business Card Name") : null, new DTCol(span(bShowExtensionDetails ? "Ext" : "Ext?").setTitle("Is an Extension present?")), bShowDetails ? new DTCol(span("Docs").setTitle("Number of assigned document types")).setDisplayType(EDTColType.INT, aDisplayLocale) : null, bShowDetails ? new DTCol(span("Procs").setTitle("Number of assigned processes")).setDisplayType(EDTColType.INT, aDisplayLocale) : null, bShowDetails ? new DTCol(span("EPs").setTitle("Number of assigned endpoints")).setDisplayType(EDTColType.INT, aDisplayLocale) : null, new BootstrapDTColAction(aDisplayLocale)).setID(getID());
    for (final ISMPServiceGroup aCurObject : aAllServiceGroups) {
        final ISimpleURL aViewLink = createViewURL(aWPEC, aCurObject);
        final String sDisplayName = aCurObject.getParticipantIdentifier().getURIEncoded();
        final HCRow aRow = aTable.addBodyRow();
        aRow.addCell(new HCA(aViewLink).addChild(sDisplayName));
        aRow.addCell(SMPCommonUI.getOwnerName(aCurObject.getOwnerID()));
        if (bShowBusinessCardName) {
            IHCNode aName = null;
            final ISMPBusinessCard aBC = aBCMgr.getSMPBusinessCardOfServiceGroup(aCurObject);
            if (aBC != null) {
                final SMPBusinessCardEntity aEntity = aBC.getEntityAtIndex(0);
                if (aEntity != null && aEntity.names().isNotEmpty())
                    aName = HCTextNode.createOnDemand(aEntity.names().getFirst().getName());
            }
            aRow.addCell(aName);
        }
        if (bShowExtensionDetails) {
            if (aCurObject.extensions().isNotEmpty())
                aRow.addCell(new HCCode().addChildren(HCExtHelper.nl2divList(aCurObject.getFirstExtensionXML())));
            else
                aRow.addCell();
        } else {
            aRow.addCell(EPhotonCoreText.getYesOrNo(aCurObject.extensions().isNotEmpty(), aDisplayLocale));
        }
        if (bShowDetails) {
            int nProcesses = 0;
            int nEndpoints = 0;
            final ICommonsList<ISMPServiceInformation> aSIs = aServiceInfoMgr.getAllSMPServiceInformationOfServiceGroup(aCurObject);
            for (final ISMPServiceInformation aSI : aSIs) {
                nProcesses += aSI.getProcessCount();
                nEndpoints += aSI.getTotalEndpointCount();
            }
            aRow.addCell(Integer.toString(aSIs.size()));
            aRow.addCell(Integer.toString(nProcesses));
            aRow.addCell(Integer.toString(nEndpoints));
        }
        final HCNodeList aActions = new HCNodeList();
        aActions.addChildren(createEditLink(aWPEC, aCurObject, "Edit " + sDisplayName), new HCTextNode(" "), createCopyLink(aWPEC, aCurObject, "Copy " + sDisplayName), new HCTextNode(" "), createDeleteLink(aWPEC, aCurObject, "Delete " + sDisplayName), new HCTextNode(" "), new HCA(LinkHelper.getURLWithServerAndContext(aCurObject.getParticipantIdentifier().getURIPercentEncoded())).setTitle("Perform SMP query on " + sDisplayName).setTargetBlank().addChild(EFamFamIcon.SCRIPT_GO.getAsNode()));
        if (eRESTType.isCompleteServiceGroupSupported()) {
            aActions.addChildren(new HCTextNode(" "), new HCA(LinkHelper.getURLWithServerAndContext("complete/" + aCurObject.getParticipantIdentifier().getURIPercentEncoded())).setTitle("Perform complete SMP query on " + sDisplayName).setTargetBlank().addChild(EFamFamIcon.SCRIPT_LINK.getAsNode()));
        }
        aRow.addCell(aActions);
    }
    final DataTables aDataTables = BootstrapDataTables.createDefaultDataTables(aWPEC, aTable);
    aNodeList.addChild(aTable).addChild(aDataTables);
}
Also used : Locale(java.util.Locale) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) HCNodeList(com.helger.html.hc.impl.HCNodeList) HCRow(com.helger.html.hc.html.tabular.HCRow) ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) ISimpleURL(com.helger.commons.url.ISimpleURL) BootstrapDTColAction(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDTColAction) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) BootstrapDataTables(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDataTables) DataTables(com.helger.photon.uictrls.datatables.DataTables) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) HCCode(com.helger.html.hc.html.textlevel.HCCode) ESMPRESTType(com.helger.phoss.smp.ESMPRESTType) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) HCA(com.helger.html.hc.html.textlevel.HCA) SMPBusinessCardEntity(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardEntity) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) ISMPBusinessCardManager(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager) HCTable(com.helger.html.hc.html.tabular.HCTable) ISMPSettings(com.helger.phoss.smp.settings.ISMPSettings) DTCol(com.helger.photon.uictrls.datatables.column.DTCol) HCTextNode(com.helger.html.hc.impl.HCTextNode) IHCNode(com.helger.html.hc.IHCNode)

Example 2 with ESMPRESTType

use of com.helger.phoss.smp.ESMPRESTType in project phoss-smp by phax.

the class PageSecureSMLRegistration method _registerSMPtoSML.

private void _registerSMPtoSML(@Nonnull final WebPageExecutionContext aWPEC, @Nonnull final FormErrorList aFormErrors) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final ESMPRESTType eRESTType = SMPServerConfiguration.getRESTType();
    final boolean bUsePeppolConstraints = eRESTType.isPeppol();
    final boolean bUsePathConstraints = eRESTType.isPathConstraint();
    final String sSMLID = aWPEC.params().getAsString(FIELD_SML_ID);
    final ISMLInfo aSMLInfo = SMPMetaManager.getSMLInfoMgr().getSMLInfoOfID(sSMLID);
    final String sPhysicalAddress = aWPEC.params().getAsString(FIELD_PHYSICAL_ADDRESS);
    final String sLogicalAddress = aWPEC.params().getAsString(FIELD_LOGICAL_ADDRESS);
    if (aSMLInfo == null)
        aFormErrors.addFieldError(FIELD_SML_ID, "A valid SML must be selected!");
    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) {
            aFormErrors.addFieldError(FIELD_PHYSICAL_ADDRESS, "The provided IP address does not resolve to a valid host. " + SMPCommonUI.getTechnicalDetailsString(ex));
        }
    }
    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 (!"http".equals(aURL.getProtocol())) {
                if (bUsePeppolConstraints || !"https".equals(aURL.getProtocol()))
                    aFormErrors.addFieldError(FIELD_LOGICAL_ADDRESS, "The provided logical address must use the 'http'" + (bUsePeppolConstraints ? "" : " or the 'https'") + " protocol and may not use the '" + aURL.getProtocol() + "' protocol." + (bUsePeppolConstraints ? " According to the Peppol SMP specification, no other protocols than 'http' are allowed!" : ""));
            }
            if (bUsePeppolConstraints) {
                // -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 (bUsePathConstraints) {
                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 SMP specifications it must run in the root (/) path!");
            }
        }
    }
    if (aFormErrors.isEmpty()) {
        final String sSMPID = SMPServerConfiguration.getSMLSMPID();
        try {
            final SSLSocketFactory aSocketFactory = SMPKeyManager.getInstance().createSSLContext().getSocketFactory();
            final ManageServiceMetadataServiceCaller aCaller = _create(aSMLInfo, 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(SMPCommonUI.getTechnicalDetailsUI(ex)));
            AuditHelper.onAuditExecuteFailure("smp-sml-create", sSMPID, sPhysicalAddress, sLogicalAddress, 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) UnknownHostException(java.net.UnknownHostException) ESMPRESTType(com.helger.phoss.smp.ESMPRESTType) ISMLInfo(com.helger.peppol.sml.ISMLInfo) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) URL(java.net.URL) UnknownHostException(java.net.UnknownHostException)

Example 3 with ESMPRESTType

use of com.helger.phoss.smp.ESMPRESTType in project phoss-smp by phax.

the class PageSecureSMLRegistration method _updateSMPatSML.

private void _updateSMPatSML(@Nonnull final WebPageExecutionContext aWPEC, @Nonnull final FormErrorList aFormErrors) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final ESMPRESTType eRESTType = SMPServerConfiguration.getRESTType();
    final boolean bUsePeppolConstraints = eRESTType.isPeppol();
    final boolean bUsePathConstraints = eRESTType.isPathConstraint();
    final String sSMLID = aWPEC.params().getAsString(FIELD_SML_ID);
    final ISMLInfo aSMLInfo = SMPMetaManager.getSMLInfoMgr().getSMLInfoOfID(sSMLID);
    final String sPhysicalAddress = aWPEC.params().getAsString(FIELD_PHYSICAL_ADDRESS);
    final String sLogicalAddress = aWPEC.params().getAsString(FIELD_LOGICAL_ADDRESS);
    if (aSMLInfo == null)
        aFormErrors.addFieldError(FIELD_SML_ID, "A valid SML must be selected!");
    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) {
            aFormErrors.addFieldError(FIELD_PHYSICAL_ADDRESS, "The provided IP address does not resolve to a valid host. " + SMPCommonUI.getTechnicalDetailsString(ex));
        }
    }
    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 (!"http".equals(aURL.getProtocol())) {
                if (bUsePeppolConstraints || !"https".equals(aURL.getProtocol()))
                    aFormErrors.addFieldError(FIELD_LOGICAL_ADDRESS, "The provided logical address must use the 'http'" + (bUsePeppolConstraints ? "" : " or the 'https'") + " protocol and may not use the '" + aURL.getProtocol() + "' protocol." + (bUsePeppolConstraints ? " According to the Peppol SMP specification, no other protocols than 'http' are allowed!" : ""));
            }
            if (bUsePeppolConstraints) {
                // -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 (bUsePathConstraints) {
                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 SMP specifications it must run in the root (/) path!");
            }
        }
    }
    if (aFormErrors.isEmpty()) {
        final String sSMPID = SMPServerConfiguration.getSMLSMPID();
        try {
            final SSLSocketFactory aSocketFactory = SMPKeyManager.getInstance().createSSLContext().getSocketFactory();
            final ManageServiceMetadataServiceCaller aCaller = _create(aSMLInfo, aSocketFactory);
            aCaller.update(sSMPID, sPhysicalAddress, sLogicalAddress);
            final String sMsg = "Successfully updated SMP '" + sSMPID + "' with physical address '" + sPhysicalAddress + "' and logical address '" + sLogicalAddress + "' at the SML '" + aSMLInfo.getManagementServiceURL() + "'.";
            LOGGER.info(sMsg);
            aNodeList.addChild(success(sMsg));
            AuditHelper.onAuditExecuteSuccess("smp-sml-update", sSMPID, sPhysicalAddress, sLogicalAddress, aSMLInfo.getManagementServiceURL());
        } catch (final Exception ex) {
            final String sMsg = "Error updating SMP '" + sSMPID + "' with physical address '" + sPhysicalAddress + "' and logical address '" + sLogicalAddress + "' to the SML '" + aSMLInfo.getManagementServiceURL() + "'.";
            aNodeList.addChild(error(sMsg).addChild(SMPCommonUI.getTechnicalDetailsUI(ex)));
            AuditHelper.onAuditExecuteFailure("smp-sml-update", sSMPID, sPhysicalAddress, sLogicalAddress, 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) UnknownHostException(java.net.UnknownHostException) ESMPRESTType(com.helger.phoss.smp.ESMPRESTType) ISMLInfo(com.helger.peppol.sml.ISMLInfo) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) URL(java.net.URL) UnknownHostException(java.net.UnknownHostException)

Aggregations

HCNodeList (com.helger.html.hc.impl.HCNodeList)3 ESMPRESTType (com.helger.phoss.smp.ESMPRESTType)3 ISMLInfo (com.helger.peppol.sml.ISMLInfo)2 ManageServiceMetadataServiceCaller (com.helger.peppol.smlclient.ManageServiceMetadataServiceCaller)2 URL (java.net.URL)2 UnknownHostException (java.net.UnknownHostException)2 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)2 ISimpleURL (com.helger.commons.url.ISimpleURL)1 IHCNode (com.helger.html.hc.IHCNode)1 HCRow (com.helger.html.hc.html.tabular.HCRow)1 HCTable (com.helger.html.hc.html.tabular.HCTable)1 HCA (com.helger.html.hc.html.textlevel.HCA)1 HCCode (com.helger.html.hc.html.textlevel.HCCode)1 HCTextNode (com.helger.html.hc.impl.HCTextNode)1 ISMPBusinessCard (com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard)1 ISMPBusinessCardManager (com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager)1 SMPBusinessCardEntity (com.helger.phoss.smp.domain.businesscard.SMPBusinessCardEntity)1 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)1 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)1 ISMPServiceInformation (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation)1