Search in sources :

Example 16 with ManageServiceMetadataServiceCaller

use of com.helger.peppol.smlclient.ManageServiceMetadataServiceCaller in project phoss-smp by phax.

the class PageSecureSMLRegistration method _create.

@Nonnull
private static ManageServiceMetadataServiceCaller _create(@Nonnull final ISMLInfo aSML, @Nonnull final SSLSocketFactory aSocketFactory) {
    final ManageServiceMetadataServiceCaller ret = new ManageServiceMetadataServiceCaller(aSML);
    ret.setSSLSocketFactory(aSocketFactory);
    return ret;
}
Also used : ManageServiceMetadataServiceCaller(com.helger.peppol.smlclient.ManageServiceMetadataServiceCaller) Nonnull(javax.annotation.Nonnull)

Example 17 with ManageServiceMetadataServiceCaller

use of com.helger.peppol.smlclient.ManageServiceMetadataServiceCaller in project peppol-practical by phax.

the class PagePublicToolsSMPSML method _deleteSMPfromSML.

private void _deleteSMPfromSML(@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 IFileItem aKeyStoreFile = aWPEC.params().getAsFileItem(FIELD_KEYSTORE);
    final String sKeyStorePassword = aWPEC.params().getAsString(FIELD_KEYSTORE_PW);
    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);
    final SSLSocketFactory aSocketFactory = _loadKeyStoreAndCreateSSLSocketFactory(EKeyStoreType.JKS, SECURITY_PROVIDER, aKeyStoreFile, sKeyStorePassword, aFormErrors, aDisplayLocale);
    if (aFormErrors.isEmpty()) {
        try {
            final ManageServiceMetadataServiceCaller aCaller = _create(aSMLInfo.getSMLInfo(), 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(AppCommonUI.getTechnicalDetailsUI(ex, true)));
            AuditHelper.onAuditExecuteFailure("smp-sml-delete", sSMPID, 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) 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) CertificateExpiredException(java.security.cert.CertificateExpiredException) ClientTransportException(com.sun.xml.ws.client.ClientTransportException) CertificateNotYetValidException(java.security.cert.CertificateNotYetValidException) UnknownHostException(java.net.UnknownHostException)

Example 18 with ManageServiceMetadataServiceCaller

use of com.helger.peppol.smlclient.ManageServiceMetadataServiceCaller in project peppol-practical by phax.

the class PagePublicToolsSMPSML method _updateSMPatSML.

private void _updateSMPatSML(@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 Exception ex) {
            aFormErrors.addFieldError(FIELD_PHYSICAL_ADDRESS, "The provided IP address does not resolve to a valid host. " + 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()))
                    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.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(AppCommonUI.getTechnicalDetailsUI(ex, true)));
            AuditHelper.onAuditExecuteFailure("smp-sml-update", 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) 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) CertificateExpiredException(java.security.cert.CertificateExpiredException) ClientTransportException(com.sun.xml.ws.client.ClientTransportException) CertificateNotYetValidException(java.security.cert.CertificateNotYetValidException) UnknownHostException(java.net.UnknownHostException) URL(java.net.URL) SimpleURL(com.helger.commons.url.SimpleURL)

Aggregations

ManageServiceMetadataServiceCaller (com.helger.peppol.smlclient.ManageServiceMetadataServiceCaller)18 HCNodeList (com.helger.html.hc.impl.HCNodeList)6 UnknownHostException (java.net.UnknownHostException)6 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)6 NotFoundFault (com.helger.peppol.smlclient.smp.NotFoundFault)5 ManageParticipantIdentifierServiceCaller (com.helger.peppol.smlclient.ManageParticipantIdentifierServiceCaller)4 URL (java.net.URL)4 Test (org.junit.Test)4 PDTFromString (com.helger.commons.datetime.PDTFromString)3 PDTToString (com.helger.commons.datetime.PDTToString)3 ISMLConfigurationManager (com.helger.peppol.app.mgr.ISMLConfigurationManager)3 ISMLConfiguration (com.helger.peppol.domain.ISMLConfiguration)3 ISMLInfo (com.helger.peppol.sml.ISMLInfo)3 IFileItem (com.helger.web.fileupload.IFileItem)3 ClientTransportException (com.sun.xml.ws.client.ClientTransportException)3 CertificateExpiredException (java.security.cert.CertificateExpiredException)3 CertificateNotYetValidException (java.security.cert.CertificateNotYetValidException)3 Locale (java.util.Locale)3 Nonnull (javax.annotation.Nonnull)3 Before (org.junit.Before)3