use of com.helger.peppolid.factory.IIdentifierFactory in project phoss-smp by phax.
the class BDXR1ServerAPI method deleteServiceGroup.
@Nonnull
public EChange deleteServiceGroup(@Nonnull final String sPathServiceGroupID, final boolean bDeleteInSML, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPServerException {
final String sLog = LOG_PREFIX + "DELETE /" + sPathServiceGroupID + (bDeleteInSML ? "" : CSMPServer.LOG_SUFFIX_NO_SML_INTERACTION);
final String sAction = "deleteServiceGroup";
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog);
STATS_COUNTER_INVOCATION.increment(sAction);
try {
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final IParticipantIdentifier aPathServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sPathServiceGroupID);
if (aPathServiceGroupID == null) {
// Invalid identifier
throw SMPBadRequestException.failedToParseSG(sPathServiceGroupID, m_aAPIDataProvider.getCurrentURI());
}
final IUser aSMPUser = SMPUserManagerPhoton.validateUserCredentials(aCredentials);
SMPUserManagerPhoton.verifyOwnership(aPathServiceGroupID, aSMPUser);
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final EChange eDeleted = aServiceGroupMgr.deleteSMPServiceGroup(aPathServiceGroupID, bDeleteInSML);
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog + " SUCCESS");
STATS_COUNTER_SUCCESS.increment(sAction);
return eDeleted;
} catch (final SMPServerException ex) {
if (LOGGER.isWarnEnabled())
LOGGER.warn(sLog + " ERROR - " + ex.getMessage());
STATS_COUNTER_ERROR.increment(sAction);
throw ex;
}
}
use of com.helger.peppolid.factory.IIdentifierFactory in project phoss-smp by phax.
the class BusinessCardServerAPI method createBusinessCard.
@Nonnull
public ESuccess createBusinessCard(@Nonnull final String sServiceGroupID, @Nonnull final PDBusinessCard aBusinessCard, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPServerException {
final String sLog = LOG_PREFIX + "PUT /businesscard/" + sServiceGroupID;
final String sAction = "createBusinessCard";
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog + " ==> " + aBusinessCard);
STATS_COUNTER_INVOCATION.increment(sAction);
try {
// Parse and validate identifier
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final IParticipantIdentifier aServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID);
if (aServiceGroupID == null) {
// Invalid identifier
throw SMPBadRequestException.failedToParseSG(sServiceGroupID, m_aAPIProvider.getCurrentURI());
}
final IParticipantIdentifier aPayloadServiceGroupID = aIdentifierFactory.createParticipantIdentifier(aBusinessCard.getParticipantIdentifier().getScheme(), aBusinessCard.getParticipantIdentifier().getValue());
if (!aServiceGroupID.hasSameContent(aPayloadServiceGroupID)) {
// Business identifiers must be equal
throw new SMPBadRequestException("Participant Inconsistency. The URL points to '" + aServiceGroupID.getURIEncoded() + "' whereas the BusinessCard contains '" + aPayloadServiceGroupID.getURIEncoded() + "'", m_aAPIProvider.getCurrentURI());
}
// Retrieve the service group
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPServiceGroup aServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aServiceGroupID);
if (aServiceGroup == null) {
// No such service group (on this server)
throw new SMPNotFoundException("Unknown serviceGroup '" + sServiceGroupID + "'", m_aAPIProvider.getCurrentURI());
}
// Check credentials and verify service group is owned by provided user
final IUser aSMPUser = SMPUserManagerPhoton.validateUserCredentials(aCredentials);
SMPUserManagerPhoton.verifyOwnership(aServiceGroupID, aSMPUser);
final ISMPBusinessCardManager aBusinessCardMgr = SMPMetaManager.getBusinessCardMgr();
if (aBusinessCardMgr == null) {
throw new SMPBadRequestException("This SMP server does not support the BusinessCard API", m_aAPIProvider.getCurrentURI());
}
final ICommonsList<SMPBusinessCardEntity> aEntities = new CommonsArrayList<>();
for (final PDBusinessEntity aEntity : aBusinessCard.businessEntities()) aEntities.add(SMPBusinessCardEntity.createFromGenericObject(aEntity));
if (aBusinessCardMgr.createOrUpdateSMPBusinessCard(aServiceGroup.getParticipantIdentifier(), aEntities) == null) {
if (LOGGER.isWarnEnabled())
LOGGER.warn(sLog + " ERROR");
STATS_COUNTER_ERROR.increment(sAction);
return ESuccess.FAILURE;
}
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog + " SUCCESS");
STATS_COUNTER_SUCCESS.increment(sAction);
return ESuccess.SUCCESS;
} catch (final SMPServerException ex) {
if (LOGGER.isWarnEnabled())
LOGGER.warn(sLog + " ERROR - " + ex.getMessage());
STATS_COUNTER_ERROR.increment(sAction);
throw ex;
}
}
use of com.helger.peppolid.factory.IIdentifierFactory in project phoss-smp by phax.
the class SMPServerAPI method getServiceRegistration.
@Nonnull
public SignedServiceMetadataType getServiceRegistration(@Nonnull final String sPathServiceGroupID, @Nonnull final String sPathDocTypeID) throws SMPServerException {
final String sLog = LOG_PREFIX + "GET /" + sPathServiceGroupID + "/services/" + sPathDocTypeID;
final String sAction = "getServiceRegistration";
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog);
STATS_COUNTER_INVOCATION.increment(sAction);
try {
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final IParticipantIdentifier aPathServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sPathServiceGroupID);
if (aPathServiceGroupID == null) {
// Invalid identifier
throw SMPBadRequestException.failedToParseSG(sPathServiceGroupID, m_aAPIDataProvider.getCurrentURI());
}
final ISMPServiceGroup aPathServiceGroup = SMPMetaManager.getServiceGroupMgr().getSMPServiceGroupOfID(aPathServiceGroupID);
if (aPathServiceGroup == null) {
throw new SMPNotFoundException("No such Service Group '" + sPathServiceGroupID + "'", m_aAPIDataProvider.getCurrentURI());
}
final IDocumentTypeIdentifier aPathDocTypeID = aIdentifierFactory.parseDocumentTypeIdentifier(sPathDocTypeID);
if (aPathDocTypeID == null) {
throw SMPBadRequestException.failedToParseDocType(sPathDocTypeID, m_aAPIDataProvider.getCurrentURI());
}
// First check for redirection, then for actual service
final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
final ISMPRedirect aRedirect = aRedirectMgr.getSMPRedirectOfServiceGroupAndDocumentType(aPathServiceGroup, aPathDocTypeID);
final SignedServiceMetadataType aSignedServiceMetadata = new SignedServiceMetadataType();
if (aRedirect != null) {
aSignedServiceMetadata.setServiceMetadata(aRedirect.getAsJAXBObjectPeppol());
} else {
// Get as regular service information
final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
final ISMPServiceInformation aServiceInfo = aServiceInfoMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aPathServiceGroup, aPathDocTypeID);
final ServiceMetadataType aSM = aServiceInfo == null ? null : aServiceInfo.getAsJAXBObjectPeppol();
if (aSM != null) {
aSignedServiceMetadata.setServiceMetadata(aSM);
} else {
// Neither nor is present, or no endpoint is available
throw new SMPNotFoundException("service(" + sPathServiceGroupID + "," + sPathDocTypeID + ")", m_aAPIDataProvider.getCurrentURI());
}
}
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog + " SUCCESS");
STATS_COUNTER_SUCCESS.increment(sAction);
return aSignedServiceMetadata;
} catch (final SMPServerException ex) {
if (LOGGER.isWarnEnabled())
LOGGER.warn(sLog + " ERROR - " + ex.getMessage());
STATS_COUNTER_ERROR.increment(sAction);
throw ex;
}
}
use of com.helger.peppolid.factory.IIdentifierFactory in project peppol-practical by phax.
the class PagePublicToolsParticipantInformation method fillContent.
@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
final HCNodeList aNodeList = aWPEC.getNodeList();
final ISMLConfigurationManager aSMLConfigurationMgr = PPMetaManager.getSMLConfigurationMgr();
final FormErrorList aFormErrors = new FormErrorList();
final boolean bShowInput = true;
String sParticipantIDScheme = DEFAULT_ID_SCHEME;
String sParticipantIDValue = null;
if (aWPEC.hasAction(CPageParam.ACTION_PERFORM)) {
// Validate fields
sParticipantIDScheme = StringHelper.trim(aWPEC.params().getAsString(FIELD_ID_SCHEME));
sParticipantIDValue = StringHelper.trim(aWPEC.params().getAsString(FIELD_ID_VALUE));
final String sSMLID = StringHelper.trim(aWPEC.params().getAsString(FIELD_SML));
final ISMLConfiguration aSMLConfiguration = aSMLConfigurationMgr.getSMLInfoOfID(sSMLID);
final boolean bSMLAutoDetect = ISMLConfigurationManager.ID_AUTO_DETECT.equals(sSMLID);
final boolean bQueryBusinessCard = aWPEC.params().isCheckBoxChecked(PARAM_QUERY_BUSINESS_CARD, DEFAULT_QUERY_BUSINESS_CARD);
final boolean bShowTime = aWPEC.params().isCheckBoxChecked(PARAM_SHOW_TIME, DEFAULT_SHOW_TIME);
final boolean bXSDValidation = aWPEC.params().isCheckBoxChecked(PARAM_XSD_VALIDATION, DEFAULT_XSD_VALIDATION);
final boolean bVerifySignatures = aWPEC.params().isCheckBoxChecked(PARAM_VERIFY_SIGNATURES, DEFAULT_VERIFY_SIGNATURES);
final IIdentifierFactory aIF = aSMLConfiguration != null ? aSMLConfiguration.getSMPIdentifierType().getIdentifierFactory() : SimpleIdentifierFactory.INSTANCE;
// Legacy URL params?
if (aWPEC.params().containsKey("idscheme") && aWPEC.params().containsKey("idvalue")) {
sParticipantIDScheme = DEFAULT_ID_SCHEME;
sParticipantIDValue = StringHelper.trim(aWPEC.params().getAsString("idscheme")) + ":" + StringHelper.trim(aWPEC.params().getAsString("idvalue"));
}
if (StringHelper.hasNoText(sParticipantIDScheme))
aFormErrors.addFieldError(FIELD_ID_SCHEME, "Please provide an identifier scheme");
else if (!aIF.isParticipantIdentifierSchemeValid(sParticipantIDScheme))
aFormErrors.addFieldError(FIELD_ID_SCHEME, "The participant identifier scheme '" + sParticipantIDScheme + "' is not valid!");
if (StringHelper.hasNoText(sParticipantIDValue))
aFormErrors.addFieldError(FIELD_ID_VALUE, "Please provide an identifier value");
else if (!aIF.isParticipantIdentifierValueValid(sParticipantIDValue))
aFormErrors.addFieldError(FIELD_ID_VALUE, "The participant identifier value '" + sParticipantIDValue + "' is not valid!");
if (aSMLConfiguration == null && !bSMLAutoDetect)
aFormErrors.addFieldError(FIELD_SML, "A valid SML must be selected!");
if (aFormErrors.isEmpty()) {
_queryParticipant(aWPEC, sParticipantIDScheme, sParticipantIDValue, aSMLConfiguration, bSMLAutoDetect, bQueryBusinessCard, bShowTime, bXSDValidation, bVerifySignatures);
}
}
if (bShowInput) {
final BootstrapForm aForm = aNodeList.addAndReturnChild(getUIHandler().createFormSelf(aWPEC).setMethod(EHCFormMethod.GET).setLeft(3));
aForm.addChild(info().addChildren(div("Show all processes, document types and endpoints of a participant."), div("You may want to try scheme ").addChild(code(DEFAULT_ID_SCHEME)).addChild(" and value ").addChild(code("9915:test")).addChild(" on ").addChild(code("SMK")).addChild(" as an example.")));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Identifier scheme").setCtrl(new HCEdit(new RequestField(FIELD_ID_SCHEME, sParticipantIDScheme)).setPlaceholder("Identifier scheme")).setHelpText(div("The most common identifier scheme is ").addChild(code(DEFAULT_ID_SCHEME))).setErrorList(aFormErrors.getListOfField(FIELD_ID_SCHEME)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Identifier value").setCtrl(new HCEdit(new RequestField(FIELD_ID_VALUE, sParticipantIDValue)).setPlaceholder("Identifier value")).setHelpText(div("The identifier value must look like ").addChild(code("9915:test"))).setErrorList(aFormErrors.getListOfField(FIELD_ID_VALUE)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("SML to use").setCtrl(new SMLConfigurationSelect(new RequestField(FIELD_SML, ISMLConfigurationManager.ID_AUTO_DETECT), true)).setErrorList(aFormErrors.getListOfField(FIELD_SML)));
aForm.addFormGroup(new BootstrapFormGroup().setLabel("Query Business Card?").setCtrl(new HCCheckBox(new RequestFieldBoolean(PARAM_QUERY_BUSINESS_CARD, DEFAULT_QUERY_BUSINESS_CARD))).setErrorList(aFormErrors.getListOfField(PARAM_QUERY_BUSINESS_CARD)));
aForm.addFormGroup(new BootstrapFormGroup().setLabel("Show query duration?").setCtrl(new HCCheckBox(new RequestFieldBoolean(PARAM_SHOW_TIME, DEFAULT_SHOW_TIME))).setErrorList(aFormErrors.getListOfField(PARAM_SHOW_TIME)));
aForm.addFormGroup(new BootstrapFormGroup().setLabel("Enable XML Schema validation of responses?").setCtrl(new HCCheckBox(new RequestFieldBoolean(PARAM_XSD_VALIDATION, DEFAULT_XSD_VALIDATION))).setErrorList(aFormErrors.getListOfField(PARAM_XSD_VALIDATION)));
aForm.addFormGroup(new BootstrapFormGroup().setLabel("Verify signatures of SMP responses?").setCtrl(new HCCheckBox(new RequestFieldBoolean(PARAM_VERIFY_SIGNATURES, DEFAULT_VERIFY_SIGNATURES))).setErrorList(aFormErrors.getListOfField(PARAM_VERIFY_SIGNATURES)));
final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(new BootstrapButtonToolbar(aWPEC));
aToolbar.addHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM);
aToolbar.addSubmitButton("Show details");
}
}
use of com.helger.peppolid.factory.IIdentifierFactory in project phoss-directory by phax.
the class PageSecureDeleteManually method fillContent.
@Override
protected void fillContent(final WebPageExecutionContext aWPEC) {
final HCNodeList aNodeList = aWPEC.getNodeList();
final IIdentifierFactory aIdentifierFactory = PDMetaManager.getIdentifierFactory();
final FormErrorList aFormErrors = new FormErrorList();
if (aWPEC.hasAction(CPageParam.ACTION_PERFORM)) {
final String sParticipantID = aWPEC.params().getAsString(FIELD_PARTICIPANT_ID);
final IParticipantIdentifier aParticipantID = aIdentifierFactory.parseParticipantIdentifier(sParticipantID);
if (StringHelper.hasNoText(sParticipantID))
aFormErrors.addFieldError(FIELD_PARTICIPANT_ID, "A participant ID must be provided.");
else if (aParticipantID == null)
aFormErrors.addFieldError(FIELD_PARTICIPANT_ID, "The provided participant ID is syntactically invalid.");
if (aFormErrors.isEmpty()) {
int nDeleted = 0;
try {
nDeleted = PDMetaManager.getStorageMgr().deleteEntry(aParticipantID, null, false);
} catch (final IOException ex) {
// ignore
nDeleted = -1;
}
if (nDeleted > 0)
aWPEC.postRedirectGetInternal(success("The participant ID '" + aParticipantID.getURIEncoded() + "' was deleted (" + nDeleted + " rows)"));
else
aWPEC.postRedirectGetInternal(error("Error deleting participant ID '" + aParticipantID.getURIEncoded() + "'"));
}
}
final BootstrapForm aForm = aNodeList.addAndReturnChild(getUIHandler().createFormSelf(aWPEC));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Participant ID").setCtrl(new HCEdit(new RequestField(FIELD_PARTICIPANT_ID, PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME + CIdentifier.URL_SCHEME_VALUE_SEPARATOR))).setHelpText(span().addChild("Enter the fully qualified Peppol participant ID (including the scheme) you want to delete.\nExample identifier layout: ").addChild(code(aIdentifierFactory.createParticipantIdentifier(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, "9999:test").getURIEncoded()))).setErrorList(aFormErrors.getListOfField(FIELD_PARTICIPANT_ID)));
final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(new BootstrapButtonToolbar(aWPEC));
aToolbar.addHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM);
aToolbar.addSubmitButton("Delete from index", EDefaultIcon.DELETE);
}
Aggregations