Search in sources :

Example 26 with IIdentifierFactory

use of com.helger.peppolid.factory.IIdentifierFactory in project phoss-smp by phax.

the class PageSecureServiceGroup method getSelectedObject.

@Override
@Nullable
protected ISMPServiceGroup getSelectedObject(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final String sID) {
    if (sID == null)
        return null;
    final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
    final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
    return aServiceGroupMgr.getSMPServiceGroupOfID(aIdentifierFactory.parseParticipantIdentifier(sID));
}
Also used : ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) Nullable(javax.annotation.Nullable)

Example 27 with IIdentifierFactory

use of com.helger.peppolid.factory.IIdentifierFactory in project phoss-smp by phax.

the class PageSecureServiceGroup method validateAndSaveInputParameters.

@Override
protected void validateAndSaveInputParameters(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMPServiceGroup aSelectedObject, @Nonnull final FormErrorList aFormErrors, @Nonnull final EWebPageFormAction eFormAction) {
    final boolean bEdit = eFormAction.isEdit();
    final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
    final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
    final String sParticipantIDScheme = aWPEC.params().getAsStringTrimmed(FIELD_PARTICIPANT_ID_SCHEME);
    final String sParticipantIDValue = aWPEC.params().getAsStringTrimmed(FIELD_PARTICIPANT_ID_VALUE);
    IParticipantIdentifier aParticipantID = null;
    final String sOwningUserID = aWPEC.params().getAsStringTrimmed(FIELD_OWNING_USER_ID);
    final IUser aOwningUser = PhotonSecurityManager.getUserMgr().getUserOfID(sOwningUserID);
    final String sExtension = aWPEC.params().getAsStringTrimmed(FIELD_EXTENSION);
    // validations
    if (aIdentifierFactory.isParticipantIdentifierSchemeMandatory() && StringHelper.hasNoText(sParticipantIDScheme))
        aFormErrors.addFieldError(FIELD_PARTICIPANT_ID_SCHEME, "Participant ID scheme must not be empty!");
    else if (StringHelper.hasNoText(sParticipantIDValue))
        aFormErrors.addFieldError(FIELD_PARTICIPANT_ID_VALUE, "Participant ID value must not be empty!");
    else {
        aParticipantID = aIdentifierFactory.createParticipantIdentifier(sParticipantIDScheme, sParticipantIDValue);
        if (aParticipantID == null)
            aFormErrors.addFieldError(FIELD_PARTICIPANT_ID_VALUE, "The provided participant ID has an invalid syntax!");
        else if (!bEdit && aServiceGroupMgr.getSMPServiceGroupOfID(aParticipantID) != null)
            aFormErrors.addFieldError(FIELD_PARTICIPANT_ID_VALUE, "Another service group for the same participant ID is already present (may be case insensitive)!");
    }
    if (StringHelper.hasNoText(sOwningUserID))
        aFormErrors.addFieldError(FIELD_OWNING_USER_ID, "Owning User must not be empty!");
    else if (aOwningUser == null)
        aFormErrors.addFieldError(FIELD_OWNING_USER_ID, "Provided owning user does not exist!");
    if (StringHelper.hasText(sExtension)) {
        final IMicroDocument aDoc = MicroReader.readMicroXML(sExtension);
        if (aDoc == null)
            aFormErrors.addFieldError(FIELD_EXTENSION, "The extension must be XML content.");
    }
    if (aFormErrors.isEmpty()) {
        if (bEdit) {
            // necessary. Only the owner and the extension can be edited!
            try {
                aServiceGroupMgr.updateSMPServiceGroup(aParticipantID, aOwningUser.getID(), sExtension);
                aWPEC.postRedirectGetInternal(success("The SMP Service Group for participant '" + aParticipantID.getURIEncoded() + "' was successfully updated."));
            } catch (final SMPServerException ex) {
                aWPEC.postRedirectGetInternal(error("Error updating the SMP Service Group for participant '" + aParticipantID.getURIEncoded() + "'.").addChild(SMPCommonUI.getTechnicalDetailsUI(ex)));
            }
        } else {
            // Create the service group both locally and on the SML (if active)!
            ISMPServiceGroup aSG = null;
            Exception aCaughtEx = null;
            try {
                aSG = aServiceGroupMgr.createSMPServiceGroup(aOwningUser.getID(), aParticipantID, sExtension, true);
            } catch (final Exception ex) {
                aCaughtEx = ex;
            }
            if (aSG != null) {
                aWPEC.postRedirectGetInternal(success("The new SMP Service Group for participant '" + aParticipantID.getURIEncoded() + "' was successfully created."));
            } else {
                aWPEC.postRedirectGetInternal(error("Error creating the new SMP Service Group for participant '" + aParticipantID.getURIEncoded() + "'.").addChild(SMPCommonUI.getTechnicalDetailsUI(aCaughtEx)));
            }
        }
    }
}
Also used : ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) IUser(com.helger.photon.security.user.IUser) IMicroDocument(com.helger.xml.microdom.IMicroDocument) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) SMPDNSResolutionException(com.helger.smpclient.url.SMPDNSResolutionException) SMPServerException(com.helger.phoss.smp.exception.SMPServerException) RegistrationHookException(com.helger.phoss.smp.smlhook.RegistrationHookException) UnknownHostException(java.net.UnknownHostException) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) SMPServerException(com.helger.phoss.smp.exception.SMPServerException)

