You should have an idea, under which thread you are executing. It is better to resolve the
CarbonContext outside that util method, as opposed to resolving the CarbonContext within the method. If calling
CarbonContext.getCurrentContext returns a
CarbonContext with tenant ID
tenantId=-1 or tenant domain
tenantDomain=null, that means, some upstream code has not populated the data needed for the
CarbonContext; therefore, you have to first look into fixing this issue.
During an execution flow, sometimes you will need to switch from super tenant mode to tenant mode, do some work as that tenant, and then get back to super tenant mode. In such a scenario, you will do the following;
Start the Tenant Flow.
Set the tenant ID and the tenant domain in the new CarbonContext data holder that gets created when you start the tenant flow.
Do somethingCarryout the respective action.
endTenantFlowEnd the tenant flow.
Always follow the following template when you carryout the latter mentioned steps:
- public int getTenantId()
- String getUsername()
- String getTenantDomain()
- Registry getRegistry(RegistryType type)
- UserRealm getUserRealm()
- CarbonQueue<?> getQueue(String name)
- Context getJNDIContext(Hashtable properties) throws NamingException
- Context getJNDIContext() throws NamingException
- CarbonContext API String discover(URI scopes)
public int getTenantId()
This method retrieves the tenant ID.
This method retrieves the tenant's username.
This method retrieves the tenant domain.
Registry getRegistry(RegistryType type)
- USER_CONFIGURATION - The configuration registry of the currently logged in user.
- USER_GOVERNANCE - The governance registry of the currently logged in user.
- SYSTEM_CONFIGURATION - The system configuration registry of the tenant.
This method retrieves the user realm of the current tenant.
CarbonQueue<?> getQueue(String name)