Package org.wso2.carbon.context
Class PrivilegedCarbonContext
- java.lang.Object
-
- org.wso2.carbon.context.CarbonContext
-
- org.wso2.carbon.context.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 Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static voiddestroyCurrentContext()static voidendTenantFlow()This will end the tenant flow and restore the previous CarbonContext.ObjectgetOSGiService(Class clazz)Deprecated.please usegetOSGiService(Class, java.util.Hashtable)insteadObjectgetOSGiService(Class clazz, Hashtable<String,String> props)Obtain the first OSGi service found for interface or classclazzand propsList<Object>getOSGiServices(Class clazz)Deprecated.please usegetOSGiServices(Class, java.util.Hashtable)insteadList<Object>getOSGiServices(Class clazz, Hashtable<String,String> props)Obtain the OSGi services found for interface or classclazzand propsorg.wso2.carbon.registry.api.RegistrygetRegistry(RegistryType type)Method to obtain an instance of a registry on this CarbonContext instance.StringgetTenantDomain(boolean resolve)Method to obtain the tenant domain on this CarbonContext instance.intgetTenantId(boolean resolve)Method to obtain the tenant id on this CarbonContext instance.static PrivilegedCarbonContextgetThreadLocalCarbonContext()voidsetApplicationName(String applicationName)voidsetOrganizationId(String organizationId)Method to set the organization id on this CarbonContext instance.voidsetRegistry(RegistryType type, org.wso2.carbon.registry.api.Registry registry)Method to set an instance of a registry on this CarbonContext instance.voidsetTenantDomain(String tenantDomain)Method to set the tenant domain on this CarbonContext instance.voidsetTenantDomain(String tenantDomain, boolean resolveTenantId)Method to set the tenant domain on this CarbonContext instance.voidsetTenantId(int tenantId)Method to set the tenant id on this CarbonContext instance.voidsetTenantId(int tenantId, boolean resolveTenantDomain)Method to set the tenant id on this CarbonContext instance.voidsetUserId(String userId)Method to set the user id on this CarbonContext instance.voidsetUsername(String username)Method to set the username on this CarbonContext instance.voidsetUserRealm(org.wso2.carbon.user.api.UserRealm userRealm)static voidstartTenantFlow()Starts a tenant flow.static voidunloadTenant(int tenantId)-
Methods inherited from class org.wso2.carbon.context.CarbonContext
createFilter, discover, getApplicationName, getCarbonContextDataHolder, getJNDIContext, getJNDIContext, getOrganizationId, getQueue, getTenantDomain, getTenantId, getUserId, getUsername, getUserRealm
-
-
-
-
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.
-
endTenantFlow
public static void endTenantFlow()
This will end the tenant flow and restore the previous CarbonContext.- See Also:
CarbonContextDataHolder.endTenantFlow()
-
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:
getRegistryin classCarbonContext- Parameters:
type- the type of registry required.- Returns:
- the requested registry instance.
-
setUserRealm
public void setUserRealm(org.wso2.carbon.user.api.UserRealm userRealm)
-
getOSGiService
@Deprecated public Object getOSGiService(Class clazz)
Deprecated.please usegetOSGiService(Class, java.util.Hashtable)insteadObtain the first OSGi service found for interface or classclazz- Overrides:
getOSGiServicein classCarbonContext- Parameters:
clazz- The type of the OSGi service- Returns:
- The OSGi service
-
getOSGiServices
@Deprecated public List<Object> getOSGiServices(Class clazz)
Deprecated.please usegetOSGiServices(Class, java.util.Hashtable)insteadObtain the OSGi services found for interface or classclazz- Overrides:
getOSGiServicesin classCarbonContext- Parameters:
clazz- The type of the OSGi service- Returns:
- The List of OSGi services
-
getOSGiService
public Object getOSGiService(Class clazz, Hashtable<String,String> props)
Obtain the first OSGi service found for interface or classclazzand props- Overrides:
getOSGiServicein classCarbonContext- Parameters:
props- attribute list that filter the serviceclazz- 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 classclazzand props- Overrides:
getOSGiServicesin classCarbonContext- Parameters:
props- attribute list that filter the service listclazz- The type of the OSGi service- Returns:
- The List of OSGi services
-
setApplicationName
public void setApplicationName(String applicationName)
-
-