Example 28 with IIdentifierFactory

use of com.helger.peppolid.factory.IIdentifierFactory in project phoss-smp by phax.

the class PageSecureServiceGroupMigrationInbound method validateAndSaveInputParameters.

@Override
protected void validateAndSaveInputParameters(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMPParticipantMigration aSelectedObject, @Nonnull final FormErrorList aFormErrors, @Nonnull final EWebPageFormAction eFormAction) {
    final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
    final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
    final ISMPSettings aSettings = SMPMetaManager.getSettings();
    final ISMPParticipantMigrationManager aParticipantMigrationMgr = SMPMetaManager.getParticipantMigrationMgr();
    final String sMigrationKey = aWPEC.params().getAsStringTrimmed(FIELD_MIGRATION_KEY);
    final String sParticipantIDScheme = aWPEC.params().getAsStringTrimmed(FIELD_PARTICIPANT_ID_SCHEME);
    final String sParticipantIDValue = aWPEC.params().getAsStringTrimmed(FIELD_PARTICIPANT_ID_VALUE);
    IParticipantIdentifier aParticipantID = null;
    final String sOwningUserID = aWPEC.params().getAsStringTrimmed(FIELD_OWNING_USER_ID);
    final IUser aOwningUser = PhotonSecurityManager.getUserMgr().getUserOfID(sOwningUserID);
    final String sExtension = aWPEC.params().getAsStringTrimmed(FIELD_EXTENSION);
    // validations
    if (StringHelper.hasNoText(sMigrationKey))
        aFormErrors.addFieldError(FIELD_MIGRATION_KEY, "The migration key must not be empty!");
    else if (!SMPParticipantMigration.isValidMigrationKey(sMigrationKey))
        aFormErrors.addFieldError(FIELD_MIGRATION_KEY, "The migration key is not valid. Please verify the received code is correct.");
    if (aIdentifierFactory.isParticipantIdentifierSchemeMandatory() && StringHelper.hasNoText(sParticipantIDScheme))
        aFormErrors.addFieldError(FIELD_PARTICIPANT_ID_SCHEME, "Participant ID scheme must not be empty!");
    else if (StringHelper.hasNoText(sParticipantIDValue))
        aFormErrors.addFieldError(FIELD_PARTICIPANT_ID_VALUE, "Participant ID value must not be empty!");
    else {
        aParticipantID = aIdentifierFactory.createParticipantIdentifier(sParticipantIDScheme, sParticipantIDValue);
        if (aParticipantID == null)
            aFormErrors.addFieldError(FIELD_PARTICIPANT_ID_VALUE, "The provided participant ID has an invalid syntax!");
        else if (aServiceGroupMgr.getSMPServiceGroupOfID(aParticipantID) != null)
            aFormErrors.addFieldError(FIELD_PARTICIPANT_ID_VALUE, "Another service group for the same participant ID is already present (may be case insensitive)!");
    }
    if (StringHelper.hasNoText(sOwningUserID))
        aFormErrors.addFieldError(FIELD_OWNING_USER_ID, "Owning User must not be empty!");
    else if (aOwningUser == null)
        aFormErrors.addFieldError(FIELD_OWNING_USER_ID, "Provided owning user does not exist!");
    if (StringHelper.hasText(sExtension)) {
        final IMicroDocument aDoc = MicroReader.readMicroXML(sExtension);
        if (aDoc == null)
            aFormErrors.addFieldError(FIELD_EXTENSION, "The extension must be XML content.");
    }
    final HCNodeList aRedirectNotes = new HCNodeList();
    if (aFormErrors.isEmpty()) {
        // create the Service Group locally
        try {
            final ManageParticipantIdentifierServiceCaller aCaller = new ManageParticipantIdentifierServiceCaller(aSettings.getSMLInfo());
            aCaller.setSSLSocketFactory(SMPKeyManager.getInstance().createSSLContext().getSocketFactory());
            // SML call
            aCaller.migrate(aParticipantID, sMigrationKey, SMPServerConfiguration.getSMLSMPID());
            LOGGER.info("Successfully migrated '" + aParticipantID.getURIEncoded() + "' in the SML to this SMP using migration key '" + sMigrationKey + "'");
            aRedirectNotes.addChild(success("Successfully migrated '" + aParticipantID.getURIEncoded() + "' in SML to this SMP using migration key ").addChild(code(sMigrationKey)));
        } catch (final Exception ex) {
            LOGGER.error("Error invoking migrate on SML", ex);
            // Use a global field error here, to avoid that users must enter the
            // values over and over in case of error
            aFormErrors.add(SingleError.builderError().errorText("Failed to confirm the migration for participant '" + aParticipantID.getURIEncoded() + "' in SML, hence the migration failed." + " Please check the participant identifier and the migration key.\n" + BootstrapTechnicalUI.getTechnicalDetailsString(ex, CSMPServer.DEFAULT_LOCALE)).build());
            if (false)
                aWPEC.postRedirectGetInternal(error("Failed to confirm the migration for participant '" + aParticipantID.getURIEncoded() + "' in SML, hence the migration failed." + " Please check the participant identifier and the migration key.").addChild(SMPCommonUI.getTechnicalDetailsUI(ex)));
        }
    }
    if (aFormErrors.isEmpty()) {
        // Now create the service group locally (it was already checked that the
        // PID is available on this SMP)
        ISMPServiceGroup aSG = null;
        Exception aCaughtEx = null;
        try {
            // Do NOT create in SMK/SML
            aSG = aServiceGroupMgr.createSMPServiceGroup(aOwningUser.getID(), aParticipantID, sExtension, false);
        } catch (final Exception ex) {
            aCaughtEx = ex;
        }
        if (aSG != null) {
            aRedirectNotes.addChild(success("The new SMP Service Group for participant '" + aParticipantID.getURIEncoded() + "' was successfully created."));
        } else {
            aRedirectNotes.addChild(error("Error creating the new SMP Service Group for participant '" + aParticipantID.getURIEncoded() + "'.").addChild(SMPCommonUI.getTechnicalDetailsUI(aCaughtEx)));
        }
        // Remember internally
        if (aParticipantMigrationMgr.createInboundParticipantMigration(aParticipantID, sMigrationKey) != null) {
            aRedirectNotes.addChild(success().addChild(div("The participant migration for '" + aParticipantID.getURIEncoded() + "' with migration key ").addChild(code(sMigrationKey)).addChild(" was successfully performed.")).addChild(div("Please inform the source SMP that the migration was successful.")));
        } else {
            aRedirectNotes.addChild(error("Failed to store the participant migration for '" + aParticipantID.getURIEncoded() + "'."));
        }
        aWPEC.postRedirectGetInternal(aRedirectNotes);
    }
}
Also used : ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) HCNodeList(com.helger.html.hc.impl.HCNodeList) ISMPSettings(com.helger.phoss.smp.settings.ISMPSettings) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) IUser(com.helger.photon.security.user.IUser) ISMPParticipantMigrationManager(com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigrationManager) PDTToString(com.helger.commons.datetime.PDTToString) IMicroDocument(com.helger.xml.microdom.IMicroDocument) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) ManageParticipantIdentifierServiceCaller(com.helger.peppol.smlclient.ManageParticipantIdentifierServiceCaller) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 29 with IIdentifierFactory

