Search in sources :

Example 41 with Tenant

use of org.wso2.carbon.user.api.Tenant in project carbon-apimgt by wso2.

the class APIUtil method getFaultSequenceName.

public static String getFaultSequenceName(API api) throws APIManagementException {
    if (APIUtil.isSequenceDefined(api.getFaultSequence())) {
        String tenantDomain = org.wso2.carbon.utils.multitenancy.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
        if (api.getId().getProviderName().contains("-AT-")) {
            String provider = api.getId().getProviderName().replace("-AT-", "@");
            tenantDomain = MultitenantUtils.getTenantDomain(provider);
        }
        int tenantId;
        try {
            tenantId = ServiceReferenceHolder.getInstance().getRealmService().getTenantManager().getTenantId(tenantDomain);
            if (APIUtil.isPerAPISequence(api.getFaultSequence(), tenantId, api.getId(), APIConstants.API_CUSTOM_SEQUENCE_TYPE_FAULT)) {
                return APIUtil.getSequenceExtensionName(api) + APIConstants.API_CUSTOM_SEQ_FAULT_EXT;
            } else {
                return api.getFaultSequence();
            }
        } catch (UserStoreException e) {
            throw new APIManagementException("Error while retrieving tenant Id from " + api.getId().getProviderName(), e);
        } catch (APIManagementException e) {
            throw new APIManagementException("Error while checking whether sequence " + api.getFaultSequence() + " is a per API sequence.", e);
        }
    }
    return null;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) Endpoint(org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint)

Example 42 with Tenant

use of org.wso2.carbon.user.api.Tenant in project carbon-apimgt by wso2.

the class APIUtil method getFileBaseTenantConfig.

private static JsonElement getFileBaseTenantConfig() throws APIManagementException {
    try {
        byte[] localTenantConfFileData = getLocalTenantConfFileData();
        String tenantConfDataStr = new String(localTenantConfFileData, Charset.defaultCharset());
        JsonParser jsonParser = new JsonParser();
        return jsonParser.parse(tenantConfDataStr);
    } catch (IOException e) {
        throw new APIManagementException("Error while retrieving file base tenant-config", e);
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) IOException(java.io.IOException) JsonParser(com.google.gson.JsonParser)

Example 43 with Tenant

use of org.wso2.carbon.user.api.Tenant in project carbon-apimgt by wso2.

the class APIUtil method getTenantBasedStoreDomainMapping.

public static Map getTenantBasedStoreDomainMapping(String tenantDomain) throws APIManagementException {
    try {
        Registry registry = ServiceReferenceHolder.getInstance().getRegistryService().getGovernanceSystemRegistry();
        String resourcePath = APIConstants.API_DOMAIN_MAPPINGS.replace(APIConstants.API_DOMAIN_MAPPING_TENANT_ID_IDENTIFIER, tenantDomain);
        if (registry.resourceExists(resourcePath)) {
            Resource resource = registry.get(resourcePath);
            String content = new String((byte[]) resource.getContent(), Charset.defaultCharset());
            JSONParser parser = new JSONParser();
            JSONObject mappings = (JSONObject) parser.parse(content);
            if (mappings.containsKey(APIConstants.API_DOMAIN_MAPPINGS_STORE)) {
                return (Map) mappings.get(APIConstants.API_DOMAIN_MAPPINGS_STORE);
            }
        }
    } catch (RegistryException e) {
        String msg = "Error while retrieving gateway domain mappings from registry";
        throw new APIManagementException(msg, e);
    } catch (ClassCastException e) {
        String msg = "Invalid JSON found in the gateway tenant domain mappings";
        throw new APIManagementException(msg, e);
    } catch (ParseException e) {
        String msg = "Malformed JSON found in the gateway tenant domain mappings";
        throw new APIManagementException(msg, e);
    }
    return null;
}
Also used : JSONObject(org.json.simple.JSONObject) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Resource(org.wso2.carbon.registry.core.Resource) APIProductResource(org.wso2.carbon.apimgt.api.model.APIProductResource) APIResource(org.wso2.carbon.apimgt.api.doc.model.APIResource) JSONParser(org.json.simple.parser.JSONParser) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) Registry(org.wso2.carbon.registry.core.Registry) ParseException(org.json.simple.parser.ParseException) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) EnumMap(java.util.EnumMap) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException)

Example 44 with Tenant

use of org.wso2.carbon.user.api.Tenant in project carbon-apimgt by wso2.

the class APIUtil method getOAuthConfigurationFromAPIMConfig.

/**
 * This method is used to get the authorization configurations from the api manager configurations
 *
 * @param property The configuration to get from api-manager.xml
 * @return The configuration read from api-manager.xml or else null
 * @throws APIManagementException Throws if the registry resource doesn't exist
 *                                or the content cannot be parsed to JSON
 */
public static String getOAuthConfigurationFromAPIMConfig(String property) throws APIManagementException {
    // If tenant registry doesn't have the configuration, then read it from api-manager.xml
    APIManagerConfiguration apimConfig = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();
    String oAuthConfiguration = apimConfig.getFirstProperty(APIConstants.OAUTH_CONFIGS + property);
    if (!StringUtils.isBlank(oAuthConfiguration)) {
        return oAuthConfiguration;
    }
    return null;
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration)

Example 45 with Tenant

use of org.wso2.carbon.user.api.Tenant in project carbon-apimgt by wso2.

the class SystemScopeUtils method loadTenantConfigBlockingMode.

/**
 * load tenant axis configurations.
 *
 * @param tenantDomain
 */
public static void loadTenantConfigBlockingMode(String tenantDomain) {
    try {
        ConfigurationContext ctx = ServiceReferenceHolder.getContextService().getServerConfigContext();
        TenantAxisUtils.getTenantAxisConfiguration(tenantDomain, ctx);
    } catch (Exception e) {
        log.error("Error while creating axis configuration for tenant " + tenantDomain, e);
    }
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) UserStoreException(org.wso2.carbon.user.api.UserStoreException) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)180 UserStoreException (org.wso2.carbon.user.api.UserStoreException)88 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)83 ArrayList (java.util.ArrayList)79 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)70 PreparedStatement (java.sql.PreparedStatement)51 SQLException (java.sql.SQLException)50 IOException (java.io.IOException)49 Connection (java.sql.Connection)49 HashMap (java.util.HashMap)44 ResultSet (java.sql.ResultSet)43 JSONObject (org.json.simple.JSONObject)41 Resource (org.wso2.carbon.registry.core.Resource)40 Registry (org.wso2.carbon.registry.core.Registry)38 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)34 API (org.wso2.carbon.apimgt.api.model.API)34 Test (org.junit.Test)33 File (java.io.File)32 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)32 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)30