Multi-country polymer site

Refer to my polymer-based site
I would like to display country-specific entity records based on the country selected by user in the website. By default the selected country should be the country the user is accessing the website from based on IP address. To achieve this I have implemented single-database multi-tenancy through access groups, where each country represents a tenant as follows:
– Countries
------ Kenya
------ Uganda
------ South Africa

This approach works well for a private site where users have to login, and a session attribute ‘country’ is automatically set based on the access group ‘country’ they belong. However my site is publicly accessed, that is it uses anonymous user login when users access it without logging in.
My challenge is how to make sure users who publicly access the website from various countries get their session attribute initially set to their country, but still allowing the user to switch the country, which is useful in case where someone is accessing the site from abroad but still want to view data for their country of origin.

This is what I have done so far in addition to implementing multi-tenancy:

  1. I have put the Anonymous user at the ‘Countries’ access group above the countries.
  2. I have put a drop-down menu element inside the polymer shell page to display list of countries as follows:
            <paper-dropdown-menu id="countryMenu" class="custom" label="Select Country" dynamic-align=true horizontal-align="right">
              <paper-listbox slot="dropdown-content" attr-for-selected="value" selected="{{country}}" on-selected-item-changed="_setCountrySessionVariable" >
               <paper-item value="Kenya" >Kenya</paper-item>
                <paper-item value="Uganda" >Uganda</paper-item>
                <paper-item value="Zambia" >Zambia</paper-item>
                <paper-item value="South Africa" >South Africa</paper-item>

My specific questions are

  1. How to set the selected country to user’s country by default
  2. How to set the ‘country’ user session attribute of Anonymous user dynamically when user switches the country in the polymer page.

Hi, the main issue here is that the anonymous users share the same middleware [anonymous] session. So in order to have different session attributes for different groups of anonymous users we have to create several middleware sessions (e.g. one for each group).

In order to achieve this you can do the following:

  1. Create anonymous users for each country, (e.g. kenya-anonymous). Double check that restrictive role and access group are assigned to each user.

  2. Override default cuba_AnonymousAuthenticationFilter bean. In order to do this:

  • create CustomAnonymousAuthenticationFilter class.
  • create rest-dispatcher-spring.xml in web/portal module with the following contents:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""

    <bean id="cuba_AnonymousAuthenticationFilter"

  • register config in
cuba.restSpringContextConfig = +com/company/demo/rest-dispatcher-spring.xml
  1. Implement CustomAnonymousAuthenticationFilter so that it will create and reuse appropriate anonymous session e.g. in depend on request header. You can use AuthenticationService/TrustedClientCredentials to log-in anonymous user.

Unfortunately currently it’s not easy to intervene to all requests to rest api made by Polymer client so that you can pass selected country as header. But there is an issue for that. Let me know if it’s viable solution for you so that we can prioritize the issue above.

Thank Vlad for the quick response. Let me try this approach and will revert back soon.

Yes please prioritize resolution of issue:“Provide an ability to intercept requests/responses” as it will be useful for my case.