org.wso2.carbon.core.multitenancy.utils.TenantAxisUtils Java Examples

The following examples show how to use org.wso2.carbon.core.multitenancy.utils.TenantAxisUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: APISynchronizer.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * Method to load the configurations of a tenant
 */
private void loadTenant(String username) {
    String tenantDomain = MultitenantUtils.getTenantDomain(username);
    PrivilegedCarbonContext.startTenantFlow();
    PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
    PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(username);
    if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
        ConfigurationContext context = ServiceDataHolder.getInstance().getConfigurationContextService()
                .getServerConfigContext();
        TenantAxisUtils.getTenantAxisConfiguration(tenantDomain, context);
        if (log.isDebugEnabled()) {
            log.debug("Tenant was loaded into Carbon Context. Tenant : " + tenantDomain
                    + ", Username : " + username);
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Skipping loading super tenant space since execution is currently in super tenant flow.");
        }
    }
}
 
Example #2
Source File: ServerStartupListener.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * Method to load the configurations of a tenant
 */
private static void loadTenant(String username) throws IOException {
    String tenantDomain;
    APIManagerConfiguration config = ServiceDataHolder.getInstance().
            getAPIManagerConfigurationService().getAPIManagerConfiguration();
    tenantDomain = MultitenantUtils.getTenantDomain(username);
    if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
        try {
            PrivilegedCarbonContext.startTenantFlow();
            PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
            carbonContext.setTenantDomain(tenantDomain);
            carbonContext.setUsername(MultitenantUtils.getTenantAwareUsername(username));
            ConfigurationContext context =
                    ServiceDataHolder.getInstance().getConfigurationContextService().getServerConfigContext();
            // load tenant configuration
            TenantAxisUtils.getTenantAxisConfiguration(tenantDomain, context);
            log.info("Successfully loaded tenant with tenant domain : " + tenantDomain);
        } finally {
            PrivilegedCarbonContext.endTenantFlow();
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Skipping loading super tenant space since execution is currently in super tenant flow.");
        }
    }
}
 
Example #3
Source File: ThrottlingSynchronizer.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
private void loadTenant(String username) {
    String tenantDomain = MultitenantUtils.getTenantDomain(username);
    PrivilegedCarbonContext.startTenantFlow();
    PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
    PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(username);
    if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
        ConfigurationContext context = ServiceReferenceHolder.getInstance()
                .getConfigContextService().getServerConfigContext();
        TenantAxisUtils.getTenantAxisConfiguration(tenantDomain, context);
        if (log.isDebugEnabled()) {
            log.debug("Tenant was loaded into Carbon Context. Tenant : " + tenantDomain
                    + ", Username : " + username);
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Skipping loading super tenant space since execution is currently in super tenant flow.");
        }
    }
}
 
Example #4
Source File: WSDL2FormGenerator.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
private AxisService getAxisService(String url, String serviceContextRoot,
                                   ConfigurationContext configCtx) throws AxisFault {
    String service =
            url.substring(url.indexOf(serviceContextRoot) + serviceContextRoot.length(),
                    url.indexOf("?"));
    AxisConfiguration axisConfig = configCtx.getAxisConfiguration();
    AxisService axisService = axisConfig.getServiceForActivation(service);
    if (axisService == null) {
        // Try to see whether the service is available in a tenant
        axisService = TenantAxisUtils.getAxisService(url, configCtx);
        axisConfig = TenantAxisUtils.getTenantAxisConfiguration(TenantAxisUtils
                .getTenantDomain(url), configCtx);
    }
    if (GhostDeployerUtils.isGhostService(axisService) && axisConfig != null) {
        // if the existing service is a ghost service, deploy the actual one
        axisService = GhostDeployerUtils.deployActualService(axisConfig, axisService);
    }
    return axisService;
}
 
Example #5
Source File: AbstractApi.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
protected ConfigurationContext getConfigContext() {

        // If a tenant has been set, then try to get the ConfigurationContext of that tenant
        PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
        ConfigurationContextService configurationContextService =
                (ConfigurationContextService) carbonContext.getOSGiService(ConfigurationContextService.class);
        ConfigurationContext mainConfigContext = configurationContextService.getServerConfigContext();
        String domain = carbonContext.getTenantDomain();
        if (domain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(domain)) {
            return TenantAxisUtils.getTenantConfigurationContext(domain, mainConfigContext);
        } else if (carbonContext.getTenantId() == MultitenantConstants.SUPER_TENANT_ID) {
            return mainConfigContext;
        } else {
            throw new UnsupportedOperationException("Tenant domain unidentified. " +
                    "Upstream code needs to identify & set the tenant domain & tenant ID. " +
                    " The TenantDomain SOAP header could be set by the clients or " +
                    "tenant authentication should be carried out.");
        }
    }
 
