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 Details

    • 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:
    • endTenantFlow

      public static void endTenantFlow()
      This will end the tenant flow and restore the previous CarbonContext.
      See Also:
    • 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.
    • setUserResidentOrganizationId

      public void setUserResidentOrganizationId(String userResidentOrganizationId)
      Method to set the user resident organization ID on this CarbonContext instance.
      Parameters:
      userResidentOrganizationId - The user's resident 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

      @Deprecated public Object getOSGiService(Class clazz)
      Deprecated.
      Obtain the first OSGi service found for interface or class clazz
      Overrides:
      getOSGiService in class CarbonContext
      Parameters:
      clazz - The type of the OSGi service
      Returns:
      The OSGi service
    • getOSGiServices

      @Deprecated public List<Object> getOSGiServices(Class clazz)
      Deprecated.
      Obtain the OSGi services found for interface or class clazz
      Overrides:
      getOSGiServices in class CarbonContext
      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 class clazz and props
      Overrides:
      getOSGiService in class CarbonContext
      Parameters:
      clazz - The type of the OSGi service
      props - attribute list that filter the 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:
      clazz - The type of the OSGi service
      props - attribute list that filter the service list
      Returns:
      The List of OSGi services
    • setApplicationName

      public void setApplicationName(String applicationName)
    • setApplicationResidentOrganizationId

      public void setApplicationResidentOrganizationId(String applicationResidentOrgId)
      Set the organization id of the organization where the application is resident when the request comes in tenant perspective.
      Parameters:
      applicationResidentOrgId - Organization id of the organization where the application is resident.
    • getApplicationResidentOrganizationId

      public String getApplicationResidentOrganizationId()
      Get the organization id of the organization where the application resides. This will be set when the request comes in tenant perspective.
      Returns:
      Organization id of the organization where the application resides.
    • setOperationScopeValidationContext

      public void setOperationScopeValidationContext(OperationScopeValidationContext operationScopeValidationContext)
      Set the operation scope validation context.
      Parameters:
      operationScopeValidationContext - Operation scope validation context.
    • getOperationScopeValidationContext

      public OperationScopeValidationContext getOperationScopeValidationContext()
      Get the operation scope validation context.
      Returns:
      Operation scope validation context.
    • setAccessingOrganizationId

      public void setAccessingOrganizationId(String accessingOrganizationId)
      Set the accessing organization id.
      Parameters:
      accessingOrganizationId - Accessing organization id.
    • getAccessingOrganizationId

      public String getAccessingOrganizationId()
      Get the accessing organization id. This represents the organization id of the accessing organization of the current request.
      Returns:
      Accessing organization id.