Search in sources :

Example 6 with ManageServiceMetadataServiceCaller

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

the class PageSecureSMLCertificateUpdate 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 7 with ManageServiceMetadataServiceCaller

use of com.helger.peppol.smlclient.ManageServiceMetadataServiceCaller 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 8 with ManageServiceMetadataServiceCaller

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

the class PageSecureSMLRegistration method _deleteSMPfromSML.

private void _deleteSMPfromSML(@Nonnull final WebPageExecutionContext aWPEC, @Nonnull final FormErrorList aFormErrors) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final String sSMLID = aWPEC.params().getAsString(FIELD_SML_ID);
    final ISMLInfo aSMLInfo = SMPMetaManager.getSMLInfoMgr().getSMLInfoOfID(sSMLID);
    if (aSMLInfo == null)
        aFormErrors.addFieldError(FIELD_SML_ID, "A valid SML must be selected!");
    if (aFormErrors.isEmpty()) {
        final String sSMPID = SMPServerConfiguration.getSMLSMPID();
        try {
            final SSLSocketFactory aSocketFactory = SMPKeyManager.getInstance().createSSLContext().getSocketFactory();
            final ManageServiceMetadataServiceCaller aCaller = _create(aSMLInfo, 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(SMPCommonUI.getTechnicalDetailsUI(ex)));
            AuditHelper.onAuditExecuteFailure("smp-sml-delete", sSMPID, 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) ISMLInfo(com.helger.peppol.sml.ISMLInfo) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) UnknownHostException(java.net.UnknownHostException)

Example 9 with ManageServiceMetadataServiceCaller

use of com.helger.peppol.smlclient.ManageServiceMetadataServiceCaller 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)

Example 10 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)

Aggregations

ManageServiceMetadataServiceCaller (com.helger.peppol.smlclient.ManageServiceMetadataServiceCaller)14 NotFoundFault (com.helger.peppol.smlclient.smp.NotFoundFault)5 ManageParticipantIdentifierServiceCaller (com.helger.peppol.smlclient.ManageParticipantIdentifierServiceCaller)4 Test (org.junit.Test)4 HCNodeList (com.helger.html.hc.impl.HCNodeList)3 ISMLInfo (com.helger.peppol.sml.ISMLInfo)3 UnknownHostException (java.net.UnknownHostException)3 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)3 Before (org.junit.Before)3 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)2 ESMPRESTType (com.helger.phoss.smp.ESMPRESTType)2 URL (java.net.URL)2 Nonnull (javax.annotation.Nonnull)2 UnauthorizedFault (com.helger.peppol.smlclient.participant.UnauthorizedFault)1 PublisherEndpointType (com.helger.peppol.smlclient.smp.PublisherEndpointType)1 ServiceMetadataPublisherServiceType (com.helger.peppol.smlclient.smp.ServiceMetadataPublisherServiceType)1 After (org.junit.After)1