use of com.helger.peppolid.factory.IIdentifierFactory in project phoss-smp by phax.

the class PageSecureServiceGroupMigrationInbound method showInputForm.

@Override
protected void showInputForm(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMPParticipantMigration aSelectedObject, @Nonnull final BootstrapForm aForm, final boolean bIsFormSubmitted, @Nonnull final EWebPageFormAction eFormAction, @Nonnull final FormErrorList aFormErrors) {
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Migration Key").setCtrl(new HCEdit(new RequestField(FIELD_MIGRATION_KEY))).setHelpText("The migration key received from the other SMP that was acknowledged by the SMK/SML.").setErrorList(aFormErrors.getListOfField(FIELD_MIGRATION_KEY)));
    {
        final String sDefaultScheme = aIdentifierFactory.getDefaultParticipantIdentifierScheme();
        final BootstrapRow aRow = new BootstrapRow();
        aRow.createColumn(GS_IDENTIFIER_SCHEME).addChild(new HCEdit(new RequestField(FIELD_PARTICIPANT_ID_SCHEME, aSelectedObject != null ? aSelectedObject.getParticipantIdentifier().getScheme() : sDefaultScheme)).setPlaceholder("Identifier scheme"));
        aRow.createColumn(GS_IDENTIFIER_VALUE).addChild(new HCEdit(new RequestField(FIELD_PARTICIPANT_ID_VALUE, aSelectedObject != null ? aSelectedObject.getParticipantIdentifier().getValue() : null)).setPlaceholder("Identifier value"));
        aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Participant ID").setCtrl(aRow).setHelpText("The participant identifier for which the service group should be created. The left part is the identifier scheme" + (sDefaultScheme == null ? "" : " (default: " + sDefaultScheme + ")") + ", the right part is the identifier value (e.g. 9915:test)").setErrorList(aFormErrors.getListOfFields(FIELD_PARTICIPANT_ID_SCHEME, FIELD_PARTICIPANT_ID_VALUE)));
    }
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Owning User").setCtrl(new HCUserSelect(new RequestField(FIELD_OWNING_USER_ID, LoggedInUserManager.getInstance().getCurrentUserID()), aDisplayLocale)).setHelpText("The user who owns this entry. Only this user can make changes via the REST API.").setErrorList(aFormErrors.getListOfField(FIELD_OWNING_USER_ID)));
    aForm.addFormGroup(new BootstrapFormGroup().setLabel("Extension").setCtrl(new HCTextArea(new RequestField(FIELD_EXTENSION))).setHelpText("Optional extension to the service group. If present it must be valid XML content!").setErrorList(aFormErrors.getListOfField(FIELD_EXTENSION)));
}
Also used : Locale(java.util.Locale) HCUserSelect(com.helger.phoss.smp.ui.secure.hc.HCUserSelect) BootstrapRow(com.helger.photon.bootstrap4.grid.BootstrapRow) HCTextArea(com.helger.html.hc.html.forms.HCTextArea) HCEdit(com.helger.html.hc.html.forms.HCEdit) PDTToString(com.helger.commons.datetime.PDTToString) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) RequestField(com.helger.photon.core.form.RequestField)

