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;
}
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);
}
}
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;
}
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;
}
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);
}
}
Aggregations