Where inserting the TenantInfoHolder to set the tenantId when implementing Multi Schema / Multi Tenant

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Active Member

Where inserting the TenantInfoHolder to set the tenantId when implementing Multi Schema / Multi Tenant

Jump to solution

Hello,

I try to implement a Multi-Schema Multi-Tenancy with the MultiSchemaMultiTenantProcessEngineConfiguration configuration class. I integrate with Activiti only through rest, my main app is written in Python.

Every request I do to activiti has the tenantId information, then it should be easy for activiti to route the query to the correct DB, however I need to crate a class implementing the TenantInfoHolder.

My question is, where do I hook this class in activiti-rest code to be sure the tenantId will be always set when a DB query is done ?

Thank you !

 

 

1 Solution

Accepted Solutions
Highlighted
Intermediate

Re: Where inserting the TenantInfoHolder to set the tenantId when implementing Multi Schema / Multi Tenant

Jump to solution

The class that implements TenantInfoHolder is registered when you create the configuration for MSMT.

It is a relatively simple interface and in general all it needs to do is correlate your current userid to the tenant id.

Alternatively, if the tenant_id will be included in the url you can use a filter to set/get a thread local variable:

protected static final ThreadLocal<Long> currentTenantIdPlaceHolder = new ThreadLocal<Long>();

...

...

    @Override

    public void setCurrentTenantId(String tenantId) {

        currentTenantIdPlHolder.set(Long.valueOf(tenantId));

    }

Also, make sure you take a look at the following blog post:
Multi-Tenancy with separate database schemas in Activiti | Small steps with big feet 

Cheers,
greg

View solution in original post

3 Replies
Highlighted
Intermediate

Re: Where inserting the TenantInfoHolder to set the tenantId when implementing Multi Schema / Multi Tenant

Jump to solution

The class that implements TenantInfoHolder is registered when you create the configuration for MSMT.

It is a relatively simple interface and in general all it needs to do is correlate your current userid to the tenant id.

Alternatively, if the tenant_id will be included in the url you can use a filter to set/get a thread local variable:

protected static final ThreadLocal<Long> currentTenantIdPlaceHolder = new ThreadLocal<Long>();

...

...

    @Override

    public void setCurrentTenantId(String tenantId) {

        currentTenantIdPlHolder.set(Long.valueOf(tenantId));

    }

Also, make sure you take a look at the following blog post:
Multi-Tenancy with separate database schemas in Activiti | Small steps with big feet 

Cheers,
greg

View solution in original post

Highlighted
Active Member

Re: Where inserting the TenantInfoHolder to set the tenantId when implementing Multi Schema / Multi Tenant

Jump to solution

Thank you Greg,

I will try to hook in the BasicAuthenticationProvider class !

Stephane

Highlighted
Intermediate

Re: Where inserting the TenantInfoHolder to set the tenantId when implementing Multi Schema / Multi Tenant

Jump to solution

Sounds like a good option. God luck.

Greg