Class PrivilegedCarbonContext


  • public class PrivilegedCarbonContext
    extends CarbonContext
    This CarbonContext provides users the ability to carry out privileged actions such as switching tenant flows, setting tenant ID etc.
    • Method Detail

      • startTenantFlow

        public static void startTenantFlow()
        Starts a tenant flow. This will stack the current CarbonContext and begin a new nested flow which can have an entirely different context. This is ideal for scenarios where multiple super-tenant and sub-tenant phases are required within as a single block of execution.
        See Also:
        CarbonContextDataHolder.startTenantFlow()
      • unloadTenant

        public static void unloadTenant​(int tenantId)
      • destroyCurrentContext

        public static void destroyCurrentContext()
      • getThreadLocalCarbonContext

        public static PrivilegedCarbonContext getThreadLocalCarbonContext()
        Returns:
        PrivilegedCarbonContext from the current thread
      • setTenantId

        public void setTenantId​(int tenantId)
        Method to set the tenant id on this CarbonContext instance. This method will not automatically calculate the tenant domain based on the tenant id.
        Parameters:
        tenantId - the tenant id.
      • setTenantId

        public void setTenantId​(int tenantId,
                                boolean resolveTenantDomain)
        Method to set the tenant id on this CarbonContext instance.
        Parameters:
        tenantId - the tenant id.
        resolveTenantDomain - whether the tenant domain should be calculated based on this tenant id.
      • setUsername

        public void setUsername​(String username)
        Method to set the username on this CarbonContext instance.
        Parameters:
        username - the username.
      • setUserId

        public void setUserId​(String userId)
        Method to set the user id on this CarbonContext instance.
        Parameters:
        userId - the user id.
      • setOrganizationId

        public void setOrganizationId​(String organizationId)
        Method to set the organization id on this CarbonContext instance.
        Parameters:
        organizationId - the organization id.
      • setTenantDomain

        public void setTenantDomain​(String tenantDomain)
        Method to set the tenant domain on this CarbonContext instance. This method will not automatically calculate the tenant id based on the tenant domain.
        Parameters:
        tenantDomain - the tenant domain.
      • setTenantDomain

        public void setTenantDomain​(String tenantDomain,
                                    boolean resolveTenantId)
        Method to set the tenant domain on this CarbonContext instance.
        Parameters:
        tenantDomain - the tenant domain.
        resolveTenantId - whether the tenant id should be calculated based on this tenant domain.
      • getTenantDomain

        public String getTenantDomain​(boolean resolve)
        Method to obtain the tenant domain on this CarbonContext instance. This method can optionally resolve the tenant domain using the tenant id that is already posses.
        Parameters:
        resolve - whether the tenant domain should be calculated based on the tenant id that is already known.
        Returns:
        the tenant domain.
      • getTenantId

        public int getTenantId​(boolean resolve)
        Method to obtain the tenant id on this CarbonContext instance. This method can optionally resolve the tenant id using the tenant domain that is already posses.
        Parameters:
        resolve - whether the tenant id should be calculated based on the tenant domain that is already known.
        Returns:
        the tenant id.
      • setRegistry

        public void setRegistry​(RegistryType type,
                                org.wso2.carbon.registry.api.Registry registry)
        Method to set an instance of a registry on this CarbonContext instance.
        Parameters:
        type - the type of registry to set.
        registry - the registry instance.
      • getRegistry

        public org.wso2.carbon.registry.api.Registry getRegistry​(RegistryType type)
        Method to obtain an instance of a registry on this CarbonContext instance.
        Overrides:
        getRegistry in class CarbonContext
        Parameters:
        type - the type of registry required.
        Returns:
        the requested registry instance.
      • setUserRealm

        public void setUserRealm​(org.wso2.carbon.user.api.UserRealm userRealm)
      • getOSGiService

        public Object getOSGiService​(Class clazz,
                                     Hashtable<String,​String> props)
        Obtain the first OSGi service found for interface or class clazz and props
        Overrides:
        getOSGiService in class CarbonContext
        Parameters:
        props - attribute list that filter the service
        clazz - The type of the OSGi service
        Returns:
        The OSGi service
      • getOSGiServices

        public List<Object> getOSGiServices​(Class clazz,
                                            Hashtable<String,​String> props)
        Obtain the OSGi services found for interface or class clazz and props
        Overrides:
        getOSGiServices in class CarbonContext
        Parameters:
        props - attribute list that filter the service list
        clazz - The type of the OSGi service
        Returns:
        The List of OSGi services
      • setApplicationName

        public void setApplicationName​(String applicationName)