Access to add and change pages is restricted. See: https://cwiki.apache.org/confluence/display/OFBIZ/Wiki+access

Commit history and discussions regarding these enhancements can be tracked from the JIRA task OFBIZ-5898 - Getting issue details... STATUS

Introduction

Multitenancy is the ability to run separate data instances (tenants) from a single code base. In this case, each tenant will have its database. A user logs into a data instance (or tenant) by specifying the tenant ID in the login form or by hitting tenant tenant-specific URL. Although a default database is still used.

Some enhancements are proposed in the multitenancy functionality of Apache OFBiz to provide support for the following features:

  • To run a frontend application on a multitenant environment
  • To make the configuration attribute specific to a tenant.
  • To specify a domain name for each tenant and to run a tenant instance on a specified domain name.
  • To support multiple domains for each tenant so that the tenant can be used with multi-site functionality

Here is a brief description of each feature

Multitenant Support At Front Store

Currently, OFBiz supports multitenancy at the back-end only, where user can login with tenant# and the system starts pointing to the database of that particular tenant. Now we have provided support of multitenancy at the frontend application as well which can be accessed by tenant specific domain name e.g. abc.com.

Tenant Specific Configuration Attributes

With the implementation of these enhancement features, tenants can have their configurations/settings also for the frontend application. In other words, we can say that now it is possible to have tenant-specific settings at the frontend application as well, like theme, layouts, catalog etc. This can be achieved by using the SystemProperty entity through EntityUtil methods.

Run Tenant Instance On Specified Domain Name

This functionality enables the service provider to specify a domain name for each tenant and run the instance on a specified domain name. Suppose we have a tenant 'XYZ' with domain name xyz.com. Now we can access XYZ specific database by hitting xyz.com in the browser.

Multiple Domains And Multi-Site Functionality

This functionality also enables support for multiple domains and subdomains for tenants. This feature can be used in multi-site functionality. For example, suppose a tenant has multiple sites like abc.com and abc.org, or has subdomains like abc.watch.com and abc.cloths.com. If any user hits any of the above URLs, the system will point to the _Single_ database of tenant 'abc'.

To provide support for above mentioned features, we will have to make the following changes:

Creation Of New Entity 'TenantDomainName'

To save information related to the Tenant and its domain name, we have an entity named 'Tenant' in OFBiz. In this entity tenantId is the primary key, so we can store only one domain name for a particular tenant. There is a problem when a tenant has more than one domain name, or we can say subdomains. So we have introduced a new entity 'TenantDomainName' which will have domainName as the primary key and tenantId as a non-primary key column. Hence, we can save multiple domain names for a tenant.

Enhancements in 'create-tenant' Target

To add support for adding a domain name while setting up a new tenant, the 'create-tenant' target has been modified. Now the system will ask "Enter domain name for tenant(optional):" at the time of tenant creation, with other information. This domain name will be stored in the new entity 'TenantDomainName' along with tenantId. At the time of URL hit, the system will look for the domain name, find the corresponding tenant, and will start pointing to the corresponding database.

Following steps should be followed to have support for above mentioned features in your application

Gradle

If you use a "new" version that does not embed Ant nor any build.xml file, it means that you should use Gradle tasks instead of the following Ant targets. For more information please refer to the Gradle documentation in the wiki.

  1. Move your code base to -r1658369

  2. Set property 'multitenant=Y' in file framework/common/config/general.properties 

  3. Create a new tenant by using the createTenantant target 'create-tenant'

  4. Do ant clean / ant build and restart your server

  5. For local instance setup, you will need to make an entry of the new domain name in /etc/hosts with ip address of the machine, like:  127.0.0.1 localhost abc.com

  6. Make Apache connector-related settings so that you do not need to use port information in url

  7. Go to the frontend application by entering url with the domain name without port like: http://abc.com/ecommerce/  or with port like: http://abc.com:8080/ecommerce/

  8. For backend applications, the domain name field is optional. You can access backend applications by entering the tenantId from the login page OR by entering url with the domain name as described above in #7.