Remove unnecessary sources

pull/19/head
tcdlpds 1 year ago
parent 500fa0df98
commit ac0ba00707

@ -24,7 +24,6 @@ import io.entgra.device.mgt.core.apimgt.application.extension.api.util.Registrat
import io.entgra.device.mgt.core.apimgt.application.extension.constants.ApiApplicationConstants;
import io.entgra.device.mgt.core.apimgt.application.extension.dto.ApiApplicationKey;
import io.entgra.device.mgt.core.apimgt.application.extension.exception.APIManagerException;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.ApplicationGrantTypeUpdater;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
@ -109,18 +108,6 @@ public class ApiApplicationRegistrationServiceImpl implements ApiApplicationRegi
if (username.equals(registrationProfile.getUsername())) {
synchronized (ApiApplicationRegistrationServiceImpl.class) {
// ApplicationGrantTypeUpdater applicationGrantTypeUpdater = null;
// if (registrationProfile.getSupportedGrantTypes() != null && !registrationProfile.getSupportedGrantTypes().isEmpty()) {
// applicationGrantTypeUpdater = new ApplicationGrantTypeUpdater();
// applicationGrantTypeUpdater.setSupportedGrantTypes(registrationProfile.getSupportedGrantTypes());
//
// } else if (StringUtils.isNotEmpty(registrationProfile.getCallbackUrl())) {
// return Response.status(Response.Status.BAD_REQUEST).entity("Callback URL should be Empty when" +
// " request does not contain supported grant types to update grant types of the " +
// "application."
// ).build();
// }
ApiApplicationKey apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys(
applicationName, registrationProfile.getTags(),
ApiApplicationConstants.DEFAULT_TOKEN_TYPE, username,

@ -20,8 +20,6 @@ package io.entgra.device.mgt.core.apimgt.application.extension;
import io.entgra.device.mgt.core.apimgt.application.extension.dto.ApiApplicationKey;
import io.entgra.device.mgt.core.apimgt.application.extension.exception.APIManagerException;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.ApplicationGrantTypeUpdater;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.TokenInfo;
import io.entgra.device.mgt.core.identity.jwt.client.extension.dto.AccessTokenInfo;
import java.util.ArrayList;
@ -37,31 +35,6 @@ public interface APIManagementProviderService {
*/
boolean isTierLoaded();
// /**
// * Generate and retreive application keys. if the application does exist then
// * create it and subscribe to apis that are grouped with the tags.
// *
// * @param apiApplicationName name of the application.
// * @param tags tags of the apis that application needs to be subscribed.
// * @param keyType of the application.
// * @param username to whom the application is created
// * @param isAllowedAllDomains application is allowed to all the tenants
// * @param validityTime validity period of the application
// * @return consumerkey and secrete of the created application.
// * @throws APIManagerException
// */
// ApiApplicationKey generateAndRetrieveApplicationKeys(String apiApplicationName, String tags[],
// String keyType, String username, boolean isAllowedAllDomains,
// String validityTime) throws APIManagerException;
// ApiApplicationKey generateAndRetrieveApplicationKeys(String applicationName, String[] tags,
// String keyType, String username,
// boolean isAllowedAllDomains,
// String validityTime, String password,
// ArrayList<String> supportedGrantTypes,
// String callbackUrl,
// boolean isMappingRequired) throws APIManagerException;
ApiApplicationKey generateAndRetrieveApplicationKeys(String applicationName, String[] tags,
String keyType, String username,
boolean isAllowedAllDomains,
@ -71,11 +44,6 @@ public interface APIManagementProviderService {
String callbackUrl,
boolean isMappingRequired) throws APIManagerException;
// /**
// * Remove APIM Application.
// */
// void removeAPIApplication(String applicationName, String username) throws APIManagerException;
/**
* To get access token for given scopes and for the given validity period
* @param scopes Scopes

@ -19,13 +19,10 @@
package io.entgra.device.mgt.core.apimgt.application.extension;
import io.entgra.device.mgt.core.apimgt.application.extension.bean.APIRegistrationProfile;
import io.entgra.device.mgt.core.apimgt.application.extension.constants.ApiApplicationConstants;
import io.entgra.device.mgt.core.apimgt.application.extension.dto.ApiApplicationKey;
import io.entgra.device.mgt.core.apimgt.application.extension.exception.APIManagerException;
import io.entgra.device.mgt.core.apimgt.application.extension.internal.APIApplicationManagerExtensionDataHolder;
import io.entgra.device.mgt.core.apimgt.application.extension.util.APIManagerUtil;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.APIInfo;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.ApplicationGrantTypeUpdater;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.ApplicationKey;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.KeyManager;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Subscription;
@ -48,16 +45,7 @@ import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.Unexpected
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.apimgt.api.APIAdmin;
import org.wso2.carbon.apimgt.api.APIConsumer;
import org.wso2.carbon.apimgt.api.APIManagementException;
import org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO;
import org.wso2.carbon.apimgt.api.model.API;
import org.wso2.carbon.apimgt.api.model.APIKey;
import org.wso2.carbon.apimgt.api.model.ApiTypeWrapper;
import org.wso2.carbon.apimgt.api.model.SubscribedAPI;
import org.wso2.carbon.apimgt.api.model.Subscriber;
import org.wso2.carbon.apimgt.impl.APIAdminImpl;
import org.wso2.carbon.apimgt.impl.APIConstants;
import org.wso2.carbon.apimgt.impl.APIManagerFactory;
import org.wso2.carbon.apimgt.impl.utils.APIUtil;
@ -65,8 +53,13 @@ import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import java.util.*;
import java.util.stream.Collectors;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
/**
* This class represents an implementation of APIManagementProviderService.
@ -92,54 +85,6 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
return false;
}
// @Override
// public void removeAPIApplication(String applicationName, String username) throws APIManagerException {
//
// try {
// APIConsumer apiConsumer = API_MANAGER_FACTORY.getAPIConsumer(username);
// Application application = null; // todo:apim - apiConsumer.getApplicationsByName(username, applicationName, "");
//// curl -k -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" "https://localhost:9443/api/am/devportal/v3/applications?query=CalculatorApp"
// if (application != null) {
// // todo:apim - apiConsumer.removeApplication(application, username);
// //curl -k -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" -X DELETE "https://localhost:9443/api/am/devportal/v3/applications/896658a0-b4ee-4535-bbfa-806c894a4015"
// }
// } catch (APIManagementException e) {
// throw new APIManagerException("Failed to remove api application : " + applicationName, e);
// }
//
//
// }
// @Override
// public synchronized ApiApplicationKey generateAndRetrieveApplicationKeys(String applicationName, String[] tags,
// String keyType,
// boolean isAllowedAllDomains,
// String validityTime, String accessToken) throws APIManagerException {
// TokenInfo tokenInfo = new TokenInfo();
// tokenInfo.setApiApplicationInfo(null);
// tokenInfo.setAccessToken(accessToken);
// return generateAndRetrieveApplicationKeys(applicationName, tags, keyType, isAllowedAllDomains, validityTime,
// tokenInfo, null, false);
// }
// @Override
// public synchronized ApiApplicationKey generateAndRetrieveApplicationKeys(String applicationName, String[] tags,
// String keyType, String username,
// boolean isAllowedAllDomains,
// String validityTime, String password,
// ArrayList<String> supportedGrantTypes,
// String callbackUrl,
// boolean isMappingRequired)
// throws APIManagerException {
//
// ApiApplicationInfo applicationInfo = getApplicationInfo(username, password);
// TokenInfo tokenInfo = new TokenInfo();
// tokenInfo.setApiApplicationInfo(applicationInfo);
// tokenInfo.setAccessToken(null);
// return generateAndRetrieveApplicationKeys(applicationName, tags, keyType, isAllowedAllDomains, validityTime,
// tokenInfo, supportedGrantTypes, callbackUrl, isMappingRequired);
// }
@Override
public synchronized ApiApplicationKey generateAndRetrieveApplicationKeys(String applicationName, String[] tags,
String keyType, String username,
@ -287,19 +232,11 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
applicationKey = consumerRESTAPIServices.generateApplicationKeys(tokenInfo, application.getApplicationId(),
keyManager.getName(), validityTime, keyType);
}
// ApplicationKey updateGrantType(TokenInfo tokenInfo, String applicationId, String keyMapId, String keyManager,
// String supportedGrantTypes, String callbackUrl)
if (supportedGrantTypes != null || StringUtils.isNotEmpty(callbackUrl)) {
applicationKey = consumerRESTAPIServices.updateGrantType(tokenInfo, application.getApplicationId(),
applicationKey.getKeyMappingId(), keyManager.getName(), supportedGrantTypes, callbackUrl);
}
// ApplicationKey applicationKey = consumerRESTAPIServices.mapApplicationKeys(tokenInfo, application,
// keyManager.getName(), keyType);
// ApplicationKey applicationKey = consumerRESTAPIServices.generateApplicationKeys(tokenInfo, application.getApplicationId(),
// keyManager.getName(), validityTime, keyType);
ApiApplicationKey apiApplicationKey = new ApiApplicationKey();
apiApplicationKey.setConsumerKey(applicationKey.getConsumerKey());
apiApplicationKey.setConsumerSecret(applicationKey.getConsumerSecret());
@ -368,235 +305,6 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
consumerRESTAPIServices.createSubscriptions(tokenInfo, subscriptionList);
}
// /**
// * {@inheritDoc}
// */
// @Override
// public synchronized ApiApplicationKey generateAndRetrieveApplicationKeys(String applicationName, String tags[],
// String keyType, String username, boolean isAllowedAllDomains, String validityTime)
// throws APIManagerException {
//
//
///*
//
//todo - Modify generateAndRetrieveApplicationKeys
//
//Check the existence of the API application.
//
//if Application is not exists
// Create the Application
//
//If super tenants
// Get set of tagged APIs
//If the tenant domain is not super tenant
// Get set of tagged APIs from super tenant space
//
//If new Application
// Subscribed to tagged APIs
//Else
// Get all subscribed APIs of application
// Filter out APIs and subscribed to APIs which can be subscribed
// Filter -> Use set of tagged APis
// Remove already subscribed APIs from the set
// Subscribed to remaining APIs
//
//Get Application keys from application
// If API keys are there return API keys
//
//Otherwise, Generate Application Keys and return them
//
// */
//
// String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
// if (StringUtils.isEmpty(username)) {
// username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername() + "@" + tenantDomain;
// }
// try {
// APIConsumer apiConsumer = API_MANAGER_FACTORY.getAPIConsumer(username);
// Application application = null; // todo:resolve:apim - apiConsumer.getApplicationsByName(username, applicationName, "");
// int applicationId = 0;
// Subscriber subscriber = null;
// if (application == null) {
// subscriber = null; // todo:resolve:apim - apiConsumer.getSubscriber(username);
// if (subscriber == null) {
// // create subscriber
// // todo:resolve:apim - apiConsumer.addSubscriber(username, "");
// subscriber = null; // todo:resolve:apim - apiConsumer.getSubscriber(username);
// }
// //create application
// application = new Application(applicationName, subscriber);
// application.setTier(ApiApplicationConstants.DEFAULT_TIER);
// application.setGroupId("");
// application.setTokenType("OAUTH");
// // todo:resolve:apim - apiConsumer.addApplication(application, username);
// application = null; // todo:resolve:apim - apiConsumer.getApplicationsByName(username, applicationName, "");
// } else {
// subscriber = null; // todo:resolve:apim - apiConsumer.getSubscriber(username);
// }
//
// Set<SubscribedAPI> subscribedAPIs =
// null; // todo:resolve:apim - apiConsumer.getSubscribedAPIs(subscriber, applicationName, "");
//
// log.info("Already subscribed API count: " + subscribedAPIs.size());
//
// // subscribe to apis.
// APIConsumer apiConsumerAPIPublishedTenant = apiConsumer;
// if (tags != null && tags.length > 0) {
// for (String tag : tags) {
// boolean startedTenantFlow = false;
// Set<API> apisWithTag = null; // todo:resolve:apim - apiConsumer.getAPIsWithTag(tag, tenantDomain);
//
// /**
// * From APIM 4.0.0, APIs published in the super tenant can only be listed by
// * APIConsumer, only if the APIConsumer belongs to the super tenant. So we
// * are starting tenant flow if we are not already in super tenant(child
// * tenant starting to create OAuth app).
// */
// if (apisWithTag == null || apisWithTag.size() == 0) {
// PrivilegedCarbonContext.startTenantFlow();
// PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME,
// true);
//
// try {
// String superAdminUsername = PrivilegedCarbonContext
// .getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration().getAdminUserName();
// apiConsumerAPIPublishedTenant = API_MANAGER_FACTORY.getAPIConsumer(superAdminUsername);
// } catch (UserStoreException e) {
// throw new APIManagerException("Failed to create api application for " +
// "tenant: " + tenantDomain +
// ". Caused by to inability to get super tenant username", e);
// }
//
// apisWithTag = null; // todo:resolve:apim - apiConsumerAPIPublishedTenant.getAPIsWithTag(tag, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
// startedTenantFlow = true;
// }
//
// Set<ApiTypeWrapper> apiTypeWrapperList = new HashSet<>();
// if (apisWithTag != null && apisWithTag.size() > 0) {
// Set<String> tempApiIds = new HashSet<>();
// for (API apiInfo : apisWithTag) {
// String id = apiInfo.getId().getProviderName().replace("@", "-AT-")
// + "-" + apiInfo.getId().getName() + "-" + apiInfo.getId().getVersion();
// boolean subscriptionExist = false;
// if (subscribedAPIs.size() > 0) {
// for (SubscribedAPI subscribedAPI : subscribedAPIs) {
// // todo:resolve:apim
//// if (String.valueOf(subscribedAPI.getApiId().toString()).equals(id)) {
//// subscriptionExist = true;
//// break;
//// }
// }
// }
// if (!subscriptionExist && !tempApiIds.contains(id)) {
// ApiTypeWrapper apiTypeWrapper;
// if (startedTenantFlow) {
// /**
// * This mean APIs were not found in the child tenant, so all
// * calls to get info about APIs need to be to super tenant.
// */
// apiTypeWrapper = apiConsumerAPIPublishedTenant.getAPIorAPIProductByUUID(
// apiInfo.getUuid(), MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
// } else {
// /**
// * Ideally, in all usecases of IoT server, tenant domain here
// * will be carbon.super. This block is kept to make sure in
// * the future, if there are some APIs published to a specific
// * tenant only.
// */
// apiTypeWrapper = apiConsumerAPIPublishedTenant.getAPIorAPIProductByUUID(
// apiInfo.getUuid(), tenantDomain);
// }
// apiTypeWrapper.setTier(ApiApplicationConstants.DEFAULT_TIER);
// apiTypeWrapperList.add(apiTypeWrapper);
// tempApiIds.add(id);
// }
// }
// if (startedTenantFlow) {
// PrivilegedCarbonContext.endTenantFlow();
// }
//
// /** This is done in a redundant loop instead of doing in the same loop
// * that populates apiTypeWrapperList because in a tenanted scenario,
// * apiConsumerAPIPublishedTenant will belong to super tenant. So super
// * tenant flow need to end before starting subscription to avoid adding
// * subscriptions inside super tenant when we are trying to create an
// * Oauth app for a child tenant.
// */
// for (ApiTypeWrapper apiTypeWrapper : apiTypeWrapperList) {
// // todo:resolve:apim - apiConsumer.addSubscription(apiTypeWrapper, username, application);
// }
// }
// }
// }
// //end of subscription
//
// List<APIKey> applicationKeys = application.getKeys();
// if (applicationKeys != null) {
// for (APIKey applicationKey : applicationKeys) {
// if (keyType.equals(applicationKey.getType())) {
// if (applicationKey.getConsumerKey() != null && !applicationKey.getConsumerKey().isEmpty()) {
// ApiApplicationKey apiApplicationKey = new ApiApplicationKey();
// apiApplicationKey.setConsumerKey(applicationKey.getConsumerKey());
// apiApplicationKey.setConsumerSecret(applicationKey.getConsumerSecret());
// return apiApplicationKey;
// }
// }
// }
// }
//
// List<String> allowedDomains = new ArrayList<>();
// if (isAllowedAllDomains) {
// allowedDomains.add(ApiApplicationConstants.ALLOWED_DOMAINS);
// } else {
// allowedDomains.add(APIManagerUtil.getTenantDomain());
// }
//
// APIAdmin apiAdmin = new APIAdminImpl();
// String keyManagerId = null;
// try {
// List<KeyManagerConfigurationDTO> keyManagerConfigurations = null; // todo:resolve:apim -
// // apiAdmin.getKeyManagerConfigurationsByTenant(tenantDomain);
// if (keyManagerConfigurations != null) {
// for (KeyManagerConfigurationDTO keyManagerConfigurationDTO : keyManagerConfigurations) {
// keyManagerId = keyManagerConfigurationDTO.getUuid();
// }
// }
// String applicationAccessTokenExpiryTime = "N/A";
// if (!StringUtils.isEmpty(validityTime)) {
// applicationAccessTokenExpiryTime = validityTime;
// }
// String jsonString = "{\"grant_types\":\"refresh_token,access_token," +
// "urn:ietf:params:oauth:grant-type:saml2-bearer," +
// "password,client_credentials,iwa:ntlm,urn:ietf:params:oauth:grant-type:jwt-bearer\"," +
// "\"additionalProperties\":\"{\\\"application_access_token_expiry_time\\\":\\\"" + applicationAccessTokenExpiryTime + "\\\"," +
// "\\\"user_access_token_expiry_time\\\":\\\"N\\/A\\\"," +
// "\\\"refresh_token_expiry_time\\\":\\\"N\\/A\\\"," +
// "\\\"id_token_expiry_time\\\":\\\"N\\/A\\\"}\"," +
// "\"username\":\"" + username + "\"}";
//
// Map<String, Object> keyDetails = null; // todo:resolve:apim - apiConsumer
//// .requestApprovalForApplicationRegistration(username, applicationName, keyType, "",
//// allowedDomains.toArray(new String[allowedDomains.size()]), validityTime, "default", "",
//// jsonString, keyManagerId, tenantDomain);
//
// if (keyDetails != null) {
// ApiApplicationKey apiApplicationKey = new ApiApplicationKey();
// apiApplicationKey.setConsumerKey((String) keyDetails.get("consumerKey"));
// apiApplicationKey.setConsumerSecret((String) keyDetails.get("consumerSecret"));
// return apiApplicationKey;
// }
// throw new APIManagerException("Failed to generate keys for tenant: " + tenantDomain);
//// todo:resolve:apim - commected as it says never throw since we commented apim calls above
//// cnt rm
//// } catch (APIManagementException e) {
// } catch (Exception e) {
// throw new APIManagerException("Failed to create api application for tenant: " + tenantDomain, e);
// }
// } catch (APIManagementException e) {
// throw new APIManagerException("Failed to create api application for tenant: " + tenantDomain, e);
// }
// }
@Override
public AccessTokenInfo getAccessToken(String scopes, String[] tags, String applicationName, String tokenType,
String validityPeriod, String username) throws APIManagerException {

Loading…
Cancel
Save