use of com.helger.peppol.smp.ESMPTransportProfile in project phoss-smp by phax.
the class ServiceMetadataInterfaceFillDBTest method testCreateAndDeleteServiceInformationSMPClient.
@Test
public void testCreateAndDeleteServiceInformationSMPClient() throws SMPClientException {
final SMPClient aSMPClient = new MockSMPClient();
final StopWatch aSW = StopWatch.createdStarted();
int nEndpoints = 0;
try (final WebScoped aWS = new WebScoped(new MockHttpServletRequest())) {
final int nCount = 2_000;
for (int i = 0; i < nCount; ++i) {
final IParticipantIdentifier aPI_LC = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme(PID_PREFIX_9999_PHOSS + StringHelper.getLeadingZero(i, 4));
final PeppolDocumentTypeIdentifier aDT = EPredefinedDocumentTypeIdentifier.INVOICE_EN16931_PEPPOL_V30.getAsDocumentTypeIdentifier();
final PeppolProcessIdentifier aProcID = EPredefinedProcessIdentifier.BIS3_BILLING.getAsProcessIdentifier();
for (final ESMPTransportProfile eTP : new ESMPTransportProfile[] { ESMPTransportProfile.TRANSPORT_PROFILE_AS2, ESMPTransportProfile.TRANSPORT_PROFILE_PEPPOL_AS4_V2 }) {
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/" + eTP.getID()));
aEndpoint.setRequireBusinessLevelSignature(false);
aEndpoint.setCertificate("blacert");
aEndpoint.setServiceDescription("Unit test service");
aEndpoint.setTechnicalContactUrl("https://github.com/phax/phoss-smp");
aEndpoint.setTransportProfile(eTP.getID());
aSEL.addEndpoint(aEndpoint);
aProcess.setServiceEndpointList(aSEL);
aPL.addProcess(aProcess);
aSI.setProcessList(aPL);
}
aSMPClient.saveServiceInformation(aSI, CREDENTIALS);
++nEndpoints;
}
}
}
aSW.stop();
LOGGER.info("Created " + nEndpoints + " ServiceInformation in " + aSW.getDuration() + " (= " + (aSW.getMillis() / nEndpoints) + " ms/entry)");
}
use of com.helger.peppol.smp.ESMPTransportProfile in project phoss-smp by phax.
the class SMPTransportProfileManagerMongoDBTest method testBasic.
@Test
public void testBasic() {
try (final SMPTransportProfileManagerMongoDB aMgr = new SMPTransportProfileManagerMongoDB()) {
assertEquals(0, aMgr.getAllSMPTransportProfiles().size());
final ICommonsList<ISMPTransportProfile> aCreated = aMgr.getAllSMPTransportProfiles();
for (final ESMPTransportProfile e : ESMPTransportProfile.values()) {
final ISMPTransportProfile aCreate = aMgr.createSMPTransportProfile(e.getID(), e.getName(), e.isDeprecated());
aCreated.add(aCreate);
}
final ICommonsList<ISMPTransportProfile> aAll = aMgr.getAllSMPTransportProfiles();
assertEquals(ESMPTransportProfile.values().length, aAll.size());
for (final ISMPTransportProfile aCreate : aCreated) assertTrue(aAll.contains(aCreate));
for (final ISMPTransportProfile aCreate : aCreated) assertTrue(aMgr.updateSMPTransportProfile(aCreate.getID(), "bla " + aCreate.getName(), aCreate.isDeprecated()).isChanged());
for (final ISMPTransportProfile aCreate : aCreated) {
final ISMPTransportProfile aInfo = aMgr.getSMPTransportProfileOfID(aCreate.getID());
assertNotNull(aInfo);
assertTrue(aInfo.getName().startsWith("bla "));
}
for (final ISMPTransportProfile aCreate : aCreated) assertTrue(aMgr.deleteSMPTransportProfile(aCreate.getID()).isChanged());
assertEquals(0, aMgr.getAllSMPTransportProfiles().size());
}
}
use of com.helger.peppol.smp.ESMPTransportProfile in project phoss-smp by phax.
the class PageSecureTasksProblems method fillContent.
@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
final HCNodeList aNodeList = aWPEC.getNodeList();
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
final OffsetDateTime aNowDT = PDTFactory.getCurrentOffsetDateTime();
final OffsetDateTime aNowPlusDT = aNowDT.plusMonths(3);
aNodeList.addChild(info("This page tries to identify upcoming tasks and potential problems in the SMP configuration. It is meant to highlight immediate and upcoming action items as well as potential misconfiguration."));
final HCOL aOL = new HCOL();
// Check for default password
if (PhotonSecurityManager.getUserMgr().areUserIDAndPasswordValid(CSecurity.USER_ADMINISTRATOR_ID, CSecurity.USER_ADMINISTRATOR_PASSWORD)) {
aOL.addItem(_createError("Please change the password of the default user " + CSecurity.USER_ADMINISTRATOR_EMAIL + "!"), div("This is a severe security risk"));
}
_checkSettings(aOL);
// check keystore configuration
_checkKeyStore(aWPEC, aOL, aNowDT, aNowPlusDT);
// Check truststore configuration
_checkTrustStore(aWPEC, aOL, aNowDT, aNowPlusDT);
// Check SML configuration
_checkSMLConfiguration(aOL);
// Check Directory configuration
_checkDirectoryConfig(aWPEC, aOL, aNowDT, aNowPlusDT);
// check service groups and redirects
{
final ICommonsList<ISMPServiceGroup> aServiceGroups = aServiceGroupMgr.getAllSMPServiceGroups();
if (aServiceGroups.isEmpty()) {
aOL.addItem(_createWarning("No service group is configured. This SMP is currently empty."));
} else {
// For all service groups
for (final ISMPServiceGroup aServiceGroup : CollectionHelper.getSorted(aServiceGroups, ISMPServiceGroup.comparator())) {
final HCUL aULPerSG = new HCUL();
final ICommonsList<ISMPServiceInformation> aServiceInfos = aServiceInfoMgr.getAllSMPServiceInformationOfServiceGroup(aServiceGroup);
if (aServiceInfos.isEmpty()) {
// This is merely a warning or an error
aULPerSG.addItem(_createInfo("No endpoint is configured for this service group."));
} else {
for (final ISMPServiceInformation aServiceInfo : aServiceInfos) {
final HCUL aULPerDocType = new HCUL();
final ICommonsList<ISMPProcess> aProcesses = aServiceInfo.getAllProcesses();
for (final ISMPProcess aProcess : aProcesses) {
final HCUL aULPerProcess = new HCUL();
final ICommonsList<ISMPEndpoint> aEndpoints = aProcess.getAllEndpoints();
for (final ISMPEndpoint aEndpoint : aEndpoints) {
final HCUL aULPerEndpoint = new HCUL();
final ESMPTransportProfile eTransportProfile = ESMPTransportProfile.getFromIDOrNull(aEndpoint.getTransportProfile());
if (eTransportProfile == null)
aULPerEndpoint.addItem(_createWarning("The endpoint uses the non-standard transport profile '" + aEndpoint.getTransportProfile() + "'."));
if (aEndpoint.getServiceActivationDateTime() != null) {
if (aEndpoint.getServiceActivationDateTime().isAfter(XMLOffsetDateTime.of(aNowDT)))
aULPerEndpoint.addItem(_createWarning("The endpoint is not yet active."), div("It will be active from " + PDTToString.getAsString(aEndpoint.getServiceActivationDateTime(), aDisplayLocale) + "."));
}
if (aEndpoint.getServiceExpirationDateTime() != null) {
if (aEndpoint.getServiceExpirationDateTime().isBefore(XMLOffsetDateTime.of(aNowDT)))
aULPerEndpoint.addItem(_createError("The endpoint is no longer active."), div("It was valid until " + PDTToString.getAsString(aEndpoint.getServiceExpirationDateTime(), aDisplayLocale) + "."));
else if (aEndpoint.getServiceExpirationDateTime().isBefore(XMLOffsetDateTime.of(aNowPlusDT)))
aULPerEndpoint.addItem(_createWarning("The endpoint will be inactive soon."), div("It is only valid until " + PDTToString.getAsString(aEndpoint.getServiceExpirationDateTime(), aDisplayLocale) + "."));
}
X509Certificate aX509Cert = null;
try {
aX509Cert = CertificateHelper.convertStringToCertficate(aEndpoint.getCertificate());
} catch (final CertificateException ex) {
// Ignore
}
if (aX509Cert == null)
aULPerEndpoint.addItem(_createError("The X.509 certificate configured at the endpoint is invalid and could not be interpreted as a certificate."));
else {
final OffsetDateTime aNotBefore = PDTFactory.createOffsetDateTime(aX509Cert.getNotBefore());
if (aNowDT.isBefore(aNotBefore))
aULPerEndpoint.addItem(_createError("The endpoint certificate is not yet active."), div("It will be valid from " + PDTToString.getAsString(aNotBefore, aDisplayLocale) + "."));
final OffsetDateTime aNotAfter = PDTFactory.createOffsetDateTime(aX509Cert.getNotAfter());
if (aNowDT.isAfter(aNotAfter))
aULPerEndpoint.addItem(_createError("The endpoint certificate is already expired."), div("It was valid until " + PDTToString.getAsString(aNotAfter, aDisplayLocale) + "."));
else if (aNowPlusDT.isAfter(aNotAfter))
aULPerEndpoint.addItem(_createWarning("The endpoint certificate will expire soon."), div("It is only valid until " + PDTToString.getAsString(aNotAfter, aDisplayLocale) + "."));
}
// Show per endpoint errors
if (aULPerEndpoint.hasChildren())
aULPerProcess.addItem(div("Transport profile ").addChild(code(aEndpoint.getTransportProfile())), aULPerEndpoint);
}
// Show per process errors
if (aULPerProcess.hasChildren())
aULPerDocType.addItem(div("Process ").addChild(code(aProcess.getProcessIdentifier().getURIEncoded()).addClass(CUICoreCSS.CSS_CLASS_NOWRAP)), aULPerProcess);
}
// Show per document type errors
if (aULPerDocType.hasChildren())
aULPerSG.addItem(div("Document type ").addChild(code(aServiceInfo.getDocumentTypeIdentifier().getURIEncoded()).addClass(CUICoreCSS.CSS_CLASS_NOWRAP)), aULPerDocType);
}
}
// Show per service group errors
if (aULPerSG.hasChildren())
aOL.addItem(div("Service group ").addChild(code(aServiceGroup.getParticipantIdentifier().getURIEncoded())), aULPerSG);
}
}
}
// Show results
if (aOL.hasChildren()) {
aNodeList.addChild(warn("The following list of tasks and problems were identified:"));
aNodeList.addChild(aOL);
} else
aNodeList.addChild(success("Great job, no tasks or problems identified!"));
}
Aggregations