use of com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup in project phoss-smp by phax.
the class SMPRedirectManagerMongoDBTest method testRedirectUpperCaseSG.
@Test
public void testRedirectUpperCaseSG() throws SMPServerException {
// Ensure the user is present
final IUser aTestUser = PhotonSecurityManager.getUserMgr().getUserOfID(CSecurity.USER_ADMINISTRATOR_ID);
assertNotNull(aTestUser);
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
assertFalse(aIdentifierFactory.isParticipantIdentifierCaseInsensitive("bla-sch-eme"));
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
assertEquals(0, aRedirectMgr.getSMPRedirectCount());
// Delete existing service group
final IParticipantIdentifier aPI = aIdentifierFactory.createParticipantIdentifier("bla-sch-eme", "0088:UpperCase");
assertNotNull(aPI);
aServiceGroupMgr.deleteSMPServiceGroupNoEx(aPI, true);
final ISMPServiceGroup aSG = aServiceGroupMgr.createSMPServiceGroup(aTestUser.getID(), aPI, null, true);
assertNotNull(aSG);
try {
final IDocumentTypeIdentifier aDocTypeID = aIdentifierFactory.createDocumentTypeIdentifier(PeppolIdentifierHelper.DOCUMENT_TYPE_SCHEME_BUSDOX_DOCID_QNS, "DocType4711");
final ISMPRedirect aRedirect = aRedirectMgr.createOrUpdateSMPRedirect(aSG, aDocTypeID, "bla", "foo", null, "<ext/>");
assertNotNull(aRedirect);
assertSame(aSG, aRedirect.getServiceGroup());
assertEquals(aDocTypeID, aRedirect.getDocumentTypeIdentifier());
assertEquals("bla", aRedirect.getTargetHref());
assertEquals("foo", aRedirect.getSubjectUniqueIdentifier());
assertNull(aRedirect.getCertificate());
assertEquals("<ext />", aRedirect.getFirstExtensionXML().trim());
} finally {
aServiceGroupMgr.deleteSMPServiceGroup(aPI, true);
}
}
use of com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup in project phoss-smp by phax.
the class AbstractPageSecureEndpoint method getSelectedObject.
@Override
@Nullable
protected ISMPServiceInformation getSelectedObject(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final String sID) {
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
final String sServiceGroupID = aWPEC.params().getAsString(FIELD_SERVICE_GROUP_ID);
final IParticipantIdentifier aServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID);
final ISMPServiceGroup aServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aServiceGroupID);
final String sDocTypeIDScheme = aWPEC.params().getAsString(FIELD_DOCTYPE_ID_SCHEME);
final String sDocTypeIDValue = aWPEC.params().getAsString(FIELD_DOCTYPE_ID_VALUE);
final IDocumentTypeIdentifier aDocTypeID = aIdentifierFactory.createDocumentTypeIdentifier(sDocTypeIDScheme, sDocTypeIDValue);
return aServiceInfoMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aDocTypeID);
}
use of com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup in project phoss-smp by phax.
the class AbstractPageSecureEndpoint method validateAndSaveInputParameters.
@Override
protected void validateAndSaveInputParameters(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMPServiceInformation aSelectedObject, @Nonnull final FormErrorList aFormErrors, @Nonnull final EWebPageFormAction eFormAction) {
final boolean bEdit = eFormAction.isEdit();
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
final ISMPProcess aSelectedProcess = aWPEC.getRequestScope().attrs().getCastedValue(REQUEST_ATTR_PROCESS);
final ISMPEndpoint aSelectedEndpoint = aWPEC.getRequestScope().attrs().getCastedValue(REQUEST_ATTR_ENDPOINT);
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
final ISMPTransportProfileManager aTransportProfileMgr = SMPMetaManager.getTransportProfileMgr();
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final String sServiceGroupID = bEdit ? aSelectedObject.getServiceGroupID() : aWPEC.params().getAsStringTrimmed(FIELD_SERVICE_GROUP_ID);
ISMPServiceGroup aServiceGroup = null;
final String sDocTypeIDScheme = bEdit ? aSelectedObject.getDocumentTypeIdentifier().getScheme() : aWPEC.params().getAsStringTrimmed(FIELD_DOCTYPE_ID_SCHEME);
final String sDocTypeIDValue = bEdit ? aSelectedObject.getDocumentTypeIdentifier().getValue() : aWPEC.params().getAsStringTrimmed(FIELD_DOCTYPE_ID_VALUE);
IDocumentTypeIdentifier aDocTypeID = null;
final String sProcessIDScheme = bEdit ? aSelectedProcess.getProcessIdentifier().getScheme() : aWPEC.params().getAsStringTrimmed(FIELD_PROCESS_ID_SCHEME);
final String sProcessIDValue = bEdit ? aSelectedProcess.getProcessIdentifier().getValue() : aWPEC.params().getAsStringTrimmed(FIELD_PROCESS_ID_VALUE);
IProcessIdentifier aProcessID = null;
final String sTransportProfileID = bEdit ? aSelectedEndpoint.getTransportProfile() : aWPEC.params().getAsStringTrimmed(FIELD_TRANSPORT_PROFILE);
final ISMPTransportProfile aTransportProfile = aTransportProfileMgr.getSMPTransportProfileOfID(sTransportProfileID);
final String sEndpointReference = aWPEC.params().getAsStringTrimmed(FIELD_ENDPOINT_REFERENCE);
final boolean bRequireBusinessLevelSignature = aWPEC.params().getAsBoolean(FIELD_REQUIRES_BUSINESS_LEVEL_SIGNATURE);
final String sMinimumAuthenticationLevel = aWPEC.params().getAsStringTrimmed(FIELD_MINIMUM_AUTHENTICATION_LEVEL);
final String sNotBefore = aWPEC.params().getAsStringTrimmed(FIELD_NOT_BEFORE);
final LocalDate aNotBeforeDate = PDTFromString.getLocalDateFromString(sNotBefore, aDisplayLocale);
final String sNotAfter = aWPEC.params().getAsStringTrimmed(FIELD_NOT_AFTER);
final LocalDate aNotAfterDate = PDTFromString.getLocalDateFromString(sNotAfter, aDisplayLocale);
final String sCertificate = aWPEC.params().getAsStringTrimmed(FIELD_CERTIFICATE);
final String sServiceDescription = aWPEC.params().getAsStringTrimmed(FIELD_SERVICE_DESCRIPTION);
final String sTechnicalContact = aWPEC.params().getAsStringTrimmed(FIELD_TECHNICAL_CONTACT);
final String sTechnicalInformation = aWPEC.params().getAsStringTrimmed(FIELD_TECHNICAL_INFORMATION);
final String sExtension = aWPEC.params().getAsStringTrimmed(FIELD_EXTENSION);
// validations
if (StringHelper.hasNoText(sServiceGroupID))
aFormErrors.addFieldError(FIELD_SERVICE_GROUP_ID, "A service group must be selected!");
else {
aServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID));
if (aServiceGroup == null)
aFormErrors.addFieldError(FIELD_SERVICE_GROUP_ID, "The provided service group does not exist!");
}
if (aIdentifierFactory.isDocumentTypeIdentifierSchemeMandatory() && StringHelper.hasNoText(sDocTypeIDScheme))
aFormErrors.addFieldError(FIELD_DOCTYPE_ID_SCHEME, "Document type ID scheme must not be empty!");
else if (StringHelper.hasNoText(sDocTypeIDValue))
aFormErrors.addFieldError(FIELD_DOCTYPE_ID_VALUE, "Document type ID value must not be empty!");
else {
aDocTypeID = aIdentifierFactory.createDocumentTypeIdentifier(sDocTypeIDScheme, sDocTypeIDValue);
if (aDocTypeID == null)
aFormErrors.addFieldError(FIELD_DOCTYPE_ID_VALUE, "The provided document type ID has an invalid syntax!");
else {
if (aServiceGroup != null)
if (aRedirectMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDocTypeID) != null)
aFormErrors.addFieldError(FIELD_DOCTYPE_ID_VALUE, "At least one redirect is registered for this document type. Delete the redirect before you can create an endpoint.");
}
}
if (aIdentifierFactory.isProcessIdentifierSchemeMandatory() && StringHelper.hasNoText(sProcessIDScheme))
aFormErrors.addFieldError(FIELD_PROCESS_ID_SCHEME, "Process ID scheme must not be empty!");
else if (StringHelper.hasNoText(sProcessIDValue))
aFormErrors.addFieldError(FIELD_PROCESS_ID_SCHEME, "Process ID value must not be empty!");
else {
aProcessID = aIdentifierFactory.createProcessIdentifier(sProcessIDScheme, sProcessIDValue);
if (aProcessID == null)
aFormErrors.addFieldError(FIELD_PROCESS_ID_VALUE, "The provided process ID has an invalid syntax!");
}
if (StringHelper.hasNoText(sTransportProfileID))
aFormErrors.addFieldError(FIELD_TRANSPORT_PROFILE, "Transport Profile must not be empty!");
else if (aTransportProfile == null)
aFormErrors.addFieldError(FIELD_TRANSPORT_PROFILE, "Transport Profile of type '" + sTransportProfileID + "' does not exist!");
if (!bEdit && aServiceGroup != null && aDocTypeID != null && aProcessID != null && aTransportProfile != null && aServiceInfoMgr.findServiceInformation(aServiceGroup, aDocTypeID, aProcessID, aTransportProfile) != null) {
final String sMsg = "Another endpoint for the provided service group, document type, process and transport profile is already present. Some of the identifiers may be treated case insensitive!";
aFormErrors.addFieldError(FIELD_DOCTYPE_ID_VALUE, sMsg);
aFormErrors.addFieldError(FIELD_PROCESS_ID_VALUE, sMsg);
aFormErrors.addFieldError(FIELD_TRANSPORT_PROFILE, sMsg);
}
if (StringHelper.hasNoText(sEndpointReference)) {
if (false)
aFormErrors.addFieldError(FIELD_ENDPOINT_REFERENCE, "Endpoint Reference must not be empty!");
} else if (URLHelper.getAsURL(sEndpointReference) == null)
aFormErrors.addFieldError(FIELD_ENDPOINT_REFERENCE, "The Endpoint Reference is not a valid URL!");
if (aNotBeforeDate != null && aNotAfterDate != null)
if (aNotBeforeDate.isAfter(aNotAfterDate))
aFormErrors.addFieldError(FIELD_NOT_BEFORE, "Not Before Date must not be after Not After Date!");
if (StringHelper.hasNoText(sCertificate))
aFormErrors.addFieldError(FIELD_CERTIFICATE, "Certificate must not be empty!");
else {
X509Certificate aCert = null;
try {
aCert = CertificateHelper.convertStringToCertficate(sCertificate);
} catch (final CertificateException ex) {
// Fall through
}
if (aCert == null)
aFormErrors.addFieldError(FIELD_CERTIFICATE, "The provided certificate string is not a valid X509 certificate!");
}
if (StringHelper.hasNoText(sServiceDescription))
aFormErrors.addFieldError(FIELD_SERVICE_DESCRIPTION, "Service Description must not be empty!");
if (StringHelper.hasNoText(sTechnicalContact))
aFormErrors.addFieldError(FIELD_TECHNICAL_CONTACT, "Technical Contact 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()) {
ISMPServiceInformation aServiceInfo = aServiceInfoMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aDocTypeID);
if (aServiceInfo == null)
aServiceInfo = new SMPServiceInformation(aServiceGroup, aDocTypeID, null, null);
ISMPProcess aProcess = aServiceInfo.getProcessOfID(aProcessID);
if (aProcess == null) {
aProcess = new SMPProcess(aProcessID, null, null);
aServiceInfo.addProcess((SMPProcess) aProcess);
}
aProcess.setEndpoint(new SMPEndpoint(sTransportProfileID, sEndpointReference, bRequireBusinessLevelSignature, sMinimumAuthenticationLevel, PDTFactory.createXMLOffsetDateTime(aNotBeforeDate), PDTFactory.createXMLOffsetDateTime(aNotAfterDate), sCertificate, sServiceDescription, sTechnicalContact, sTechnicalInformation, sExtension));
if (aServiceInfoMgr.mergeSMPServiceInformation(aServiceInfo).isSuccess()) {
if (bEdit) {
aWPEC.postRedirectGetInternal(success("Successfully edited the endpoint for service group '" + aServiceGroup.getParticipantIdentifier().getURIEncoded() + "'."));
} else {
aWPEC.postRedirectGetInternal(success("Successfully created a new endpoint for service group '" + aServiceGroup.getParticipantIdentifier().getURIEncoded() + "'."));
}
} else {
if (bEdit) {
aWPEC.postRedirectGetInternal(error("Error editing the endpoint for service group '" + aServiceGroup.getParticipantIdentifier().getURIEncoded() + "'."));
} else {
aWPEC.postRedirectGetInternal(error("Error creating a new endpoint for service group '" + aServiceGroup.getParticipantIdentifier().getURIEncoded() + "'."));
}
}
}
}
use of com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup in project phoss-smp by phax.
the class ServiceMetadataInterfaceTest method testCreateAndDeleteRedirectSMPClient.
@Test
public void testCreateAndDeleteRedirectSMPClient() throws SMPClientException {
// Lower case
final IParticipantIdentifier aPI_LC = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9915:xxx");
// Upper case
final IParticipantIdentifier aPI_UC = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9915:XXX");
final IDocumentTypeIdentifier aDT = EPredefinedDocumentTypeIdentifier.INVOICE_EN16931_PEPPOL_V30.getAsDocumentTypeIdentifier();
final ServiceGroupType aSG = new ServiceGroupType();
aSG.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI_LC));
aSG.setServiceMetadataReferenceCollection(new ServiceMetadataReferenceCollectionType());
final RedirectType aRedir = _createRedirect();
final ISMPServiceGroupManager aSGMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPRedirectManager aSRMgr = SMPMetaManager.getRedirectMgr();
final SMPClient aSMPClient = new MockSMPClient();
assertNull(aSMPClient.getServiceGroupOrNull(aPI_LC));
assertNull(aSMPClient.getServiceGroupOrNull(aPI_UC));
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
try {
// PUT ServiceGroup
aSMPClient.saveServiceGroup(aSG, CREDENTIALS);
assertNotNull(aSMPClient.getServiceGroupOrNull(aPI_LC));
assertNotNull(aSMPClient.getServiceGroupOrNull(aPI_UC));
assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
final ISMPServiceGroup aServiceGroup = aSGMgr.getSMPServiceGroupOfID(aPI_LC);
assertNotNull(aServiceGroup);
final ISMPServiceGroup aServiceGroup_UC = aSGMgr.getSMPServiceGroupOfID(aPI_UC);
assertEquals(aServiceGroup, aServiceGroup_UC);
try {
// PUT 1 ServiceInformation
aSMPClient.saveServiceRedirect(aPI_LC, aDT, aRedir, CREDENTIALS);
assertNotNull(aSRMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDT));
// PUT 2 ServiceInformation
aSMPClient.saveServiceRedirect(aPI_LC, aDT, aRedir, CREDENTIALS);
assertNotNull(aSRMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDT));
// DELETE 1 Redirect
aSMPClient.deleteServiceRegistration(aPI_LC, aDT, CREDENTIALS);
assertNull(aSRMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDT));
} finally {
// DELETE 2 Redirect
try {
aSMPClient.deleteServiceRegistration(aPI_LC, aDT, CREDENTIALS);
} catch (final SMPClientNotFoundException ex) {
// Expected
}
assertNull(aSRMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDT));
}
assertNotNull(aSGMgr.getSMPServiceGroupOfID(aPI_LC));
} finally {
// DELETE ServiceGroup
try {
aSMPClient.deleteServiceGroup(aPI_LC, CREDENTIALS);
} catch (final SMPClientNotFoundException ex) {
// Expected
}
assertNull(aSMPClient.getServiceGroupOrNull(aPI_LC));
assertNull(aSMPClient.getServiceGroupOrNull(aPI_UC));
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
}
}
use of com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup in project phoss-smp by phax.
the class ServiceMetadataInterfaceTest method testCreateAndDeleteServiceInformationSMPClient.
@Test
public void testCreateAndDeleteServiceInformationSMPClient() throws SMPClientException {
// Lower case
final IParticipantIdentifier aPI_LC = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9915:xxx");
// Upper case
final IParticipantIdentifier aPI_UC = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9915:XXX");
final PeppolDocumentTypeIdentifier aDT = EPredefinedDocumentTypeIdentifier.INVOICE_EN16931_PEPPOL_V30.getAsDocumentTypeIdentifier();
final PeppolProcessIdentifier aProcID = EPredefinedProcessIdentifier.BIS3_BILLING.getAsProcessIdentifier();
final ServiceGroupType aSG = new ServiceGroupType();
aSG.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI_LC));
aSG.setServiceMetadataReferenceCollection(new ServiceMetadataReferenceCollectionType());
final ServiceInformationType aSI = new ServiceInformationType();
aSI.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI_LC));
aSI.setDocumentIdentifier(aDT);
{
final ProcessListType aPL = new ProcessListType();
final ProcessType aProcess = new ProcessType();
aProcess.setProcessIdentifier(aProcID);
final ServiceEndpointList aSEL = new ServiceEndpointList();
final EndpointType aEndpoint = new EndpointType();
aEndpoint.setEndpointReference(W3CEndpointReferenceHelper.createEndpointReference("http://test.smpserver/as2"));
aEndpoint.setRequireBusinessLevelSignature(false);
aEndpoint.setCertificate("blacert");
aEndpoint.setServiceDescription("Unit test service");
aEndpoint.setTechnicalContactUrl("https://github.com/phax/phoss-smp");
aEndpoint.setTransportProfile(ESMPTransportProfile.TRANSPORT_PROFILE_AS2.getID());
aSEL.addEndpoint(aEndpoint);
aProcess.setServiceEndpointList(aSEL);
aPL.addProcess(aProcess);
aSI.setProcessList(aPL);
}
final ISMPServiceGroupManager aSGMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPServiceInformationManager aSIMgr = SMPMetaManager.getServiceInformationMgr();
final SMPClient aSMPClient = new MockSMPClient();
assertNull(aSMPClient.getServiceGroupOrNull(aPI_LC));
assertNull(aSMPClient.getServiceGroupOrNull(aPI_UC));
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
try {
// PUT ServiceGroup
aSMPClient.saveServiceGroup(aSG, CREDENTIALS);
// Read both
assertNotNull(aSMPClient.getServiceGroupOrNull(aPI_LC));
assertNotNull(aSMPClient.getServiceGroupOrNull(aPI_UC));
assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
final ISMPServiceGroup aServiceGroup = aSGMgr.getSMPServiceGroupOfID(aPI_LC);
assertNotNull(aServiceGroup);
final ISMPServiceGroup aServiceGroup_UC = aSGMgr.getSMPServiceGroupOfID(aPI_UC);
assertEquals(aServiceGroup, aServiceGroup_UC);
try {
// PUT 1 ServiceInformation
aSMPClient.saveServiceInformation(aSI, CREDENTIALS);
assertNotNull(aSIMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aDT));
// PUT 2 ServiceInformation
aSMPClient.saveServiceInformation(aSI, CREDENTIALS);
assertNotNull(aSIMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aDT));
// DELETE 1 ServiceInformation
aSMPClient.deleteServiceRegistration(aPI_LC, aDT, CREDENTIALS);
assertNull(aSIMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aDT));
} finally {
// DELETE 2 ServiceInformation
try {
aSMPClient.deleteServiceRegistration(aPI_LC, aDT, CREDENTIALS);
} catch (final SMPClientNotFoundException ex) {
// Expected
}
assertNull(aSIMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aDT));
}
assertNotNull(aSMPClient.getServiceGroup(aPI_LC));
} finally {
// DELETE ServiceGroup
try {
aSMPClient.deleteServiceGroup(aPI_LC, CREDENTIALS);
} catch (final SMPClientNotFoundException ex) {
// Expected
}
assertNull(aSMPClient.getServiceGroupOrNull(aPI_LC));
assertNull(aSMPClient.getServiceGroupOrNull(aPI_UC));
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
}
}
Aggregations