use of com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider in project phoss-smp by phax.
the class APIExecutorServiceMetadataDelete method invokeAPI.
public void invokeAPI(@Nonnull final IAPIDescriptor aAPIDescriptor, @Nonnull @Nonempty final String sPath, @Nonnull final Map<String, String> aPathVariables, @Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final UnifiedResponse aUnifiedResponse) throws Exception {
final String sPathServiceGroupID = aPathVariables.get(SMPRestFilter.PARAM_SERVICE_GROUP_ID);
final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider(aRequestScope, sPathServiceGroupID);
// Is the writable API disabled?
if (SMPMetaManager.getSettings().isRESTWritableAPIDisabled()) {
throw new SMPPreconditionFailedException("The writable REST API is disabled. deleteServiceRegistration will not be executed", aDataProvider.getCurrentURI());
}
final String sDocumentTypeID = aPathVariables.get(SMPRestFilter.PARAM_DOCUMENT_TYPE_ID);
final BasicAuthClientCredentials aBasicAuth = getMandatoryAuth(aRequestScope.headers());
switch(SMPServerConfiguration.getRESTType()) {
case PEPPOL:
new SMPServerAPI(aDataProvider).deleteServiceRegistration(sPathServiceGroupID, sDocumentTypeID, aBasicAuth);
break;
case OASIS_BDXR_V1:
new BDXR1ServerAPI(aDataProvider).deleteServiceRegistration(sPathServiceGroupID, sDocumentTypeID, aBasicAuth);
break;
default:
throw new UnsupportedOperationException("Unsupported REST type specified!");
}
aUnifiedResponse.setStatus(CHttp.HTTP_OK).disableCaching();
}
use of com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider in project phoss-smp by phax.
the class APIExecutorServiceMetadataGet method invokeAPI.
public void invokeAPI(@Nonnull final IAPIDescriptor aAPIDescriptor, @Nonnull @Nonempty final String sPath, @Nonnull final Map<String, String> aPathVariables, @Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final UnifiedResponse aUnifiedResponse) throws Exception {
final String sPathServiceGroupID = aPathVariables.get(SMPRestFilter.PARAM_SERVICE_GROUP_ID);
final String sPathDocumentTypeID = aPathVariables.get(SMPRestFilter.PARAM_DOCUMENT_TYPE_ID);
final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider(aRequestScope, sPathServiceGroupID);
// Create the unsigned response document
final Document aDoc;
switch(SMPServerConfiguration.getRESTType()) {
case PEPPOL:
{
final com.helger.xsds.peppol.smp1.SignedServiceMetadataType ret = new SMPServerAPI(aDataProvider).getServiceRegistration(sPathServiceGroupID, sPathDocumentTypeID);
// Convert to DOM document
// Disable XSD check, because Signature is added later
final SMPMarshallerSignedServiceMetadataType aMarshaller = new SMPMarshallerSignedServiceMetadataType(false);
aDoc = aMarshaller.getAsDocument(ret);
break;
}
case OASIS_BDXR_V1:
{
final com.helger.xsds.bdxr.smp1.SignedServiceMetadataType ret = new BDXR1ServerAPI(aDataProvider).getServiceRegistration(sPathServiceGroupID, sPathDocumentTypeID);
// Convert to DOM document
// Disable XSD check, because Signature is added later
final BDXR1MarshallerSignedServiceMetadataType aMarshaller = new BDXR1MarshallerSignedServiceMetadataType(false);
aDoc = aMarshaller.getAsDocument(ret);
break;
}
default:
throw new UnsupportedOperationException("Unsupported REST type specified!");
}
if (aDoc == null)
throw new IllegalStateException("Failed to serialize unsigned node!");
// Sign the document
try {
SMPKeyManager.getInstance().signXML(aDoc.getDocumentElement(), SMPServerConfiguration.getRESTType().isBDXR());
LOGGER.info("Successfully signed response XML");
} catch (final Exception ex) {
throw new SMPInternalErrorException("Error in signing the response XML", ex);
}
// Serialize the signed document
try (final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream()) {
if (false) {
// IMPORTANT: no indent and no align!
final IXMLWriterSettings aSettings = XMLWriterSettings.createForCanonicalization();
// Write the result to a byte array
if (XMLWriter.writeToStream(aDoc, aBAOS, aSettings).isFailure())
throw new IllegalStateException("Failed to serialize signed node!");
} else {
// for validating the signature!
try {
final Transformer aTransformer = XMLTransformerFactory.newTransformer();
aTransformer.transform(new DOMSource(aDoc), new StreamResult(aBAOS));
} catch (final TransformerException ex) {
throw new IllegalStateException("Failed to serialized signed node", ex);
}
}
aUnifiedResponse.setContent(aBAOS.toByteArray()).setMimeType(CMimeType.TEXT_XML).setCharset(XMLWriterSettings.DEFAULT_XML_CHARSET_OBJ);
}
}
use of com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider in project phoss-smp by phax.
the class APIExecutorServiceMetadataPut method invokeAPI.
public void invokeAPI(@Nonnull final IAPIDescriptor aAPIDescriptor, @Nonnull @Nonempty final String sPath, @Nonnull final Map<String, String> aPathVariables, @Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final UnifiedResponse aUnifiedResponse) throws Exception {
final String sPathServiceGroupID = aPathVariables.get(SMPRestFilter.PARAM_SERVICE_GROUP_ID);
final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider(aRequestScope, sPathServiceGroupID);
// Is the writable API disabled?
if (SMPMetaManager.getSettings().isRESTWritableAPIDisabled()) {
throw new SMPPreconditionFailedException("The writable REST API is disabled. saveServiceRegistration will not be executed", aDataProvider.getCurrentURI());
}
// Parse main payload
final byte[] aPayload = StreamHelper.getAllBytes(aRequestScope.getRequest().getInputStream());
final Document aServiceMetadataDoc = DOMReader.readXMLDOM(aPayload);
if (aServiceMetadataDoc == null) {
throw new SMPBadRequestException("Failed to parse provided payload as XML", aDataProvider.getCurrentURI());
}
final String sDocumentTypeID = aPathVariables.get(SMPRestFilter.PARAM_DOCUMENT_TYPE_ID);
final BasicAuthClientCredentials aBasicAuth = getMandatoryAuth(aRequestScope.headers());
ESuccess eSuccess = ESuccess.FAILURE;
switch(SMPServerConfiguration.getRESTType()) {
case PEPPOL:
{
final com.helger.xsds.peppol.smp1.ServiceMetadataType aServiceMetadata = new SMPMarshallerServiceMetadataType(XML_SCHEMA_VALIDATION).read(aServiceMetadataDoc);
if (aServiceMetadata != null) {
eSuccess = new SMPServerAPI(aDataProvider).saveServiceRegistration(sPathServiceGroupID, sDocumentTypeID, aServiceMetadata, aBasicAuth);
}
break;
}
case OASIS_BDXR_V1:
{
final com.helger.xsds.bdxr.smp1.ServiceMetadataType aServiceMetadata = new BDXR1MarshallerServiceMetadataType(XML_SCHEMA_VALIDATION).read(aServiceMetadataDoc);
if (aServiceMetadata != null) {
eSuccess = new BDXR1ServerAPI(aDataProvider).saveServiceRegistration(sPathServiceGroupID, sDocumentTypeID, aServiceMetadata, aBasicAuth);
}
break;
}
default:
throw new UnsupportedOperationException("Unsupported REST type specified!");
}
if (eSuccess.isFailure())
aUnifiedResponse.setStatus(CHttp.HTTP_INTERNAL_SERVER_ERROR);
else
aUnifiedResponse.setStatus(CHttp.HTTP_OK).disableCaching();
}
use of com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider in project phoss-smp by phax.
the class APIExecutorExportSpecificXMLVer1 method invokeAPI.
public void invokeAPI(@Nonnull final IAPIDescriptor aAPIDescriptor, @Nonnull @Nonempty final String sPath, @Nonnull final Map<String, String> aPathVariables, @Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final UnifiedResponse aUnifiedResponse) throws Exception {
final String sPathServiceGroupID = aPathVariables.get(SMPRestFilter.PARAM_SERVICE_GROUP_ID);
final String sLogPrefix = "[REST API Export-Specific-XML-V1] ";
LOGGER.info(sLogPrefix + "Starting Export of '" + sPathServiceGroupID + "'");
// Only authenticated user may do so
final BasicAuthClientCredentials aBasicAuth = getMandatoryAuth(aRequestScope.headers());
SMPUserManagerPhoton.validateUserCredentials(aBasicAuth);
// Start action after authentication
final ISMPSettingsManager aSettingsMgr = SMPMetaManager.getSettingsMgr();
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider(aRequestScope, null);
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final IParticipantIdentifier aPathServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sPathServiceGroupID);
if (aPathServiceGroupID == null) {
// Invalid identifier
throw SMPBadRequestException.failedToParseSG(sPathServiceGroupID, aDataProvider.getCurrentURI());
}
// Retrieve the service group
final ISMPServiceGroup aServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aPathServiceGroupID);
if (aServiceGroup == null) {
// No such service group
throw new SMPNotFoundException("Unknown Service Group '" + sPathServiceGroupID + "'", aDataProvider.getCurrentURI());
}
final boolean bIncludeBusinessCards = aRequestScope.params().getAsBoolean(PARAM_INCLUDE_BUSINESS_CARDS, aSettingsMgr.getSettings().isDirectoryIntegrationEnabled());
final IMicroDocument aDoc = ServiceGroupExport.createExportDataXMLVer10(new CommonsArrayList<>(aServiceGroup), bIncludeBusinessCards);
LOGGER.info(sLogPrefix + "Finished creating Export data");
// Build the XML response
final IXMLWriterSettings aXWS = new XMLWriterSettings();
aUnifiedResponse.setContentAndCharset(MicroWriter.getNodeAsString(aDoc, aXWS), aXWS.getCharset()).setMimeType(new MimeType(CMimeType.APPLICATION_XML).addParameter(CMimeType.PARAMETER_NAME_CHARSET, aXWS.getCharset().name())).disableCaching();
}
use of com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider in project phoss-smp by phax.
the class APIExecutorBusinessCardDelete method invokeAPI.
public void invokeAPI(@Nonnull final IAPIDescriptor aAPIDescriptor, @Nonnull @Nonempty final String sPath, @Nonnull final Map<String, String> aPathVariables, @Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final UnifiedResponse aUnifiedResponse) throws Exception {
final String sServiceGroupID = aPathVariables.get(SMPRestFilter.PARAM_SERVICE_GROUP_ID);
final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider(aRequestScope, sServiceGroupID);
// Is the writable API disabled?
if (SMPMetaManager.getSettings().isRESTWritableAPIDisabled()) {
throw new SMPPreconditionFailedException("The writable REST API is disabled. deleteBusinessCard will not be executed", aDataProvider.getCurrentURI());
}
if (!SMPMetaManager.getSettings().isDirectoryIntegrationEnabled()) {
// PD integration is disabled
throw new SMPPreconditionFailedException("The " + SMPWebAppConfiguration.getDirectoryName() + " integration is disabled. deleteBusinessCard will not be executed", aDataProvider.getCurrentURI());
}
final BasicAuthClientCredentials aBasicAuth = getMandatoryAuth(aRequestScope.headers());
new BusinessCardServerAPI(aDataProvider).deleteBusinessCard(sServiceGroupID, aBasicAuth);
aUnifiedResponse.setStatus(CHttp.HTTP_OK);
}
Aggregations