use of com.helger.phoss.smp.domain.transportprofile.ISMPTransportProfileManager in project phoss-smp by phax.
the class AbstractPageSecureEndpoint method isValidToDisplayPage.
@Override
@Nonnull
protected IValidityIndicator isValidToDisplayPage(@Nonnull final WebPageExecutionContext aWPEC) {
final HCNodeList aNodeList = aWPEC.getNodeList();
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
if (aServiceGroupMgr.getSMPServiceGroupCount() <= 0) {
aNodeList.addChild(warn("No service group is present! At least one service group must be present to create an endpoint for it."));
aNodeList.addChild(new BootstrapButton().addChild("Create new service group").setOnClick(createCreateURL(aWPEC, CMenuSecure.MENU_SERVICE_GROUPS)).setIcon(EDefaultIcon.YES));
return EValidity.INVALID;
}
final ISMPTransportProfileManager aTransportProfileMgr = SMPMetaManager.getTransportProfileMgr();
if (aTransportProfileMgr.getSMPTransportProfileCount() <= 0) {
aNodeList.addChild(warn("No transport profile is present! At least one transport profile must be present to create an endpoint for it."));
aNodeList.addChild(new BootstrapButton().addChild("Create new transport profile").setOnClick(createCreateURL(aWPEC, CMenuSecure.MENU_TRANSPORT_PROFILES)).setIcon(EDefaultIcon.YES));
aNodeList.addChild(new BootstrapButton().addChild("Check default transport profiles").setOnClick(aWPEC.getLinkToMenuItem(CMenuSecure.MENU_TRANSPORT_PROFILES)).setIcon(EDefaultIcon.YES));
return EValidity.INVALID;
}
return super.isValidToDisplayPage(aWPEC);
}
use of com.helger.phoss.smp.domain.transportprofile.ISMPTransportProfileManager 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.transportprofile.ISMPTransportProfileManager in project phoss-smp by phax.
the class PageSecureTransportProfiles method validateAndSaveInputParameters.
@Override
protected void validateAndSaveInputParameters(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMPTransportProfile aSelectedObject, @Nonnull final FormErrorList aFormErrors, @Nonnull final EWebPageFormAction eFormAction) {
final boolean bEdit = eFormAction.isEdit();
final ISMPTransportProfileManager aTransportProfileMgr = SMPMetaManager.getTransportProfileMgr();
// Never edit ID
final String sID = bEdit ? aSelectedObject.getID() : aWPEC.params().getAsString(FIELD_ID);
final String sName = aWPEC.params().getAsString(FIELD_NAME);
final boolean bIsDeprecated = aWPEC.params().getAsBoolean(FIELD_DEPRECATED, DEFAULT_DEPRECATED);
// validations
if (StringHelper.hasNoText(sID))
aFormErrors.addFieldError(FIELD_ID, "Transport profile ID must not be empty!");
else if (!bEdit) {
final ISMPTransportProfile aOther = aTransportProfileMgr.getSMPTransportProfileOfID(sID);
if (aOther != null)
aFormErrors.addFieldError(FIELD_ID, "Another transport profile with the same name already exists!");
}
if (StringHelper.hasNoText(sName))
aFormErrors.addFieldError(FIELD_NAME, "The transport profile name must not be empty!");
if (aFormErrors.isEmpty()) {
if (bEdit) {
if (aTransportProfileMgr.updateSMPTransportProfile(sID, sName, bIsDeprecated).isChanged())
aWPEC.postRedirectGetInternal(success("The transport profile '" + sID + "' was successfully edited."));
else
aWPEC.postRedirectGetInternal(error("Failed to edit transport profile '" + sID + "'."));
} else {
if (aTransportProfileMgr.createSMPTransportProfile(sID, sName, bIsDeprecated) != null)
aWPEC.postRedirectGetInternal(success("The new transport profile '" + sID + "' was successfully created."));
else
aWPEC.postRedirectGetInternal(error("Failed to create transport profile '" + sID + "'."));
}
}
}
use of com.helger.phoss.smp.domain.transportprofile.ISMPTransportProfileManager in project phoss-smp by phax.
the class NiceNameUI method getTransportProfile.
@Nonnull
public static IHCNode getTransportProfile(@Nullable final String sTransportProfile, final boolean bInDetails) {
final ISMPTransportProfileManager aTransportProfileMgr = SMPMetaManager.getTransportProfileMgr();
final ISMPTransportProfile aTP = aTransportProfileMgr.getSMPTransportProfileOfID(sTransportProfile);
if (aTP == null)
return createFormattedID(sTransportProfile, null, null, false, bInDetails);
return createFormattedID(sTransportProfile, aTP.getName(), EBootstrapBadgeType.SUCCESS, aTP.isDeprecated(), bInDetails);
}
use of com.helger.phoss.smp.domain.transportprofile.ISMPTransportProfileManager in project phoss-smp by phax.
the class PageSecureTransportProfiles method showListOfExistingObjects.
@Override
protected void showListOfExistingObjects(@Nonnull final WebPageExecutionContext aWPEC) {
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
final HCNodeList aNodeList = aWPEC.getNodeList();
final ISMPTransportProfileManager aTransportProfileMgr = SMPMetaManager.getTransportProfileMgr();
aNodeList.addChild(info("This page lets you create custom transport profiles that can be used in service information endpoints."));
final ICommonsList<ISMPTransportProfile> aList = aTransportProfileMgr.getAllSMPTransportProfiles();
final BootstrapButtonToolbar aToolbar = new BootstrapButtonToolbar(aWPEC);
aToolbar.addChild(new BootstrapButton().addChild("Create new transport profile").setOnClick(createCreateURL(aWPEC)).setIcon(EDefaultIcon.NEW));
final ICommonsSet<String> aExistingIDs = new CommonsHashSet<>(aList, ISMPTransportProfile::getID);
if (!aExistingIDs.containsAll(DEFAULT_PROFILE_IDS)) {
// Show button only on demand
aToolbar.addChild(new BootstrapButton().addChild("Ensure all default transport profiles").setOnClick(aWPEC.getSelfHref().add(CPageParam.PARAM_ACTION, ACTION_ENSURE_DEFAULT)).setIcon(EDefaultIcon.PLUS));
}
aNodeList.addChild(aToolbar);
final HCTable aTable = new HCTable(new DTCol("ID").setInitialSorting(ESortOrder.ASCENDING), new DTCol("Name"), new DTCol("Deprecated?"), new BootstrapDTColAction(aDisplayLocale)).setID(getID());
for (final ISMPTransportProfile aCurObject : aList) {
final ISimpleURL aViewLink = createViewURL(aWPEC, aCurObject);
final HCRow aRow = aTable.addBodyRow();
aRow.addCell(new HCA(aViewLink).addChild(aCurObject.getID()));
aRow.addCell(aCurObject.getName());
aRow.addCell(EPhotonCoreText.getYesOrNo(aCurObject.isDeprecated(), aDisplayLocale));
aRow.addCell(createEditLink(aWPEC, aCurObject, "Edit " + aCurObject.getID()), new HCTextNode(" "), createCopyLink(aWPEC, aCurObject, "Copy " + aCurObject.getID()), new HCTextNode(" "), isActionAllowed(aWPEC, EWebPageFormAction.DELETE, aCurObject) ? createDeleteLink(aWPEC, aCurObject, "Delete " + aCurObject.getID()) : createEmptyAction());
}
final DataTables aDataTables = BootstrapDataTables.createDefaultDataTables(aWPEC, aTable);
aNodeList.addChild(aTable).addChild(aDataTables);
}
Aggregations