use of com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup 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);
}
}
use of com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup in project phoss-smp by phax.
the class PageSecureRedirect method isActionAllowed.
@Override
protected boolean isActionAllowed(@Nonnull final WebPageExecutionContext aWPEC, @Nonnull final EWebPageFormAction eFormAction, @Nullable final ISMPRedirect aSelectedObject) {
if (eFormAction == EWebPageFormAction.VIEW || eFormAction == EWebPageFormAction.COPY || eFormAction == EWebPageFormAction.EDIT || eFormAction == EWebPageFormAction.DELETE) {
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final String sServiceGroupID = aWPEC.params().getAsString(FIELD_SERVICE_GROUP_ID);
final IParticipantIdentifier aServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID);
final ISMPServiceGroup aServiceGroup = SMPMetaManager.getServiceGroupMgr().getSMPServiceGroupOfID(aServiceGroupID);
if (aServiceGroup != null) {
final String sDocTypeID = aWPEC.params().getAsString(FIELD_DOCTYPE_ID);
final IDocumentTypeIdentifier aDocTypeID = aIdentifierFactory.parseDocumentTypeIdentifier(sDocTypeID);
if (aDocTypeID != null) {
aWPEC.getRequestScope().attrs().putIn(ATTR_SERVICE_GROUP, aServiceGroup);
aWPEC.getRequestScope().attrs().putIn(ATTR_DOCTYPE_ID, aDocTypeID);
return true;
}
}
return false;
}
return super.isActionAllowed(aWPEC, eFormAction, aSelectedObject);
}
use of com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup in project phoss-smp by phax.
the class PageSecureRedirect method getSelectedObject.
@Override
@Nullable
protected ISMPRedirect getSelectedObject(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final String sID) {
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final String sServiceGroupID = aWPEC.params().getAsString(FIELD_SERVICE_GROUP_ID);
final IParticipantIdentifier aServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID);
final ISMPServiceGroup aServiceGroup = SMPMetaManager.getServiceGroupMgr().getSMPServiceGroupOfID(aServiceGroupID);
if (aServiceGroup != null) {
final String sDocTypeID = aWPEC.params().getAsString(FIELD_DOCTYPE_ID);
final IDocumentTypeIdentifier aDocTypeID = aIdentifierFactory.parseDocumentTypeIdentifier(sDocTypeID);
if (aDocTypeID != null) {
final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
return aRedirectMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDocTypeID);
}
}
return null;
}
use of com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup in project phoss-smp by phax.
the class PageSecureRedirect method validateAndSaveInputParameters.
@Override
protected void validateAndSaveInputParameters(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMPRedirect aSelectedObject, @Nonnull final FormErrorList aFormErrors, @Nonnull final EWebPageFormAction eFormAction) {
final boolean bEdit = eFormAction.isEdit();
final ISMPServiceGroupManager aServiceGroupManager = SMPMetaManager.getServiceGroupMgr();
final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final String sServiceGroupID = bEdit ? aSelectedObject.getServiceGroupID() : aWPEC.params().getAsString(FIELD_SERVICE_GROUP_ID);
ISMPServiceGroup aServiceGroup = null;
final String sDocTypeID = bEdit ? aSelectedObject.getDocumentTypeIdentifier().getURIEncoded() : aWPEC.params().getAsString(FIELD_DOCTYPE_ID);
IDocumentTypeIdentifier aDocTypeID = null;
final String sRedirectTo = aWPEC.params().getAsString(FIELD_REDIRECT_TO);
final String sSubjectUniqueIdentifier = aWPEC.params().getAsString(FIELD_SUBJECT_UNIQUE_IDENTIFIER);
// TODO add certificate redirect support
final X509Certificate aCertificate = null;
final String sExtension = aWPEC.params().getAsString(FIELD_EXTENSION);
// validations
if (StringHelper.hasNoText(sServiceGroupID))
aFormErrors.addFieldError(FIELD_SERVICE_GROUP_ID, "A Service Group must be selected!");
else {
aServiceGroup = aServiceGroupManager.getSMPServiceGroupOfID(aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID));
if (aServiceGroup == null)
aFormErrors.addFieldError(FIELD_SERVICE_GROUP_ID, "The provided Service Group does not exist!");
}
if (StringHelper.hasNoText(sDocTypeID))
aFormErrors.addFieldError(FIELD_DOCTYPE_ID, "Document Type ID must not be empty!");
else {
aDocTypeID = aIdentifierFactory.parseDocumentTypeIdentifier(sDocTypeID);
if (aDocTypeID == null)
aFormErrors.addFieldError(FIELD_DOCTYPE_ID, "The provided Document Type ID has an invalid syntax!");
else {
if (aServiceGroup != null) {
if (aServiceInfoMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aDocTypeID) != null)
aFormErrors.addFieldError(FIELD_DOCTYPE_ID, "At least one Endpoint is registered for this Document Type. Delete the Endpoint before you can create a Redirect.");
else if (!bEdit && aRedirectMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDocTypeID) != null)
aFormErrors.addFieldError(FIELD_DOCTYPE_ID, "Another Redirect for the provided Service Group and Document Type is already present.");
}
}
}
if (StringHelper.hasNoText(sRedirectTo))
aFormErrors.addFieldError(FIELD_REDIRECT_TO, "The Redirect URL must not be empty!");
else if (URLHelper.getAsURL(sRedirectTo) == null)
aFormErrors.addFieldError(FIELD_REDIRECT_TO, "The Redirect URL is not a valid URL!");
if (StringHelper.hasNoText(sSubjectUniqueIdentifier))
aFormErrors.addFieldError(FIELD_SUBJECT_UNIQUE_IDENTIFIER, "Subject Unique Identifier must not be empty!");
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 (aRedirectMgr.createOrUpdateSMPRedirect(aServiceGroup, aDocTypeID, sRedirectTo, sSubjectUniqueIdentifier, aCertificate, sExtension) == null)
aWPEC.postRedirectGetInternal(error("Error creating the Redirect for Service Group '" + sServiceGroupID + "'."));
else
aWPEC.postRedirectGetInternal(success("The Redirect for Service Group '" + sServiceGroupID + "' was successfully saved."));
}
}
use of com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup in project phoss-smp by phax.
the class ISMPBusinessCardManagerFuncTest method testBusinessCard.
@Test
public void testBusinessCard() throws SMPServerException {
final ISMPBusinessCardManager aBusinessCardMgr = SMPMetaManager.getBusinessCardMgr();
final String sUserID = CSecurity.USER_ADMINISTRATOR_ID;
if (SMPMetaManager.getInstance().getBackendConnectionState().isFalse()) {
// Failed to get DB connection. E.g. MySQL down or misconfigured.
return;
}
final SMPBusinessCardEntity aEntity1 = new SMPBusinessCardEntity();
aEntity1.names().add(new SMPBusinessCardName("Test entity", null));
aEntity1.setCountryCode("AT");
final SMPBusinessCardEntity aEntity2 = new SMPBusinessCardEntity();
aEntity2.names().add(new SMPBusinessCardName("Test entity2", null));
aEntity2.setCountryCode("AT");
aEntity2.setGeographicalInformation("Address here");
aEntity2.identifiers().add(new SMPBusinessCardIdentifier("gln", "1234567890123"));
aEntity2.websiteURIs().add("https://www.peppol-directory.org/fake");
aEntity2.contacts().add(new SMPBusinessCardContact("support", "Unit test support", null, "support@peppol.eu"));
aEntity2.setAdditionalInformation("Bla foo fasel");
aEntity2.setRegistrationDate(PDTFactory.getCurrentLocalDate());
final SMPBusinessCardEntity aEntity3 = new SMPBusinessCardEntity();
aEntity3.names().add(new SMPBusinessCardName("Test entity3", null));
aEntity3.setCountryCode("AT");
aEntity3.setAdditionalInformation("Entity 3");
final IParticipantIdentifier aPI1 = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9999:junittest1");
final IParticipantIdentifier aPI2 = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9999:junittest2");
final ISMPServiceGroupManager aSGMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPServiceGroup aSG = aSGMgr.createSMPServiceGroup(sUserID, aPI1, null, true);
assertNotNull(aSG);
ISMPBusinessCard aBusinessCard = null;
try {
final long nBCCount = aBusinessCardMgr.getSMPBusinessCardCount();
// Create new one
aBusinessCard = aBusinessCardMgr.createOrUpdateSMPBusinessCard(aPI1, new CommonsArrayList<>(aEntity1));
assertEquals(aPI1, aBusinessCard.getParticipantIdentifier());
assertEquals(1, aBusinessCard.getEntityCount());
assertEquals(nBCCount + 1, aBusinessCardMgr.getSMPBusinessCardCount());
assertEquals(aBusinessCard, aBusinessCardMgr.getSMPBusinessCardOfServiceGroup(aSG));
assertEquals(aBusinessCard, aBusinessCardMgr.getSMPBusinessCardOfID(aSG.getParticipantIdentifier()));
// Update existing
aBusinessCard = aBusinessCardMgr.createOrUpdateSMPBusinessCard(aPI1, new CommonsArrayList<>(aEntity1, aEntity2));
assertEquals(aPI1, aBusinessCard.getParticipantIdentifier());
assertEquals(2, aBusinessCard.getEntityCount());
// Must not have changed
assertEquals(nBCCount + 1, aBusinessCardMgr.getSMPBusinessCardCount());
assertEquals(aBusinessCard, aBusinessCardMgr.getSMPBusinessCardOfServiceGroup(aSG));
assertEquals(aBusinessCard, aBusinessCardMgr.getSMPBusinessCardOfID(aSG.getParticipantIdentifier()));
// Add second one
final ISMPServiceGroup aSG2 = aSGMgr.createSMPServiceGroup(sUserID, aPI2, null, true);
assertNotNull(aSG2);
ISMPBusinessCard aBusinessCard2 = null;
try {
aBusinessCard2 = aBusinessCardMgr.createOrUpdateSMPBusinessCard(aPI2, new CommonsArrayList<>(aEntity3));
assertEquals(aPI2, aBusinessCard2.getParticipantIdentifier());
assertEquals(1, aBusinessCard2.getEntityCount());
assertEquals(nBCCount + 2, aBusinessCardMgr.getSMPBusinessCardCount());
assertEquals(aBusinessCard2, aBusinessCardMgr.getSMPBusinessCardOfServiceGroup(aSG2));
assertEquals(aBusinessCard2, aBusinessCardMgr.getSMPBusinessCardOfID(aSG2.getParticipantIdentifier()));
// Cleanup
assertTrue(aBusinessCardMgr.deleteSMPBusinessCard(aBusinessCard2).isChanged());
assertEquals(nBCCount + 1, aBusinessCardMgr.getSMPBusinessCardCount());
assertTrue(aBusinessCardMgr.deleteSMPBusinessCard(aBusinessCard).isChanged());
assertEquals(nBCCount + 0, aBusinessCardMgr.getSMPBusinessCardCount());
assertTrue(aSGMgr.deleteSMPServiceGroupNoEx(aPI2, true).isChanged());
assertTrue(aSGMgr.deleteSMPServiceGroupNoEx(aPI1, true).isChanged());
} finally {
// Real cleanup
aBusinessCardMgr.deleteSMPBusinessCard(aBusinessCard2);
aSGMgr.deleteSMPServiceGroupNoEx(aPI2, true);
}
} finally {
// Real cleanup
aBusinessCardMgr.deleteSMPBusinessCard(aBusinessCard);
aSGMgr.deleteSMPServiceGroupNoEx(aPI1, true);
}
}
Aggregations