Example 30 with IIdentifierFactory

use of com.helger.peppolid.factory.IIdentifierFactory in project phoss-smp by phax.

the class PageSecureRedirect method showInputForm.

@Override
protected void showInputForm(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMPRedirect aSelectedObject, @Nonnull final BootstrapForm aForm, final boolean bFormSubmitted, @Nonnull final EWebPageFormAction eFormAction, @Nonnull final FormErrorList aFormErrors) {
    final boolean bEdit = eFormAction.isEdit();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
    aForm.addChild(getUIHandler().createActionHeader(bEdit ? "Edit Redirect" : "Create new Redirect"));
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Service Group").setCtrl(new HCServiceGroupSelect(new RequestField(FIELD_SERVICE_GROUP_ID, aSelectedObject != null ? aSelectedObject.getServiceGroupID() : null), aDisplayLocale).setReadOnly(bEdit)).setErrorList(aFormErrors.getListOfField(FIELD_SERVICE_GROUP_ID)));
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Document Type ID").setCtrl(new HCEdit(new RequestField(FIELD_DOCTYPE_ID, aSelectedObject != null ? aSelectedObject.getDocumentTypeIdentifier().getURIEncoded() : aIdentifierFactory.getDefaultDocumentTypeIdentifierScheme() + CIdentifier.URL_SCHEME_VALUE_SEPARATOR)).setReadOnly(bEdit)).setErrorList(aFormErrors.getListOfField(FIELD_DOCTYPE_ID)));
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Redirect To").setCtrl(new HCEdit(new RequestField(FIELD_REDIRECT_TO, aSelectedObject != null ? aSelectedObject.getTargetHref() : null))).setHelpText("URL to redirect to. Must include the service group and the document type in the URL!").setErrorList(aFormErrors.getListOfField(FIELD_REDIRECT_TO)));
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Subject Unique Identifier").setCtrl(new HCEdit(new RequestField(FIELD_SUBJECT_UNIQUE_IDENTIFIER, aSelectedObject != null ? aSelectedObject.getSubjectUniqueIdentifier() : null))).setHelpText("Holds the Subject Unique Identifier of the certificate of the " + "destination SMP. A client SHOULD validate that the Subject " + "Unique Identifier of the certificate used to sign the resource at the " + "destination SMP matches the Subject Unique Identifier published in " + "the redirecting SMP.").setErrorList(aFormErrors.getListOfField(FIELD_SUBJECT_UNIQUE_IDENTIFIER)));
    aForm.addFormGroup(new BootstrapFormGroup().setLabel("Extension").setCtrl(new HCTextArea(new RequestField(FIELD_EXTENSION, aSelectedObject != null ? aSelectedObject.getFirstExtensionXML() : null))).setHelpText("Optional extension to the service group. If present it must be valid XML content!").setErrorList(aFormErrors.getListOfField(FIELD_EXTENSION)));
}
Also used : Locale(java.util.Locale) HCServiceGroupSelect(com.helger.phoss.smp.ui.secure.hc.HCServiceGroupSelect) HCTextArea(com.helger.html.hc.html.forms.HCTextArea) HCEdit(com.helger.html.hc.html.forms.HCEdit) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) RequestField(com.helger.photon.core.form.RequestField)

Aggregations

IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)84 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)57 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)34 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)33 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)30 SMPServerException (com.helger.phoss.smp.exception.SMPServerException)22 IUser (com.helger.photon.security.user.IUser)20 Nonnull (javax.annotation.Nonnull)19 Test (org.junit.Test)19 ISMPServiceInformationManager (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager)17 SMPNotFoundException (com.helger.phoss.smp.exception.SMPNotFoundException)16 ISMPRedirectManager (com.helger.phoss.smp.domain.redirect.ISMPRedirectManager)15 ISMPServiceInformation (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation)13 SMPBadRequestException (com.helger.phoss.smp.exception.SMPBadRequestException)13 HCNodeList (com.helger.html.hc.impl.HCNodeList)11 BootstrapFormGroup (com.helger.photon.bootstrap4.form.BootstrapFormGroup)11 Locale (java.util.Locale)11 Nullable (javax.annotation.Nullable)11 HCEdit (com.helger.html.hc.html.forms.HCEdit)10 RequestField (com.helger.photon.core.form.RequestField)10