use of org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException in project carbon-apimgt by wso2.
the class AbstractKeyValidationHandler method validate.
private APIKeyValidationInfoDTO validate(APIKeyValidationInfoDTO infoDTO, String apiTenantDomain, int tenantId, SubscriptionDataStore datastore, API api, ApplicationKeyMapping key, Application app, Subscription sub, String keyManager) {
String subscriptionStatus = sub.getSubscriptionState();
String type = key.getKeyType();
if (APIConstants.SubscriptionStatus.BLOCKED.equals(subscriptionStatus)) {
infoDTO.setValidationStatus(APIConstants.KeyValidationStatus.API_BLOCKED);
infoDTO.setAuthorized(false);
return infoDTO;
} else if (APIConstants.SubscriptionStatus.ON_HOLD.equals(subscriptionStatus) || APIConstants.SubscriptionStatus.REJECTED.equals(subscriptionStatus)) {
infoDTO.setValidationStatus(APIConstants.KeyValidationStatus.SUBSCRIPTION_INACTIVE);
infoDTO.setAuthorized(false);
return infoDTO;
} else if (APIConstants.SubscriptionStatus.PROD_ONLY_BLOCKED.equals(subscriptionStatus) && !APIConstants.API_KEY_TYPE_SANDBOX.equals(type)) {
infoDTO.setValidationStatus(APIConstants.KeyValidationStatus.API_BLOCKED);
infoDTO.setType(type);
infoDTO.setAuthorized(false);
return infoDTO;
}
infoDTO.setTier(sub.getPolicyId());
infoDTO.setSubscriber(app.getSubName());
infoDTO.setApplicationId(app.getId().toString());
infoDTO.setApiName(api.getApiName());
infoDTO.setApiVersion(api.getApiVersion());
infoDTO.setApiPublisher(api.getApiProvider());
infoDTO.setApplicationName(app.getName());
infoDTO.setApplicationTier(app.getPolicy());
infoDTO.setApplicationUUID(app.getUUID());
infoDTO.setAppAttributes(app.getAttributes());
infoDTO.setType(type);
// Advanced Level Throttling Related Properties
String apiTier = api.getApiTier();
String subscriberTenant = MultitenantUtils.getTenantDomain(app.getSubName());
ApplicationPolicy appPolicy = datastore.getApplicationPolicyByName(app.getPolicy(), APIUtil.getTenantIdFromTenantDomain(app.getOrganization()));
if (appPolicy == null) {
try {
appPolicy = new SubscriptionDataLoaderImpl().getApplicationPolicy(app.getPolicy(), app.getOrganization());
datastore.addOrUpdateApplicationPolicy(appPolicy);
} catch (DataLoadingException e) {
log.error("Error while loading ApplicationPolicy");
}
}
SubscriptionPolicy subPolicy = datastore.getSubscriptionPolicyByName(sub.getPolicyId(), tenantId);
if (subPolicy == null) {
try {
subPolicy = new SubscriptionDataLoaderImpl().getSubscriptionPolicy(sub.getPolicyId(), apiTenantDomain);
datastore.addOrUpdateSubscriptionPolicy(subPolicy);
} catch (DataLoadingException e) {
log.error("Error while loading SubscriptionPolicy");
}
}
ApiPolicy apiPolicy = datastore.getApiPolicyByName(api.getApiTier(), tenantId);
boolean isContentAware = false;
if (appPolicy.isContentAware() || subPolicy.isContentAware() || (apiPolicy != null && apiPolicy.isContentAware())) {
isContentAware = true;
}
infoDTO.setContentAware(isContentAware);
// TODO this must implement as a part of throttling implementation.
int spikeArrest = 0;
String apiLevelThrottlingKey = "api_level_throttling_key";
if (subPolicy.getRateLimitCount() > 0) {
spikeArrest = subPolicy.getRateLimitCount();
}
String spikeArrestUnit = null;
if (subPolicy.getRateLimitTimeUnit() != null) {
spikeArrestUnit = subPolicy.getRateLimitTimeUnit();
}
boolean stopOnQuotaReach = subPolicy.isStopOnQuotaReach();
int graphQLMaxDepth = 0;
if (subPolicy.getGraphQLMaxDepth() > 0) {
graphQLMaxDepth = subPolicy.getGraphQLMaxDepth();
}
int graphQLMaxComplexity = 0;
if (subPolicy.getGraphQLMaxComplexity() > 0) {
graphQLMaxComplexity = subPolicy.getGraphQLMaxComplexity();
}
List<String> list = new ArrayList<String>();
list.add(apiLevelThrottlingKey);
infoDTO.setSpikeArrestLimit(spikeArrest);
infoDTO.setSpikeArrestUnit(spikeArrestUnit);
infoDTO.setStopOnQuotaReach(stopOnQuotaReach);
infoDTO.setSubscriberTenantDomain(subscriberTenant);
infoDTO.setGraphQLMaxDepth(graphQLMaxDepth);
infoDTO.setGraphQLMaxComplexity(graphQLMaxComplexity);
if (apiTier != null && apiTier.trim().length() > 0) {
infoDTO.setApiTier(apiTier);
}
// We also need to set throttling data list associated with given API. This need to have
// policy id and
// condition id list for all throttling tiers associated with this API.
infoDTO.setThrottlingDataList(list);
infoDTO.setAuthorized(true);
return infoDTO;
}
use of org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException in project carbon-apimgt by wso2.
the class SubscriptionDataStoreImpl method addOrUpdateAPIWithUrlTemplates.
@Override
public void addOrUpdateAPIWithUrlTemplates(API api) {
try {
API newAPI = new SubscriptionDataLoaderImpl().getApi(api.getContext(), api.getApiVersion());
if (newAPI != null) {
apiMap.put(api.getCacheKey(), newAPI);
String key = newAPI.getApiName().concat(":").concat(newAPI.getApiVersion());
apiNameVersionMap.put(key, newAPI);
apiByUUIDMap.put(newAPI.getUuid(), newAPI);
}
} catch (DataLoadingException e) {
log.error("Exception while loading api for " + api.getContext() + " " + api.getApiVersion(), e);
}
}
use of org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException in project carbon-apimgt by wso2.
the class SubscriptionDataStoreImpl method getApplicationById.
@Override
public Application getApplicationById(int appId) {
String synchronizeKey = "SubscriptionDataStoreImpl-Application-" + appId;
Application application = applicationMap.get(appId);
if (application == null) {
synchronized (synchronizeKey.intern()) {
application = applicationMap.get(appId);
if (application != null) {
return application;
}
}
try {
application = new SubscriptionDataLoaderImpl().getApplicationById(appId);
} catch (DataLoadingException e) {
log.error("Error while Retrieving Application Metadata From Internal API.", e);
}
if (application != null && application.getId() != null && application.getId() != 0) {
// load to the memory
log.debug("Loading Application to the in-memory datastore. applicationId = " + application.getId());
addOrUpdateApplication(application);
} else {
log.debug("Application not found. applicationId = " + appId);
}
}
if (log.isDebugEnabled()) {
log.debug("Retrieving Application information with Application Id : " + appId);
if (application != null) {
log.debug("Retrieved Application :" + application.toString());
} else {
log.debug("Retrieved Application information with Application Id : " + appId + " is empty");
}
}
return application;
}
use of org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException in project carbon-apimgt by wso2.
the class SubscriptionDataStoreImpl method getApiByContextAndVersion.
@Override
public API getApiByContextAndVersion(String context, String version) {
String key = context + DELEM_PERIOD + version;
String synchronizeKey = "SubscriptionDataStoreImpl-API-" + key;
API api = apiMap.get(key);
if (api == null) {
synchronized (synchronizeKey.intern()) {
api = apiMap.get(key);
if (api != null) {
return api;
}
try {
api = new SubscriptionDataLoaderImpl().getApi(context, version);
} catch (DataLoadingException e) {
log.error("Error while Retrieving Data From Internal Rest API", e);
}
if (api != null && api.getApiId() != 0) {
// load to the memory
log.debug("Loading API to the in-memory datastore.");
addOrUpdateAPI(api);
}
}
}
if (log.isDebugEnabled()) {
log.debug("Retrieving API information with Context " + context + " and Version : " + version);
if (api != null) {
log.debug("Retrieved API information with Context : " + context + " and Version : " + version + " is" + " " + api.toString());
} else {
log.debug("Retrieved API information with Context : " + context + " and Version : " + version + " is" + " empty");
}
}
return api;
}
use of org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException in project carbon-apimgt by wso2.
the class WebSocketAnalyticsDataProvider method getApi.
@Override
public API getApi() {
String apiContext = (String) WebSocketUtils.getPropertyFromChannel(RESTConstants.REST_API_CONTEXT, ctx);
String apiVersion = (String) WebSocketUtils.getPropertyFromChannel(RESTConstants.SYNAPSE_REST_API_VERSION, ctx);
String tenantDomain = MultitenantUtils.getTenantDomainFromRequestURL(apiContext);
if (tenantDomain == null) {
tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
}
SubscriptionDataStore store = SubscriptionDataHolder.getInstance().getTenantSubscriptionStore(tenantDomain);
org.wso2.carbon.apimgt.keymgt.model.entity.API apiObj = store.getApiByContextAndVersion(apiContext, apiVersion);
API api = new API();
if (apiObj == null) {
try {
apiObj = new SubscriptionDataLoaderImpl().getApi(apiContext, apiVersion);
} catch (DataLoadingException e) {
log.error("Error occurred when getting api.", e);
throw new RuntimeException("Error occurred when getting API information", e);
}
}
if (apiObj != null) {
api.setApiId(apiObj.getUuid());
api.setApiType(apiObj.getApiType());
api.setApiName(apiObj.getApiName());
api.setApiVersion(apiObj.getApiVersion());
api.setApiCreator(apiObj.getApiProvider());
api.setApiCreatorTenantDomain(MultitenantUtils.getTenantDomain(api.getApiCreator()));
}
return api;
}
Aggregations