use of org.wso2.carbon.apimgt.api.model.subscription.ApplicationKeyMapping in project carbon-apimgt by wso2.
the class SubscriptionValidationDataUtil method fromApplicationKeyMappingToApplicationKeyMappingListDTO.
public static ApplicationKeyMappingListDTO fromApplicationKeyMappingToApplicationKeyMappingListDTO(List<ApplicationKeyMapping> model) {
ApplicationKeyMappingListDTO applicationKeyMappingListDTO = new ApplicationKeyMappingListDTO();
if (model != null) {
for (ApplicationKeyMapping applicationKeyMapping : model) {
ApplicationKeyMappingDTO applicationKeyMappingDTO = new ApplicationKeyMappingDTO();
applicationKeyMappingDTO.setApplicationId(applicationKeyMapping.getApplicationId());
applicationKeyMappingDTO.setConsumerKey(applicationKeyMapping.getConsumerKey());
applicationKeyMappingDTO.setKeyType(applicationKeyMapping.getKeyType());
applicationKeyMappingDTO.setKeyManager(applicationKeyMapping.getKeyManager());
applicationKeyMappingDTO.setApplicationUUID(applicationKeyMapping.getApplicationUUID());
applicationKeyMappingListDTO.getList().add(applicationKeyMappingDTO);
}
applicationKeyMappingListDTO.setCount(model.size());
} else {
applicationKeyMappingListDTO.setCount(0);
}
return applicationKeyMappingListDTO;
}
use of org.wso2.carbon.apimgt.api.model.subscription.ApplicationKeyMapping in project carbon-apimgt by wso2.
the class AbstractKeyValidationHandler method validateSubscriptionDetails.
private APIKeyValidationInfoDTO validateSubscriptionDetails(APIKeyValidationInfoDTO infoDTO, String context, String version, String consumerKey, String keyManager, boolean defaultVersionInvoked) {
String apiTenantDomain = MultitenantUtils.getTenantDomainFromRequestURL(context);
if (apiTenantDomain == null) {
apiTenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
}
int tenantId = APIUtil.getTenantIdFromTenantDomain(apiTenantDomain);
API api = null;
ApplicationKeyMapping key = null;
Application app = null;
Subscription sub = null;
SubscriptionDataStore datastore = SubscriptionDataHolder.getInstance().getTenantSubscriptionStore(apiTenantDomain);
// TODO add a check to see whether datastore is initialized an load data using rest api if it is not loaded
if (datastore != null) {
api = datastore.getApiByContextAndVersion(context, version);
if (api != null) {
key = datastore.getKeyMappingByKeyAndKeyManager(consumerKey, keyManager);
if (key != null) {
app = datastore.getApplicationById(key.getApplicationId());
if (app != null) {
sub = datastore.getSubscriptionById(app.getId(), api.getApiId());
if (sub != null) {
if (log.isDebugEnabled()) {
log.debug("All information is retrieved from the inmemory data store.");
}
} else {
if (log.isDebugEnabled()) {
log.debug("Valid subscription not found for appId " + app.getId() + " and apiId " + api.getApiId());
}
}
} else {
if (log.isDebugEnabled()) {
log.debug("Application not found in the datastore for id " + key.getApplicationId());
}
}
} else {
if (log.isDebugEnabled()) {
log.debug("Application keymapping not found in the datastore for id consumerKey " + consumerKey);
}
}
} else {
if (log.isDebugEnabled()) {
log.debug("API not found in the datastore for " + context + ":" + version);
}
}
} else {
log.error("Subscription datastore is not initialized for tenant domain " + apiTenantDomain);
}
if (api != null && app != null && key != null && sub != null) {
validate(infoDTO, apiTenantDomain, tenantId, datastore, api, key, app, sub, keyManager);
} else if (!infoDTO.isAuthorized() && infoDTO.getValidationStatus() == 0) {
// Scenario where validation failed and message is not set
infoDTO.setValidationStatus(APIConstants.KeyValidationStatus.API_AUTH_RESOURCE_FORBIDDEN);
} else {
infoDTO.setAuthorized(false);
infoDTO.setValidationStatus(APIConstants.KeyValidationStatus.API_AUTH_RESOURCE_FORBIDDEN);
}
return infoDTO;
}
use of org.wso2.carbon.apimgt.api.model.subscription.ApplicationKeyMapping in project carbon-apimgt by wso2.
the class ApplicationKeyMappingsApiServiceImpl method applicationKeyMappingsGet.
@Override
public Response applicationKeyMappingsGet(String xWSO2Tenant, String consumerKey, String keymanager, MessageContext messageContext) throws APIManagementException {
SubscriptionValidationDAO subscriptionValidationDAO = new SubscriptionValidationDAO();
xWSO2Tenant = SubscriptionValidationDataUtil.validateTenantDomain(xWSO2Tenant, messageContext);
if (StringUtils.isNotEmpty(consumerKey)) {
ApplicationKeyMapping keyMapping = subscriptionValidationDAO.getApplicationKeyMapping(consumerKey, keymanager, xWSO2Tenant);
List<ApplicationKeyMapping> applicationKeyMappings = new ArrayList<>();
if (keyMapping != null) {
applicationKeyMappings.add(keyMapping);
}
return Response.ok().entity(SubscriptionValidationDataUtil.fromApplicationKeyMappingToApplicationKeyMappingListDTO(applicationKeyMappings)).build();
}
if (StringUtils.isNotEmpty(xWSO2Tenant)) {
return Response.ok().entity(SubscriptionValidationDataUtil.fromApplicationKeyMappingToApplicationKeyMappingListDTO(subscriptionValidationDAO.getAllApplicationKeyMappings(xWSO2Tenant))).build();
}
return null;
}
use of org.wso2.carbon.apimgt.api.model.subscription.ApplicationKeyMapping in project carbon-apimgt by wso2.
the class SubscriptionDataLoaderImpl method loadAllKeyMappings.
@Override
public List<ApplicationKeyMapping> loadAllKeyMappings(String tenantDomain) throws DataLoadingException {
String applicationsEP = APIConstants.SubscriptionValidationResources.APPLICATION_KEY_MAPPINGS;
List<ApplicationKeyMapping> applicationKeyMappings = new ArrayList<>();
String responseString = null;
try {
responseString = invokeService(applicationsEP, tenantDomain);
} catch (IOException e) {
String msg = "Error while executing the http client " + applicationsEP;
log.error(msg, e);
throw new DataLoadingException(msg, e);
}
if (responseString != null && !responseString.isEmpty()) {
applicationKeyMappings = (new Gson().fromJson(responseString, ApplicationKeyMappingList.class)).getList();
}
return applicationKeyMappings;
}
use of org.wso2.carbon.apimgt.api.model.subscription.ApplicationKeyMapping in project carbon-apimgt by wso2.
the class SubscriptionDataStoreImpl method getKeyMappingByKeyAndKeyManager.
@Override
public ApplicationKeyMapping getKeyMappingByKeyAndKeyManager(String key, String keyManager) {
ApplicationKeyMappingCacheKey applicationKeyMappingCacheKey = new ApplicationKeyMappingCacheKey(key, keyManager);
String synchronizeKey = "SubscriptionDataStoreImpl-KeyMapping-" + applicationKeyMappingCacheKey;
ApplicationKeyMapping applicationKeyMapping = applicationKeyMappingMap.get(applicationKeyMappingCacheKey);
if (applicationKeyMapping == null) {
synchronized (synchronizeKey.intern()) {
applicationKeyMapping = applicationKeyMappingMap.get(applicationKeyMappingCacheKey);
if (applicationKeyMapping != null) {
return applicationKeyMapping;
}
try {
applicationKeyMapping = new SubscriptionDataLoaderImpl().getKeyMapping(key, keyManager, tenantDomain);
} catch (DataLoadingException e) {
log.error("Error while Loading KeyMapping Information from Internal API.", e);
}
if (applicationKeyMapping != null && !StringUtils.isEmpty(applicationKeyMapping.getConsumerKey())) {
// load to the memory
log.debug("Loading Keymapping to the in-memory datastore.");
addOrUpdateApplicationKeyMapping(applicationKeyMapping);
}
}
}
if (log.isDebugEnabled()) {
log.debug("Retrieving Application information with Consumer Key : " + key + " and keymanager : " + keyManager);
if (applicationKeyMapping != null) {
log.debug("Retrieved Application information with Consumer Key : " + key + " and keymanager : " + keyManager + " is " + applicationKeyMapping.toString());
} else {
log.debug("Retrieving Application information with Consumer Key : " + key + " and keymanager : " + keyManager + " is empty");
}
}
return applicationKeyMapping;
}
Aggregations