cancel
Showing results for 
Search instead for 
Did you mean: 

Switching tenant depending on the url

Former Member
0 Kudos
493

Hi all,

I have two websites in one storefront and each one in a tenant.

customStoreFront:

  • website 1 => tenant master

  • website 2 => tenant slave1

I want to access each website with a different url, like :

www.company1 .com and www.company2.com.

The webroot of the storefront is the same for each website : /

 customstorefront.webroot=/


The problem is that, when I request www.company2.com I have a cms site not found exception because I am on the master tenant instead of slave1.

Should I use something like a DataSourceSwitchingFilter or a TenantActivationFilter to request the desired tenant?

For now I have an exception like

 java.lang.IllegalStateException: ###############################################################
 Given current tenant is <<company2>>[1091343644] but returned servlet context related web context (Root WebApplicationContext - : startup date [Tue Oct 17 15:00:58 CEST 2017]; parent: hybris Application context - master) is attached to other tenant master
 ###############################################################


When I try to change the current tenant.

Any help on this?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Another solution is to run two Docker with Hybris where each instance is set on specified context and tenant.

Nginx will have to redirect to the correct container.

And then, I am using multitenancy without having to specify a webroot.

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

Another solution I tried is, to add a webroot for each tenant and add the webroot with nginx and proxypass

like:

client request : www.company1.com => nginx : www.company1.com/webroot1 => hybris

and

client request : www.company2.com => nginx : www.company2.com/webroot2 => hybris

But now I am facing trouble with spring security as it redirect with the webroot in the url and if I remove it before the redirect I'm not logged in.

So my question is: Which solution seems to be the best? the TenantActivationFilter or with the webroot and nginx ?

former_member537989
Contributor
0 Kudos

TenantActivationFilter is the way to go forward, DataSourceSwitchingFilter is a wrong place because it depends on the activated Tenant.

Former Member
0 Kudos

Gavazyuk thanks for the reply. TenantActivationFilter is marked as deprecated should I use it anyway or is there a better solution ?

former_member537989
Contributor
0 Kudos

yeah, because it's done now by de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain (de.hybris.platform.servicelayer.web.PlatformFilterChain is actual instance) so you will need to overrid there.

Former Member
0 Kudos

From my understanding so far, it is impossible to set-up a multi-tenant environment without specifying a webroot for each tenant.

Am I right?

former_member537989
Contributor
0 Kudos

Vice versa, you can do identification of tenant in any way possible, default approach is based on URL postfix.

Former Member
0 Kudos

Thanks , for taking the time to reply.

I am able to change the tenant based on the request but without specifying the webroot the context is always master. And that, throws the exception mention in my first post.

gopinath_nese
Explorer
0 Kudos

Hi, am also looking for the exact solution. can someone share their experience on creating multi tenant.

So far, i have tried creating multi tenant with copy of master tenant configurations using same database, then done only system update. The actual suggestion was to do the Initialization for activating the slave tenant.

In my organisation, we have stopped doing initialization from long time, reason being loosing customer data. Hence trying with system update only [the slave tenant is not activated]

With master, junit example - with initialization am able to see multi tenant working /hac and /hac_junit. Can someone pleas suggest

Thank you.