I'm developing a multi tenant app on the SAP BTP and I need to process webhook events that I receive from a non-SAP system. More specifically, upon receiving an event, I need to access a destination in my tenant's sub account and query some data from the system configured behind this destination.
The endpoint on which I receive the webhook events on is secured via basic authentication with my own user database. So that means the incoming webhook request never passes the sdk's RequestFilter
which would usually extract the JWT token (which in my case wouldn't be present anyways) and set the ThreadContext
.
I tried the following code (the webhook payload contains the correct tenant id):
@Override
public void handleWebhook(WebhookEvent webhookEvent) {
TenantAccessor.executeWithTenant(tenantOfString(webhookEvent.getTenantId()), () -> {
Destination destination = DestinationAccessor.getDestination("MyDestination");
//Do some stuff with the destination
});
}
private Tenant tenantOfString(String tenantId) {
return new Tenant() {
@Nonnull
@Override
public String getTenantId() {
return tenantId;
}
};
}
Unfortunately, this code results in the following error:
com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationAccessException: com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationNotFoundException: No destination for name 'MyDestination' could be found in any of the registered loaders. When your app runs on SAP Cloud Platform, make sure you have one of the following modules in your dependency tree: com.sap.cloud.sdk.cloudplatform:scp-neo or com.sap.cloud.sdk.cloudplatform:scp-cf, depending on your SCP landscape.
What could be a solution to solve this kind of issue? It seems to me that I somehow have to manually configure a proper ThreadContext
in order to perform such kind of operations.
EDIT: The destination exists in the tenant's sub account and I also set up a test endpoint with oAuth and an JWT token retrieved from the tenant's authentication endpoint, with which i can successfully access the tenant's destination from my provider account. So I assume the the entire saas provisioning process works correctly.