Site Resolution
Broadleaf provides a flexible mechanism for resolving which site needs to serve a customer request.
The first component involved in site resolution is the BroadleafRequestProcessor
. This component is responsible for
resolving other request specific concerns such as the current Locale, TimeZone, and Currency. It does this via a set of
"resolver" components.
For sites, the BroadleafRequestProcessor
calls the resolveSite
method of the blSiteResovler
component.
Here is the interface used by this component ...
public interface BroadleafSiteResolver {
public Site resolveSite(WebRequest request) throws SiteNotFoundException;
}
The MultiTenant module provides an implementation of this interface named MultiTenantSiteResolver
. This component
uses the data stored in the BLC_SITE
table to resolve the site in one of two ways.
The BLC_SITE
table SITE_IDENTIFIER_TYPE
column stores either DOMAIN or DOMAIN_PREFIX.
Domain Resolution
If the Site resolution type is DOMAIN then a Site will be used if it matches the request.getHeader("Host")
. For
example, if the request is for "http://www.mysite.com" then "www.mysite.com" would be the value to be matched.
Domain Prefix Resolution
If the Site resolution type is DOMAIN_PREFIX then the Site will be used if it matches the first token of the domain. For
example, if the request is for "http://site1.mycompany.com" then "site1" would be the value to be matched
API Resolution
While the above domain and domain prefix resolution still apply for the API, it might also be interesting to configure resolution by either a request parameter or request header and not change the domain at all. You can configure this by specifying your own version of the blSiteResolver
bean.
Query Parameter Resolution
This keys off of a siteIdentifier
query parameter. For example: http://localhost:8080/api/catalog/v2/categories?siteIdentifier=abc
.
XML config:
<bean id="blSiteResolver" class="com.broadleafcommerce.tenant.web.resolver.MultiTenantQueryParameterSiteResolver" />
Java Config:
@Bean
public SiteResolver blSiteResolver() {
return new MultiTenantQueryParameterSiteResolver();
}
Request Header Resolution
This keys off of a SITE_IDENTIFIER
request header. For example, send a request to http://localhost:8080/api/catalog/v2/categories
with a header for SITE_IDENTIFIER=abc
.
XML config:
<bean id="blSiteResolver" class="com.broadleafcommerce.tenant.web.resolver.MultiTenantHeaderSiteResolver" />
Java Config:
@Bean
public SiteResolver blSiteResolver() {
return new MultiTenantHeaderSiteResolver();
}
Additional Notes
- Like most components in Broadleaf, the
blSiteResolver
component can be extended for more exotic implementation needs. - The tenant admin application is accessed in the same way as the tenant site. The particular tenant/site will be harvested from the request URL in the same way as the tenant site (e.g. http://mysite.mydomain.com/admin). Also, the development mode is also supported for the admin application (e.g. http://localhost:8080/admin?siteId=1).
Rendering Global Admin Application
The global admin application is a special admin application that has specialized functions that apply to the system or in
some cases to all sites. Typical usages would be limited to maintaining global admin users and creating new sites (although
typically creating new sites would happen through a Site Provisioning process.
Global admin users can also be given the ability permissions that apply to all sites. For example, a global admin user
with a "merchandising" role could perform operations on the catalog of any site.
This differs from site admins that only have roles and permissions for one or more sites, but not all. This is described
in more detail in the Security Contexts section.