Example #6
Source File: ServiceUtils.java    From product-private-paas with Apache License 2.0 6 votes vote down vote up
private static ConfigurationContext getConfigContext() {

        // If a tenant has been set, then try to get the ConfigurationContext of that tenant
        PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
        ConfigurationContextService configurationContextService = (ConfigurationContextService) carbonContext
                .getOSGiService(ConfigurationContextService.class);
        ConfigurationContext mainConfigContext = configurationContextService.getServerConfigContext();
        String domain = carbonContext.getTenantDomain();
        if (domain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(domain)) {
            return TenantAxisUtils.getTenantConfigurationContext(domain, mainConfigContext);
        } else if (carbonContext.getTenantId() == MultitenantConstants.SUPER_TENANT_ID) {
            return mainConfigContext;
        } else {
            throw new UnsupportedOperationException("Tenant domain unidentified. " +
                    "Upstream code needs to identify & set the tenant domain & tenant ID. " +
                    " The TenantDomain SOAP header could be set by the clients or " +
                    "tenant authentication should be carried out.");
        }
    }
 
Example #7
Source File: AbstractAdmin.java    From product-private-paas with Apache License 2.0 6 votes vote down vote up
protected ConfigurationContext getConfigContext() {

        // If a tenant has been set, then try to get the ConfigurationContext of that tenant
        PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
        ConfigurationContextService configurationContextService = (ConfigurationContextService) carbonContext
                .getOSGiService(ConfigurationContextService.class);
        ConfigurationContext mainConfigContext = configurationContextService.getServerConfigContext();
        String domain = carbonContext.getTenantDomain();
        if (domain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(domain)) {
            return TenantAxisUtils.getTenantConfigurationContext(domain, mainConfigContext);
        } else if (carbonContext.getTenantId() == MultitenantConstants.SUPER_TENANT_ID) {
            return mainConfigContext;
        } else {
            throw new UnsupportedOperationException("Tenant domain unidentified. " +
                    "Upstream code needs to identify & set the tenant domain & tenant ID. " +
                    " The TenantDomain SOAP header could be set by the clients or " +
                    "tenant authentication should be carried out.");
        }
    }
 
Example #8
Source File: APISynchronizerTest.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
public void mockCommonCases() throws UserStoreException {
    PrivilegedCarbonContext privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class);
    PowerMockito.mockStatic(PrivilegedCarbonContext.class);
    PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext);
    PowerMockito.mockStatic(TenantAxisUtils.class);

    String carbonConfigPath = System.getProperty(Constants.CARBON_HOME) + Constants.CARBON_CONFIGS_PATH;
    String tenantDirPath = System.getProperty(Constants.CARBON_HOME) + Constants.CARBON_TENANT_CONFIGS_PATH;
    PowerMockito.mockStatic(CarbonUtils.class);
    PowerMockito.when(CarbonUtils.getCarbonTenantsDirPath()).thenReturn(tenantDirPath);
    PowerMockito.when(CarbonUtils.getCarbonConfigDirPath()).thenReturn(carbonConfigPath);

    PowerMockito.mockStatic(TokenUtil.class);
    PowerMockito.mockStatic(APIMappingUtil.class);
    Mockito.mock(OnPremiseGatewayDAO.class);

    PowerMockito.mockStatic(RealmService.class);
    RealmService realmService = Mockito.mock(RealmService.class);
    TenantManager tenantManager = Mockito.mock(TenantManager.class);
    ServiceDataHolder serviceDataHolder = Mockito.mock(ServiceDataHolder.class);

    PowerMockito.mockStatic(ServiceDataHolder.class);
    PowerMockito.when(ServiceDataHolder.getInstance()).thenReturn(serviceDataHolder);
    PowerMockito.when(serviceDataHolder.getRealmService()).thenReturn(realmService);
    PowerMockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
    PowerMockito.when(tenantManager.getTenantId(any(String.class))).thenReturn(1);

    ConfigurationContextService contextService = Mockito.mock(ConfigurationContextService.class);
    ConfigurationContext context = Mockito.mock(ConfigurationContext.class);
    PowerMockito.when(serviceDataHolder.getConfigurationContextService()).thenReturn(contextService);
    PowerMockito.when(contextService.getServerConfigContext()).thenReturn(context);

    Properties properties = Mockito.mock(Properties.class);
    Mockito.when(properties.getProperty(Constants.API_PUBLISHER_URL_PROPERTY))
            .thenReturn(Constants.DEFAULT_API_PUBLISHER_URL);
    Mockito.when(properties.getProperty(Constants.DEFAULT_API_UPDATE_URL_PROPERTY))
            .thenReturn(Constants.DEFAULT_API_UPDATE_SERVICE_URL);
    APIManagerConfigurationService apimConfigService = Mockito.mock(APIManagerConfigurationService.class);
    APIManagerConfiguration apimConfig = Mockito.mock(APIManagerConfiguration.class);
    PowerMockito.when(ServiceDataHolder.getInstance()).thenReturn(serviceDataHolder);
    Mockito.when(serviceDataHolder.getAPIManagerConfigurationService()).thenReturn(apimConfigService);
    Mockito.when(apimConfigService.getAPIManagerConfiguration()).thenReturn(apimConfig);
    Mockito.when(apimConfig.getFirstProperty(Constants.KEY_VALIDATOR_USERNAME))
            .thenReturn(Constants.USERNAME);
    Mockito.when(apimConfig.getFirstProperty(Constants.KEY_VALIDATOR_PASSWORD))
            .thenReturn(Constants.PASSWORD);
}