diff --git a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/APIAdmin.java b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/APIAdmin.java index 041a774d1334..4e8ab9666be1 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/APIAdmin.java +++ b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/APIAdmin.java @@ -276,10 +276,12 @@ void updateMonetizationUsagePublishInfo(MonetizationUsagePublishInfo monetizatio /** * This method used to retrieve key manager configurations for tenant * @param organization organization of the key manager + * @param checkUsages whether to check usages * @return KeyManagerConfigurationDTO list * @throws APIManagementException if error occurred */ - List getKeyManagerConfigurationsByOrganization(String organization) throws APIManagementException; + List getKeyManagerConfigurationsByOrganization(String organization, + boolean checkUsages) throws APIManagementException; /** * This method returns all the key managers registered in all the tenants @@ -515,6 +517,15 @@ Map searchPaginatedApis(String searchQuery, String organization, */ List getGlobalKeyManagerConfigurations() throws APIManagementException; + /** + * This method used to retrieve global key manager configurations with usage check + * @param organization organization + * @return KeyManagerConfigurationDTO list + * @throws APIManagementException if error occurred + */ + List getGlobalKeyManagerConfigurations(String organization) + throws APIManagementException; + /** * This method used to retrieve global key manager with Id * @param id uuid of key manager diff --git a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/APIConsumer.java b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/APIConsumer.java index 7df9c706bd3b..54a0b8e2f5d8 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/APIConsumer.java +++ b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/APIConsumer.java @@ -33,6 +33,7 @@ import org.wso2.carbon.apimgt.api.model.Application; import org.wso2.carbon.apimgt.api.model.Comment; import org.wso2.carbon.apimgt.api.model.Identifier; +import org.wso2.carbon.apimgt.api.model.KeyManagerApplicationInfo; import org.wso2.carbon.apimgt.api.model.Monetization; import org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo; import org.wso2.carbon.apimgt.api.model.ResourceFile; @@ -851,4 +852,12 @@ List getKeyManagerConfigurationsByOrganization(Strin boolean isKeyManagerByNameAllowedForUser(String keyManagerName, String organization, String username) throws APIManagementException; + /** + * Remove application keys. + * @param application application + * @param keyMappingId key mapping id + * @param xWSO2Tenant tenant domain + * @throws APIManagementException + */ + boolean removalKeys(Application application, String keyMappingId, String xWSO2Tenant) throws APIManagementException; } diff --git a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/ExceptionCodes.java b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/ExceptionCodes.java index ef13a401622d..10b3f1188153 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/ExceptionCodes.java +++ b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/ExceptionCodes.java @@ -549,6 +549,8 @@ public enum ExceptionCodes implements ErrorHandler { // Admin portal get apis and api provider change related errors CHANGE_API_PROVIDER_FAILED(903011, "Error while changing the API provider", 500, "Error while changing the API provider in the registry or DB"), GET_SEARCH_APIS_IN_ADMIN_FAILED(903012, "Error while getting the apis", 500, "Error while getting/searching the apis from registry"), + KEY_MANAGER_DELETE_FAILED(902015, "Key Manager Delete error", 412,"Error while deleting the Key Manager. %s", false), + KEYS_DELETE_FAILED(902014, "Key Delete error", 412,"Error while deleting Keys. %s", false), // AI service invocation related exceptions AI_SERVICE_INVALID_RESPONSE(903100, "Invalid response from AI service", 500, "Error while invoking AI service. %s", false), diff --git a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/KeyManagerConfigurationDTO.java b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/KeyManagerConfigurationDTO.java index f989bba03edd..f1a61252290b 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/KeyManagerConfigurationDTO.java +++ b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/KeyManagerConfigurationDTO.java @@ -43,6 +43,7 @@ public class KeyManagerConfigurationDTO implements Serializable { private String externalReferenceId = null; private String alias = null; private KeyManagerPermissionConfigurationDTO permissions = new KeyManagerPermissionConfigurationDTO(); + private Boolean isUsed = null; public KeyManagerConfigurationDTO() { } @@ -196,4 +197,14 @@ public void setPermissions (KeyManagerPermissionConfigurationDTO permissions) { } this.permissions = permissions; } + + public Boolean getIsUsed() { + + return this.isUsed; + } + + public void setUsed(Boolean isUsed) { + + this.isUsed = isUsed; + } } diff --git a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/KeyManagerApplicationInfo.java b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/KeyManagerApplicationInfo.java new file mode 100644 index 000000000000..6e0a86e66a2b --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/KeyManagerApplicationInfo.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com) All Rights Reserved. + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.wso2.carbon.apimgt.api.model; + +public class KeyManagerApplicationInfo { + String keyManagerName; + String consumerKey; + String mode; + + public String getKeyManagerName() { + return keyManagerName; + } + + public void setKeyManagerName(String keyManagerName) { + this.keyManagerName = keyManagerName; + } + + public String getConsumerKey() { + return consumerKey; + } + + public void setConsumerKey(String consumerKey) { + this.consumerKey = consumerKey; + } + + public String getMode() { + return mode; + } + + public void setMode(String mode) { + this.mode = mode; + } +} diff --git a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/KeyManagerApplicationUsages.java b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/KeyManagerApplicationUsages.java new file mode 100644 index 000000000000..3f7d9bfe9ce9 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/KeyManagerApplicationUsages.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com) All Rights Reserved. + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.wso2.carbon.apimgt.api.model; + +import java.util.ArrayList; +import java.util.List; + +public class KeyManagerApplicationUsages { + + int applicationCount; + List applications = new ArrayList<>(); + + public int getApplicationCount() { + return applicationCount; + } + + public void setApplicationCount(int applicationCount) { + this.applicationCount = applicationCount; + } + + public List getApplications() { return applications; } + + public void setApplications(List applications) {this.applications = applications; } +} diff --git a/components/apimgt/org.wso2.carbon.apimgt.cleanup.service/src/main/java/org/wso2/carbon/apimgt/cleanup/service/IdpKeyMangerPurge.java b/components/apimgt/org.wso2.carbon.apimgt.cleanup.service/src/main/java/org/wso2/carbon/apimgt/cleanup/service/IdpKeyMangerPurge.java index 4f38c4f82564..e7166996a9ae 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.cleanup.service/src/main/java/org/wso2/carbon/apimgt/cleanup/service/IdpKeyMangerPurge.java +++ b/components/apimgt/org.wso2.carbon.apimgt.cleanup.service/src/main/java/org/wso2/carbon/apimgt/cleanup/service/IdpKeyMangerPurge.java @@ -87,7 +87,7 @@ public LinkedHashMap purge(String organization) { isKeyManagerOrganizationExist = organizationPurgeDAO.keyManagerOrganizationExist(organization); break; case APIConstants.OrganizationDeletion.KM_RETRIEVER: - keyManagerList = apiAdmin.getKeyManagerConfigurationsByOrganization(organization); + keyManagerList = apiAdmin.getKeyManagerConfigurationsByOrganization(organization, false); break; case APIConstants.OrganizationDeletion.IDP_DATA_REMOVER: deleteIdpList(organization, keyManagerList); diff --git a/components/apimgt/org.wso2.carbon.apimgt.cleanup.service/src/test/java/organization/purge/IdpKmPurgeTest.java b/components/apimgt/org.wso2.carbon.apimgt.cleanup.service/src/test/java/organization/purge/IdpKmPurgeTest.java index dca1234a6f62..b8ea0f071d71 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.cleanup.service/src/test/java/organization/purge/IdpKmPurgeTest.java +++ b/components/apimgt/org.wso2.carbon.apimgt.cleanup.service/src/test/java/organization/purge/IdpKmPurgeTest.java @@ -74,7 +74,7 @@ public class IdpKmPurgeTest { List keyManagerList = new ArrayList<>(); keyManagerList.add(kmConfig); - Mockito.doReturn(keyManagerList).when(amAdmin).getKeyManagerConfigurationsByOrganization("testOrg"); + Mockito.doReturn(keyManagerList).when(amAdmin).getKeyManagerConfigurationsByOrganization("testOrg", false); Mockito.doNothing().when(organizationPurgeDAO).deleteKeyManagerConfigurationList(keyManagerList, "testOrg"); Mockito.doReturn(true).when(organizationPurgeDAO).keyManagerOrganizationExist(Mockito.anyString()); Mockito.doNothing().when(amAdmin).deleteIdentityProvider("testOrg", kmConfig); diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIAdminImpl.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIAdminImpl.java index f3a83718695f..e2f15bd6aac6 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIAdminImpl.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIAdminImpl.java @@ -27,7 +27,6 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.solr.client.solrj.util.ClientUtils; import org.everit.json.schema.Schema; import org.everit.json.schema.ValidationException; import org.json.JSONException; @@ -44,14 +43,12 @@ import org.wso2.carbon.apimgt.api.dto.KeyManagerPermissionConfigurationDTO; import org.wso2.carbon.apimgt.api.model.APICategory; import org.wso2.carbon.apimgt.api.model.APIIdentifier; -import org.wso2.carbon.apimgt.api.model.APIProduct; -import org.wso2.carbon.apimgt.api.model.APIProductIdentifier; import org.wso2.carbon.apimgt.api.model.Application; import org.wso2.carbon.apimgt.api.model.ApplicationInfo; +import org.wso2.carbon.apimgt.api.model.ApplicationInfoKeyManager; import org.wso2.carbon.apimgt.api.model.ConfigurationDto; -import org.wso2.carbon.apimgt.api.model.Documentation; -import org.wso2.carbon.apimgt.api.model.DocumentationType; import org.wso2.carbon.apimgt.api.model.Environment; +import org.wso2.carbon.apimgt.api.model.KeyManagerApplicationUsages; import org.wso2.carbon.apimgt.api.model.KeyManagerConfiguration; import org.wso2.carbon.apimgt.api.model.KeyManagerConnectorConfiguration; import org.wso2.carbon.apimgt.api.model.Monetization; @@ -73,24 +70,13 @@ import org.wso2.carbon.apimgt.impl.monetization.DefaultMonetizationImpl; import org.wso2.carbon.apimgt.impl.service.KeyMgtRegistrationService; import org.wso2.carbon.apimgt.impl.utils.APINameComparator; -import org.wso2.carbon.apimgt.impl.utils.APIProductNameComparator; import org.wso2.carbon.apimgt.impl.utils.APIUtil; import org.wso2.carbon.apimgt.impl.utils.ContentSearchResultNameComparator; import org.wso2.carbon.apimgt.persistence.APIPersistence; -import org.wso2.carbon.apimgt.persistence.dto.AdminApiInfo; import org.wso2.carbon.apimgt.persistence.dto.AdminApiSearchContent; import org.wso2.carbon.apimgt.persistence.dto.AdminContentSearchResult; -import org.wso2.carbon.apimgt.persistence.dto.DocumentSearchContent; -import org.wso2.carbon.apimgt.persistence.dto.Organization; -import org.wso2.carbon.apimgt.persistence.dto.PublisherAPIInfo; -import org.wso2.carbon.apimgt.persistence.dto.PublisherAPISearchResult; -import org.wso2.carbon.apimgt.persistence.dto.PublisherContentSearchResult; -import org.wso2.carbon.apimgt.persistence.dto.PublisherSearchContent; import org.wso2.carbon.apimgt.persistence.dto.SearchContent; -import org.wso2.carbon.apimgt.persistence.dto.UserContext; import org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException; -import org.wso2.carbon.apimgt.persistence.mapper.APIMapper; -import org.wso2.carbon.apimgt.persistence.utils.RegistrySearchUtil; import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.core.util.CryptoException; @@ -117,10 +103,8 @@ import java.util.Date; import java.util.HashMap; import java.util.Iterator; -import java.util.LinkedHashSet; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.SortedSet; import java.util.TimeZone; import java.util.TreeSet; @@ -136,6 +120,7 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import static org.wso2.carbon.apimgt.impl.utils.APIUtil.getPaginatedApplicationList; /** * This class provides the core API admin functionality. @@ -390,8 +375,8 @@ public long getTimestamp(String date) { } @Override - public List getKeyManagerConfigurationsByOrganization(String organization) - throws APIManagementException { + public List getKeyManagerConfigurationsByOrganization(String organization, + boolean checkUsages) throws APIManagementException { // For Choreo scenario (Choreo organization uses the same super tenant Resident Key Manager // Hence no need to register the default key manager per organization) @@ -443,6 +428,10 @@ public List getKeyManagerConfigurationsByOrganizatio } setIdentityProviderRelatedInformation(keyManagerConfigurationsByTenant, organization); + if (checkUsages) { + setKeyManagerUsageRelatedInformation(keyManagerConfigurationsByTenant, organization); + } + return keyManagerConfigurationsByTenant; } @@ -472,6 +461,29 @@ private void setIdentityProviderRelatedInformation(List keyManagerConfigurationsByOrganization, String organization) + throws APIManagementException { + + for (KeyManagerConfigurationDTO keyManagerConfigurationDTO : keyManagerConfigurationsByOrganization) { + + KeyManagerApplicationUsages appUsages = getApplicationsOfKeyManager(keyManagerConfigurationDTO.getUuid(), 0, + Integer.MAX_VALUE); + if (appUsages.getApplicationCount() > 0) { + keyManagerConfigurationDTO.setUsed(true); + continue; + } + + AdminContentSearchResult apiUsages = getAPIUsagesByKeyManagerNameAndOrganization(organization, + keyManagerConfigurationDTO.getName(), 0, Integer.MAX_VALUE); + if (apiUsages.getApiCount() > 0) { + keyManagerConfigurationDTO.setUsed(true); + continue; + } + keyManagerConfigurationDTO.setUsed(false); + } + } + private void setAliasForTokenExchangeKeyManagers(List keyManagerConfigurationsByTenant, String tenantDomain) throws APIManagementException { for (KeyManagerConfigurationDTO keyManagerConfigurationDTO : keyManagerConfigurationsByTenant) { @@ -643,6 +655,29 @@ public KeyManagerConfigurationDTO addKeyManagerConfiguration( return keyManagerConfigurationDTO; } + public AdminContentSearchResult getAPIUsagesByKeyManagerNameAndOrganization(String org, String keyManagerName, + int offset, int limit) throws APIManagementException { + + APIPersistence apiPersistenceInstance = PersistenceFactory.getAPIPersistenceInstance(); + String searchQuery = APIConstants.API_USAGE_BY_KEY_MANAGER_QUERY.replace("$1", keyManagerName); + try { + return apiPersistenceInstance.searchContentForAdmin(org, searchQuery, offset, limit, limit); + } catch (APIPersistenceException e) { + throw new APIManagementException("Error while finding the key manager ", e); + } + } + + public KeyManagerApplicationUsages getApplicationsOfKeyManager(String keyManagerId, int offset, int limit) + throws APIManagementException { + + KeyManagerApplicationUsages keyManagerApplicationUsages = new KeyManagerApplicationUsages(); + ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance(); + List applications = apiMgtDAO.getAllApplicationsOfKeyManager(keyManagerId); + keyManagerApplicationUsages.setApplicationCount(applications.size()); + keyManagerApplicationUsages.setApplications(getPaginatedApplicationList(applications, offset, limit)); + return keyManagerApplicationUsages; + } + private void validateKeyManagerEndpointConfiguration(KeyManagerConfigurationDTO keyManagerConfigurationDTO) throws APIManagementException { if (!APIConstants.KeyManager.DEFAULT_KEY_MANAGER.equals(keyManagerConfigurationDTO.getName())) { @@ -926,14 +961,24 @@ public void deleteIdentityProvider(String organization, KeyManagerConfigurationD public void deleteKeyManagerConfigurationById(String organization, KeyManagerConfigurationDTO kmConfig) throws APIManagementException { if (kmConfig != null) { - if (!APIConstants.KeyManager.DEFAULT_KEY_MANAGER.equals(kmConfig.getName())) { - deleteIdentityProvider(organization, kmConfig); - apiMgtDAO.deleteKeyManagerConfigurationById(kmConfig.getUuid(), organization); - new KeyMgtNotificationSender() - .notify(kmConfig, APIConstants.KeyManager.KeyManagerEvent.ACTION_DELETE); + AdminContentSearchResult apiUsage = getAPIUsagesByKeyManagerNameAndOrganization(organization, + kmConfig.getName(), 0, Integer.MAX_VALUE); + KeyManagerApplicationUsages appUsages = getApplicationsOfKeyManager(kmConfig.getUuid(), 0, + Integer.MAX_VALUE); + if (apiUsage != null && apiUsage.getApiCount() == 0 && appUsages != null + && appUsages.getApplicationCount() == 0) { + if (!APIConstants.KeyManager.DEFAULT_KEY_MANAGER.equals(kmConfig.getName())) { + deleteIdentityProvider(organization, kmConfig); + apiMgtDAO.deleteKeyManagerConfigurationById(kmConfig.getUuid(), organization); + new KeyMgtNotificationSender() + .notify(kmConfig, APIConstants.KeyManager.KeyManagerEvent.ACTION_DELETE); + } else { + throw new APIManagementException(APIConstants.KeyManager.DEFAULT_KEY_MANAGER + " couldn't delete", + ExceptionCodes.KEY_MANAGER_DELETE_FAILED); + } } else { - throw new APIManagementException(APIConstants.KeyManager.DEFAULT_KEY_MANAGER + " couldn't delete", - ExceptionCodes.INTERNAL_ERROR); + throw new APIManagementException("Key Manager is already used by an API or an Application.", + ExceptionCodes.KEY_MANAGER_DELETE_FAILED); } } } @@ -1704,4 +1749,15 @@ public List getGlobalKeyManagerConfigurations() thro } return keyManagerConfigurations; } + + public List getGlobalKeyManagerConfigurations(String organization) + throws APIManagementException { + List keyManagerConfigurations = apiMgtDAO.getKeyManagerConfigurationsByOrganization( + APIConstants.GLOBAL_KEY_MANAGER_TENANT_DOMAIN); + for (KeyManagerConfigurationDTO keyManagerConfigurationDTO : keyManagerConfigurations) { + decryptKeyManagerConfigurationValues(keyManagerConfigurationDTO); + } + setKeyManagerUsageRelatedInformation(keyManagerConfigurations, organization); + return keyManagerConfigurations; + } } diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConstants.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConstants.java index e0a581e2cf35..9020b8911df0 100755 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConstants.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConstants.java @@ -2360,6 +2360,8 @@ public enum APITransportType { public static final String API_SUBSCRIPTION_TYPE = "API"; public static final String TYPE = "type"; public static final String TYPE_SEARCH_TYPE_KEY = "type="; + public static final String API_USAGE_BY_KEY_MANAGER_QUERY = "overview_keyManagers:\\*\"$1\"\\* " + + " AND mediaType:application\\/vnd.wso2\\-api\\+xml"; public static class OASResourceAuthTypes { diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java index 6531ad4207d9..4ec2d402e854 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java @@ -64,6 +64,7 @@ import org.wso2.carbon.apimgt.api.model.Environment; import org.wso2.carbon.apimgt.api.model.Identifier; import org.wso2.carbon.apimgt.api.model.KeyManager; +import org.wso2.carbon.apimgt.api.model.KeyManagerApplicationInfo; import org.wso2.carbon.apimgt.api.model.KeyManagerConfiguration; import org.wso2.carbon.apimgt.api.model.Label; import org.wso2.carbon.apimgt.api.model.Monetization; @@ -3617,6 +3618,56 @@ public void cleanUpApplicationRegistrationByApplicationIdAndKeyMappingId(int app } } + public boolean removalKeys(Application application, String keyMappingId, String xWSO2Tenant) + throws APIManagementException { + + try { + APIConsumer apiConsumer = APIManagerFactory.getInstance().getAPIConsumer(this.username); + + if (StringUtils.isNotEmpty(xWSO2Tenant)) { + int tenantId = APIUtil.getInternalOrganizationId(xWSO2Tenant); + // To handle choreo scenario. due to key managers are not per organization atm. using ST + if (tenantId == MultitenantConstants.SUPER_TENANT_ID) { + xWSO2Tenant = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME; + } + } + String tenantDomain = this.tenantDomain; + if (StringUtils.isNotEmpty(xWSO2Tenant)) { + tenantDomain = xWSO2Tenant; + } + + String keyManagerName = APIConstants.KeyManager.DEFAULT_KEY_MANAGER; + ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance(); + KeyManagerApplicationInfo KeyManagerApplicationInfo = + apiMgtDAO.getKeyManagerNameAndConsumerKeyByAppIdAndKeyMappingId(application.getId(), keyMappingId); + String keyManagerNameResult = KeyManagerApplicationInfo.getKeyManagerName(); + if (!StringUtils.isEmpty(keyManagerNameResult)) { + keyManagerName = keyManagerNameResult; + } + String consumerKey = KeyManagerApplicationInfo.getConsumerKey(); + + //Removed the key manager entry from the key manager if it is not a mapped key.xxx + if (KeyManagerApplicationInfo.getMode().equals(APIConstants.OAuthAppMode.CREATED.name())) { + KeyManager keyManager = KeyManagerHolder.getKeyManagerInstance(tenantDomain, keyManagerName); + keyManager.deleteApplication(consumerKey); + } + + apiConsumer.cleanUpApplicationRegistrationByApplicationIdAndKeyMappingId(application.getId(), keyMappingId); + + //publishing event for application key cleanup in gateway. + ApplicationRegistrationEvent removeEntryTrigger = new ApplicationRegistrationEvent( + UUID.randomUUID().toString(), System.currentTimeMillis(), + APIConstants.EventType.REMOVE_APPLICATION_KEYMAPPING.name(), + APIUtil.getTenantIdFromTenantDomain(tenantDomain), application.getOrganization(), + application.getId(), application.getUUID(), consumerKey, application.getKeyType(), keyManagerName); + APIUtil.sendNotification(removeEntryTrigger, APIConstants.NotifierType.APPLICATION_REGISTRATION.name()); + return true; + } catch (APIManagementException e) { + throw new APIManagementException("Error occurred while application key cleanup process", + ExceptionCodes.KEYS_DELETE_FAILED); + } + } + @Override public APIKey getApplicationKeyByAppIDAndKeyMapping(int applicationId, String keyMappingId) throws APIManagementException { @@ -4439,7 +4490,7 @@ public List getKeyManagerConfigurationsByOrganizatio APIAdmin apiAdmin = new APIAdminImpl(); List keyManagerConfigurations = - apiAdmin.getKeyManagerConfigurationsByOrganization(organization); + apiAdmin.getKeyManagerConfigurationsByOrganization(organization, false); List permittedKeyManagerConfigurations = new ArrayList<>(); if (keyManagerConfigurations.size() > 0) { for (KeyManagerConfigurationDTO keyManagerConfiguration : keyManagerConfigurations) { diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/ApiMgtDAO.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/ApiMgtDAO.java index cf672bff2f7d..8fcb44a815a2 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/ApiMgtDAO.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/ApiMgtDAO.java @@ -55,6 +55,7 @@ import org.wso2.carbon.apimgt.api.model.ApiTypeWrapper; import org.wso2.carbon.apimgt.api.model.Application; import org.wso2.carbon.apimgt.api.model.ApplicationInfo; +import org.wso2.carbon.apimgt.api.model.ApplicationInfoKeyManager; import org.wso2.carbon.apimgt.api.model.BlockConditionsDTO; import org.wso2.carbon.apimgt.api.model.Comment; import org.wso2.carbon.apimgt.api.model.CommentList; @@ -64,6 +65,7 @@ import org.wso2.carbon.apimgt.api.model.GatewayPolicyDeployment; import org.wso2.carbon.apimgt.api.model.Identifier; import org.wso2.carbon.apimgt.api.model.KeyManager; +import org.wso2.carbon.apimgt.api.model.KeyManagerApplicationInfo; import org.wso2.carbon.apimgt.api.model.LifeCycleEvent; import org.wso2.carbon.apimgt.api.model.MonetizationUsagePublishInfo; import org.wso2.carbon.apimgt.api.model.OAuthAppRequest; @@ -9807,6 +9809,30 @@ public APIKey getKeyMappingFromApplicationIdAndKeyMappingId(int applicationId, S return null; } + public KeyManagerApplicationInfo getKeyManagerNameAndConsumerKeyByAppIdAndKeyMappingId(int applicationId, + String keyMappingId) throws APIManagementException { + + String query = SQLConstants.KeyManagerSqlConstants + .GET_KEY_MANAGER_NAME_AND_CONSUMER_KEY_BY_APPLICATION_ID_AND_KEY_MAPPING_ID; + try (Connection connection = APIMgtDBUtil.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement(query)) { + preparedStatement.setInt(1, applicationId); + preparedStatement.setString(2, keyMappingId); + try (ResultSet resultSet = preparedStatement.executeQuery()) { + if (resultSet.next()) { + KeyManagerApplicationInfo keyManagerApplicationInfo = new KeyManagerApplicationInfo(); + keyManagerApplicationInfo.setConsumerKey(resultSet.getString("CONSUMER_KEY")); + keyManagerApplicationInfo.setKeyManagerName(resultSet.getString("KEY_MANAGER_NAME")); + keyManagerApplicationInfo.setMode(resultSet.getString("CREATE_MODE")); + return keyManagerApplicationInfo; + } + } + } catch (SQLException e) { + throw new APIManagementException("Error while Retrieving Key Mapping ", e); + } + return null; + } + public void deleteApplicationKeyMappingByMappingId(String keyMappingId) throws APIManagementException { Connection connection = null; @@ -20154,6 +20180,32 @@ private Set getAllClonedPolicyIdsForAPI(Connection connection, String ap return policyIds; } + public List getAllApplicationsOfKeyManager(String keyManagerId) + throws APIManagementException { + + ArrayList applicationsList = new ArrayList<>(); + String sqlQuery = SQLConstants.GET_APPLICATIONS_OF_KEY_MANAGERS_SQL; + + try (Connection connection = APIMgtDBUtil.getConnection(); + PreparedStatement prepStmt = connection.prepareStatement(sqlQuery)) { + prepStmt.setString(1, keyManagerId); + try (ResultSet rs = prepStmt.executeQuery()) { + ApplicationInfoKeyManager application; + while (rs.next()) { + application = new ApplicationInfoKeyManager(); + application.setUuid(rs.getString("UUID")); + application.setName(rs.getString("NAME")); + application.setOwner(rs.getString("CREATED_BY")); + application.setOrganization(rs.getString("ORGANIZATION")); + applicationsList.add(application); + } + } + } catch (SQLException e) { + handleException("Error when reading the application information from the persistence store.", e); + } + return applicationsList; + } + /** * This method will query AM_API_OPERATION_POLICY table from CLONED_POLICY_ID row for a matching policy ID * for the required API. This is useful to find the cloned API specific policy ID from a common policy. diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SQLConstants.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SQLConstants.java index 2577872ebae5..647afaf999a8 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SQLConstants.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SQLConstants.java @@ -1269,6 +1269,13 @@ public class SQLConstants { "SELECT MAP.CONSUMER_KEY, MAP.CREATE_MODE, KM.NAME, KM.ORGANIZATION FROM AM_APPLICATION_KEY_MAPPING MAP," + " AM_KEY_MANAGER KM WHERE MAP.APPLICATION_ID = ? AND MAP.KEY_MANAGER = KM.UUID"; + public static final String GET_APPLICATIONS_OF_KEY_MANAGERS_SQL = + "SELECT DISTINCT APP.UUID, APP.CREATED_BY, APP.NAME, APP.APPLICATION_STATUS, APP.ORGANIZATION, " + + "APP.SUBSCRIBER_ID FROM AM_APPLICATION_KEY_MAPPING MAP, AM_KEY_MANAGER KM, AM_APPLICATION APP " + + "WHERE MAP.KEY_MANAGER = ? " + + "AND MAP.KEY_MANAGER = KM.UUID " + + "AND APP.APPLICATION_ID = MAP.APPLICATION_ID"; + public static final String REMOVE_APPLICATION_FROM_SUBSCRIPTIONS_SQL = "DELETE FROM AM_SUBSCRIPTION WHERE APPLICATION_ID = ?"; @@ -3697,12 +3704,18 @@ public static class KeyManagerSqlConstants { public static final String ADD_KEY_MANAGER = " INSERT INTO AM_KEY_MANAGER (UUID,NAME,DESCRIPTION,TYPE,CONFIGURATION,ORGANIZATION,ENABLED," + "DISPLAY_NAME,TOKEN_TYPE,EXTERNAL_REFERENCE_ID) VALUES (?,?,?,?,?,?,?,?,?,?)"; + public static final String UPDATE_KEY_MANAGER = "UPDATE AM_KEY_MANAGER SET NAME = ?,DESCRIPTION = ?,TYPE = ?,CONFIGURATION = ?,ORGANIZATION = ?," + "ENABLED = ?,DISPLAY_NAME = ?,TOKEN_TYPE = ?, EXTERNAL_REFERENCE_ID = ? WHERE UUID = ?"; public static final String DELETE_KEY_MANAGER = "DELETE FROM AM_KEY_MANAGER WHERE UUID = ? AND ORGANIZATION = ?"; + + public static final String GET_KEY_MANAGER_NAME_AND_CONSUMER_KEY_BY_APPLICATION_ID_AND_KEY_MAPPING_ID = + "SELECT NAME AS KEY_MANAGER_NAME, CONSUMER_KEY, CREATE_MODE FROM AM_KEY_MANAGER AKM, " + + "AM_APPLICATION_KEY_MAPPING AAKM WHERE APPLICATION_ID=? AND AAKM.UUID = ? " + + "AND AKM.UUID=AAKM.KEY_MANAGER"; } /** diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java index 896f9d34b562..0b5c47771986 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java @@ -101,6 +101,7 @@ import org.wso2.carbon.apimgt.api.model.APIStatus; import org.wso2.carbon.apimgt.api.model.APIStore; import org.wso2.carbon.apimgt.api.model.Application; +import org.wso2.carbon.apimgt.api.model.ApplicationInfoKeyManager; import org.wso2.carbon.apimgt.api.model.CORSConfiguration; import org.wso2.carbon.apimgt.api.model.Documentation; import org.wso2.carbon.apimgt.api.model.DocumentationType; @@ -10560,4 +10561,22 @@ public static void DeleteApi(String endpoint, String authToken, throw new APIManagementException("Error encountered while connecting to service", e); } } + + /** + * Retrieves a paginated list of applications from the provided list, based on the specified offset and limit. + * + * @param applications The list of applications to paginate. + * @param offset The starting index of the paginated sublist. + * @param limit The maximum number of applications to include in the paginated sublist. + * @return A paginated sublist of applications, or an empty list if the offset exceeds the size of the input list. + */ + public static List getPaginatedApplicationList( + List applications, int offset, int limit) { + + int endIndex = Math.min(offset + limit, applications.size()); + if (offset >= applications.size()) { + return Collections.emptyList(); + } + return applications.subList(offset, endIndex); + } } diff --git a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/java/org/wso2/carbon/apimgt/internal/service/impl/KeymanagersApiServiceImpl.java b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/java/org/wso2/carbon/apimgt/internal/service/impl/KeymanagersApiServiceImpl.java index c742d014ab31..bad28801a6c2 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/java/org/wso2/carbon/apimgt/internal/service/impl/KeymanagersApiServiceImpl.java +++ b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/java/org/wso2/carbon/apimgt/internal/service/impl/KeymanagersApiServiceImpl.java @@ -45,7 +45,7 @@ public Response keymanagersGet(String xWSO2Tenant, MessageContext messageContext APIAdmin apiAdmin = new APIAdminImpl(); List keyManagerConfigurations = - apiAdmin.getKeyManagerConfigurationsByOrganization(xWSO2Tenant); + apiAdmin.getKeyManagerConfigurationsByOrganization(xWSO2Tenant, false); List globalKeyManagerConfigurations = apiAdmin .getGlobalKeyManagerConfigurations(); keyManagerConfigurations.addAll(globalKeyManagerConfigurations); diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/KeyManagersApi.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/KeyManagersApi.java index 9a4d43b1c698..8c952e4fd159 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/KeyManagersApi.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/KeyManagersApi.java @@ -1,6 +1,8 @@ package org.wso2.carbon.apimgt.rest.api.admin.v1; import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ErrorDTO; +import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerAPIUsagesDTO; +import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerAppUsagesDTO; import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerDTO; import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerListDTO; import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerWellKnownResponseDTO; @@ -72,6 +74,42 @@ public Response keyManagersGet() throws APIManagementException{ return delegate.keyManagersGet(securityContext); } + @GET + @Path("/{keyManagerId}/api-usages") + + @Produces({ "application/json" }) + @ApiOperation(value = "Retrieve Key Manager Usages (APIs)", notes = "Retrieves a list of APIs that are specifically utilizing the Key Manager identified by the provided ID. The Key Manager ID should be provided as a path parameter. ", response = KeyManagerAPIUsagesDTO.class, authorizations = { + @Authorization(value = "OAuth2Security", scopes = { + @AuthorizationScope(scope = "apim:admin", description = "Manage all admin operations"), + @AuthorizationScope(scope = "apim:admin_operations", description = "Manage API categories and Key Managers related operations") + }) + }, tags={ "Key Manager (Individual)", }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "OK. KeyManager API usages returned. ", response = KeyManagerAPIUsagesDTO.class), + @ApiResponse(code = 404, message = "Not Found. The specified resource does not exist.", response = ErrorDTO.class), + @ApiResponse(code = 406, message = "Not Acceptable. The requested media type is not supported.", response = ErrorDTO.class) }) + public Response keyManagersKeyManagerIdApiUsagesGet(@ApiParam(value = "Key Manager UUID ",required=true) @PathParam("keyManagerId") String keyManagerId, @ApiParam(value = "Starting point within the complete list of items qualified. ", defaultValue="0") @DefaultValue("0") @QueryParam("offset") Integer offset, @ApiParam(value = "Maximum size of resource array to return. ", defaultValue="25") @DefaultValue("25") @QueryParam("limit") Integer limit) throws APIManagementException{ + return delegate.keyManagersKeyManagerIdApiUsagesGet(keyManagerId, offset, limit, securityContext); + } + + @GET + @Path("/{keyManagerId}/app-usages") + + @Produces({ "application/json" }) + @ApiOperation(value = "Retrieve Key Manager Usages (Appilcations)", notes = "Retrieves a list of Applications that are specifically utilizing the Key Manager identified by the provided ID. The Key Manager ID should be provided as a path parameter. ", response = KeyManagerAppUsagesDTO.class, authorizations = { + @Authorization(value = "OAuth2Security", scopes = { + @AuthorizationScope(scope = "apim:admin", description = "Manage all admin operations"), + @AuthorizationScope(scope = "apim:admin_operations", description = "Manage API categories and Key Managers related operations") + }) + }, tags={ "Key Manager (Individual)", }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "OK. KeyManager application usages returned. ", response = KeyManagerAppUsagesDTO.class), + @ApiResponse(code = 404, message = "Not Found. The specified resource does not exist.", response = ErrorDTO.class), + @ApiResponse(code = 406, message = "Not Acceptable. The requested media type is not supported.", response = ErrorDTO.class) }) + public Response keyManagersKeyManagerIdAppUsagesGet(@ApiParam(value = "Key Manager UUID ",required=true) @PathParam("keyManagerId") String keyManagerId, @ApiParam(value = "Starting point within the complete list of items qualified. ", defaultValue="0") @DefaultValue("0") @QueryParam("offset") Integer offset, @ApiParam(value = "Maximum size of resource array to return. ", defaultValue="25") @DefaultValue("25") @QueryParam("limit") Integer limit) throws APIManagementException{ + return delegate.keyManagersKeyManagerIdAppUsagesGet(keyManagerId, offset, limit, securityContext); + } + @DELETE @Path("/{keyManagerId}") diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/KeyManagersApiService.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/KeyManagersApiService.java index 5c2dd6fd0453..b6b7b6557d00 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/KeyManagersApiService.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/KeyManagersApiService.java @@ -10,6 +10,8 @@ import org.wso2.carbon.apimgt.api.APIManagementException; import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ErrorDTO; +import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerAPIUsagesDTO; +import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerAppUsagesDTO; import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerDTO; import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerListDTO; import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerWellKnownResponseDTO; @@ -25,6 +27,8 @@ public interface KeyManagersApiService { public Response keyManagersDiscoverPost(String url, String type, MessageContext messageContext) throws APIManagementException; public Response keyManagersGet(MessageContext messageContext) throws APIManagementException; + public Response keyManagersKeyManagerIdApiUsagesGet(String keyManagerId, Integer offset, Integer limit, MessageContext messageContext) throws APIManagementException; + public Response keyManagersKeyManagerIdAppUsagesGet(String keyManagerId, Integer offset, Integer limit, MessageContext messageContext) throws APIManagementException; public Response keyManagersKeyManagerIdDelete(String keyManagerId, MessageContext messageContext) throws APIManagementException; public Response keyManagersKeyManagerIdGet(String keyManagerId, MessageContext messageContext) throws APIManagementException; public Response keyManagersKeyManagerIdPut(String keyManagerId, KeyManagerDTO keyManagerDTO, MessageContext messageContext) throws APIManagementException; diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/APIInfoKeyManagerDTO.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/APIInfoKeyManagerDTO.java new file mode 100644 index 000000000000..fd756a259449 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/APIInfoKeyManagerDTO.java @@ -0,0 +1,317 @@ +package org.wso2.carbon.apimgt.rest.api.admin.v1.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.*; + + +import io.swagger.annotations.*; +import java.util.Objects; + +import javax.xml.bind.annotation.*; +import org.wso2.carbon.apimgt.rest.api.common.annotations.Scope; +import com.fasterxml.jackson.annotation.JsonCreator; + +import javax.validation.Valid; + + + +public class APIInfoKeyManagerDTO { + + private String id = null; + private String type = null; + private String name = null; + private String transportType = null; + private String description = null; + private String context = null; + private String version = null; + private String provider = null; + private String status = null; + private String thumbnailUri = null; + private Boolean advertiseOnly = null; + private String keyManagerEntry = null; + + /** + * The ID of the API. + **/ + public APIInfoKeyManagerDTO id(String id) { + this.id = id; + return this; + } + + + @ApiModelProperty(required = true, value = "The ID of the API.") + @JsonProperty("id") + @NotNull + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + + /** + * The type of the entry (e.g., \"API\"). + **/ + public APIInfoKeyManagerDTO type(String type) { + this.type = type; + return this; + } + + + @ApiModelProperty(value = "The type of the entry (e.g., \"API\").") + @JsonProperty("type") + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + + /** + * The name of the API. + **/ + public APIInfoKeyManagerDTO name(String name) { + this.name = name; + return this; + } + + + @ApiModelProperty(required = true, value = "The name of the API.") + @JsonProperty("name") + @NotNull + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + /** + * The transport type of the API. + **/ + public APIInfoKeyManagerDTO transportType(String transportType) { + this.transportType = transportType; + return this; + } + + + @ApiModelProperty(value = "The transport type of the API.") + @JsonProperty("transportType") + public String getTransportType() { + return transportType; + } + public void setTransportType(String transportType) { + this.transportType = transportType; + } + + /** + * The description of the API. + **/ + public APIInfoKeyManagerDTO description(String description) { + this.description = description; + return this; + } + + + @ApiModelProperty(value = "The description of the API.") + @JsonProperty("description") + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + + /** + * The context of the API. + **/ + public APIInfoKeyManagerDTO context(String context) { + this.context = context; + return this; + } + + + @ApiModelProperty(value = "The context of the API.") + @JsonProperty("context") + public String getContext() { + return context; + } + public void setContext(String context) { + this.context = context; + } + + /** + * The version of the API. + **/ + public APIInfoKeyManagerDTO version(String version) { + this.version = version; + return this; + } + + + @ApiModelProperty(required = true, value = "The version of the API.") + @JsonProperty("version") + @NotNull + public String getVersion() { + return version; + } + public void setVersion(String version) { + this.version = version; + } + + /** + * The provider of the API. + **/ + public APIInfoKeyManagerDTO provider(String provider) { + this.provider = provider; + return this; + } + + + @ApiModelProperty(required = true, value = "The provider of the API.") + @JsonProperty("provider") + @NotNull + public String getProvider() { + return provider; + } + public void setProvider(String provider) { + this.provider = provider; + } + + /** + * The status of the API. + **/ + public APIInfoKeyManagerDTO status(String status) { + this.status = status; + return this; + } + + + @ApiModelProperty(value = "The status of the API.") + @JsonProperty("status") + public String getStatus() { + return status; + } + public void setStatus(String status) { + this.status = status; + } + + /** + * The URI of the thumbnail of the API. + **/ + public APIInfoKeyManagerDTO thumbnailUri(String thumbnailUri) { + this.thumbnailUri = thumbnailUri; + return this; + } + + + @ApiModelProperty(value = "The URI of the thumbnail of the API.") + @JsonProperty("thumbnailUri") + public String getThumbnailUri() { + return thumbnailUri; + } + public void setThumbnailUri(String thumbnailUri) { + this.thumbnailUri = thumbnailUri; + } + + /** + * Indicates if the API is advertised only. + **/ + public APIInfoKeyManagerDTO advertiseOnly(Boolean advertiseOnly) { + this.advertiseOnly = advertiseOnly; + return this; + } + + + @ApiModelProperty(value = "Indicates if the API is advertised only.") + @JsonProperty("advertiseOnly") + public Boolean isAdvertiseOnly() { + return advertiseOnly; + } + public void setAdvertiseOnly(Boolean advertiseOnly) { + this.advertiseOnly = advertiseOnly; + } + + /** + * The key manager entry related to the API. + **/ + public APIInfoKeyManagerDTO keyManagerEntry(String keyManagerEntry) { + this.keyManagerEntry = keyManagerEntry; + return this; + } + + + @ApiModelProperty(value = "The key manager entry related to the API.") + @JsonProperty("keyManagerEntry") + public String getKeyManagerEntry() { + return keyManagerEntry; + } + public void setKeyManagerEntry(String keyManagerEntry) { + this.keyManagerEntry = keyManagerEntry; + } + + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + APIInfoKeyManagerDTO apIInfoKeyManager = (APIInfoKeyManagerDTO) o; + return Objects.equals(id, apIInfoKeyManager.id) && + Objects.equals(type, apIInfoKeyManager.type) && + Objects.equals(name, apIInfoKeyManager.name) && + Objects.equals(transportType, apIInfoKeyManager.transportType) && + Objects.equals(description, apIInfoKeyManager.description) && + Objects.equals(context, apIInfoKeyManager.context) && + Objects.equals(version, apIInfoKeyManager.version) && + Objects.equals(provider, apIInfoKeyManager.provider) && + Objects.equals(status, apIInfoKeyManager.status) && + Objects.equals(thumbnailUri, apIInfoKeyManager.thumbnailUri) && + Objects.equals(advertiseOnly, apIInfoKeyManager.advertiseOnly) && + Objects.equals(keyManagerEntry, apIInfoKeyManager.keyManagerEntry); + } + + @Override + public int hashCode() { + return Objects.hash(id, type, name, transportType, description, context, version, provider, status, thumbnailUri, advertiseOnly, keyManagerEntry); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class APIInfoKeyManagerDTO {\n"); + + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" transportType: ").append(toIndentedString(transportType)).append("\n"); + sb.append(" description: ").append(toIndentedString(description)).append("\n"); + sb.append(" context: ").append(toIndentedString(context)).append("\n"); + sb.append(" version: ").append(toIndentedString(version)).append("\n"); + sb.append(" provider: ").append(toIndentedString(provider)).append("\n"); + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append(" thumbnailUri: ").append(toIndentedString(thumbnailUri)).append("\n"); + sb.append(" advertiseOnly: ").append(toIndentedString(advertiseOnly)).append("\n"); + sb.append(" keyManagerEntry: ").append(toIndentedString(keyManagerEntry)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/ApplicationInfoKeyManagerDTO.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/ApplicationInfoKeyManagerDTO.java new file mode 100644 index 000000000000..9794d155c738 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/ApplicationInfoKeyManagerDTO.java @@ -0,0 +1,170 @@ +package org.wso2.carbon.apimgt.rest.api.admin.v1.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.*; + + +import io.swagger.annotations.*; +import java.util.Objects; + +import javax.xml.bind.annotation.*; +import org.wso2.carbon.apimgt.rest.api.common.annotations.Scope; +import com.fasterxml.jackson.annotation.JsonCreator; + +import javax.validation.Valid; + + + +public class ApplicationInfoKeyManagerDTO { + + private String name = null; + private String uuid = null; + private String organizationId = null; + private String owner = null; + private String organization = null; + + /** + * The name of the application. + **/ + public ApplicationInfoKeyManagerDTO name(String name) { + this.name = name; + return this; + } + + + @ApiModelProperty(required = true, value = "The name of the application.") + @JsonProperty("name") + @NotNull + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + /** + * The UUID of the application. + **/ + public ApplicationInfoKeyManagerDTO uuid(String uuid) { + this.uuid = uuid; + return this; + } + + + @ApiModelProperty(required = true, value = "The UUID of the application.") + @JsonProperty("uuid") + @NotNull + public String getUuid() { + return uuid; + } + public void setUuid(String uuid) { + this.uuid = uuid; + } + + /** + * The ID of the organization to which the application belongs. + **/ + public ApplicationInfoKeyManagerDTO organizationId(String organizationId) { + this.organizationId = organizationId; + return this; + } + + + @ApiModelProperty(value = "The ID of the organization to which the application belongs.") + @JsonProperty("organizationId") + public String getOrganizationId() { + return organizationId; + } + public void setOrganizationId(String organizationId) { + this.organizationId = organizationId; + } + + /** + * The owner of the application. + **/ + public ApplicationInfoKeyManagerDTO owner(String owner) { + this.owner = owner; + return this; + } + + + @ApiModelProperty(required = true, value = "The owner of the application.") + @JsonProperty("owner") + @NotNull + public String getOwner() { + return owner; + } + public void setOwner(String owner) { + this.owner = owner; + } + + /** + * The organization of the application. + **/ + public ApplicationInfoKeyManagerDTO organization(String organization) { + this.organization = organization; + return this; + } + + + @ApiModelProperty(required = true, value = "The organization of the application.") + @JsonProperty("organization") + @NotNull + public String getOrganization() { + return organization; + } + public void setOrganization(String organization) { + this.organization = organization; + } + + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ApplicationInfoKeyManagerDTO applicationInfoKeyManager = (ApplicationInfoKeyManagerDTO) o; + return Objects.equals(name, applicationInfoKeyManager.name) && + Objects.equals(uuid, applicationInfoKeyManager.uuid) && + Objects.equals(organizationId, applicationInfoKeyManager.organizationId) && + Objects.equals(owner, applicationInfoKeyManager.owner) && + Objects.equals(organization, applicationInfoKeyManager.organization); + } + + @Override + public int hashCode() { + return Objects.hash(name, uuid, organizationId, owner, organization); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class ApplicationInfoKeyManagerDTO {\n"); + + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" uuid: ").append(toIndentedString(uuid)).append("\n"); + sb.append(" organizationId: ").append(toIndentedString(organizationId)).append("\n"); + sb.append(" owner: ").append(toIndentedString(owner)).append("\n"); + sb.append(" organization: ").append(toIndentedString(organization)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/KeyManagerAPIUsagesDTO.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/KeyManagerAPIUsagesDTO.java new file mode 100644 index 000000000000..aba2cd60f80e --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/KeyManagerAPIUsagesDTO.java @@ -0,0 +1,108 @@ +package org.wso2.carbon.apimgt.rest.api.admin.v1.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import java.util.ArrayList; +import java.util.List; +import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.APIInfoKeyManagerDTO; +import javax.validation.constraints.*; + + +import io.swagger.annotations.*; +import java.util.Objects; + +import javax.xml.bind.annotation.*; +import org.wso2.carbon.apimgt.rest.api.common.annotations.Scope; +import com.fasterxml.jackson.annotation.JsonCreator; + +import javax.validation.Valid; + + + +public class KeyManagerAPIUsagesDTO { + + private Integer apiCount = null; + private List apis = new ArrayList(); + + /** + * The total count of APIs. + **/ + public KeyManagerAPIUsagesDTO apiCount(Integer apiCount) { + this.apiCount = apiCount; + return this; + } + + + @ApiModelProperty(required = true, value = "The total count of APIs.") + @JsonProperty("apiCount") + @NotNull + public Integer getApiCount() { + return apiCount; + } + public void setApiCount(Integer apiCount) { + this.apiCount = apiCount; + } + + /** + **/ + public KeyManagerAPIUsagesDTO apis(List apis) { + this.apis = apis; + return this; + } + + + @ApiModelProperty(required = true, value = "") + @Valid + @JsonProperty("apis") + @NotNull + public List getApis() { + return apis; + } + public void setApis(List apis) { + this.apis = apis; + } + + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + KeyManagerAPIUsagesDTO keyManagerAPIUsages = (KeyManagerAPIUsagesDTO) o; + return Objects.equals(apiCount, keyManagerAPIUsages.apiCount) && + Objects.equals(apis, keyManagerAPIUsages.apis); + } + + @Override + public int hashCode() { + return Objects.hash(apiCount, apis); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class KeyManagerAPIUsagesDTO {\n"); + + sb.append(" apiCount: ").append(toIndentedString(apiCount)).append("\n"); + sb.append(" apis: ").append(toIndentedString(apis)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/KeyManagerAppUsagesDTO.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/KeyManagerAppUsagesDTO.java new file mode 100644 index 000000000000..e767089ab236 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/KeyManagerAppUsagesDTO.java @@ -0,0 +1,108 @@ +package org.wso2.carbon.apimgt.rest.api.admin.v1.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import java.util.ArrayList; +import java.util.List; +import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ApplicationInfoKeyManagerDTO; +import javax.validation.constraints.*; + + +import io.swagger.annotations.*; +import java.util.Objects; + +import javax.xml.bind.annotation.*; +import org.wso2.carbon.apimgt.rest.api.common.annotations.Scope; +import com.fasterxml.jackson.annotation.JsonCreator; + +import javax.validation.Valid; + + + +public class KeyManagerAppUsagesDTO { + + private Integer applicationCount = null; + private List applications = new ArrayList(); + + /** + * The total count of applications. + **/ + public KeyManagerAppUsagesDTO applicationCount(Integer applicationCount) { + this.applicationCount = applicationCount; + return this; + } + + + @ApiModelProperty(required = true, value = "The total count of applications.") + @JsonProperty("applicationCount") + @NotNull + public Integer getApplicationCount() { + return applicationCount; + } + public void setApplicationCount(Integer applicationCount) { + this.applicationCount = applicationCount; + } + + /** + **/ + public KeyManagerAppUsagesDTO applications(List applications) { + this.applications = applications; + return this; + } + + + @ApiModelProperty(required = true, value = "") + @Valid + @JsonProperty("applications") + @NotNull + public List getApplications() { + return applications; + } + public void setApplications(List applications) { + this.applications = applications; + } + + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + KeyManagerAppUsagesDTO keyManagerAppUsages = (KeyManagerAppUsagesDTO) o; + return Objects.equals(applicationCount, keyManagerAppUsages.applicationCount) && + Objects.equals(applications, keyManagerAppUsages.applications); + } + + @Override + public int hashCode() { + return Objects.hash(applicationCount, applications); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class KeyManagerAppUsagesDTO {\n"); + + sb.append(" applicationCount: ").append(toIndentedString(applicationCount)).append("\n"); + sb.append(" applications: ").append(toIndentedString(applications)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/KeyManagerInfoDTO.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/KeyManagerInfoDTO.java index a2289f906e13..dcfa091db746 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/KeyManagerInfoDTO.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/KeyManagerInfoDTO.java @@ -26,6 +26,7 @@ public class KeyManagerInfoDTO { private String description = null; private Boolean enabled = null; private Boolean isGlobal = null; + private Boolean isUsed = null; @XmlType(name="TokenTypeEnum") @XmlEnum(String.class) @@ -164,6 +165,23 @@ public void setIsGlobal(Boolean isGlobal) { this.isGlobal = isGlobal; } + /** + **/ + public KeyManagerInfoDTO isUsed(Boolean isUsed) { + this.isUsed = isUsed; + return this; + } + + + @ApiModelProperty(example = "true", value = "") + @JsonProperty("isUsed") + public Boolean isIsUsed() { + return isUsed; + } + public void setIsUsed(Boolean isUsed) { + this.isUsed = isUsed; + } + /** * The type of the tokens to be used (exchanged or without exchanged). Accepted values are EXCHANGED, DIRECT and BOTH. **/ @@ -198,12 +216,13 @@ public boolean equals(java.lang.Object o) { Objects.equals(description, keyManagerInfo.description) && Objects.equals(enabled, keyManagerInfo.enabled) && Objects.equals(isGlobal, keyManagerInfo.isGlobal) && + Objects.equals(isUsed, keyManagerInfo.isUsed) && Objects.equals(tokenType, keyManagerInfo.tokenType); } @Override public int hashCode() { - return Objects.hash(id, name, type, description, enabled, isGlobal, tokenType); + return Objects.hash(id, name, type, description, enabled, isGlobal, isUsed, tokenType); } @Override @@ -217,6 +236,7 @@ public String toString() { sb.append(" description: ").append(toIndentedString(description)).append("\n"); sb.append(" enabled: ").append(toIndentedString(enabled)).append("\n"); sb.append(" isGlobal: ").append(toIndentedString(isGlobal)).append("\n"); + sb.append(" isUsed: ").append(toIndentedString(isUsed)).append("\n"); sb.append(" tokenType: ").append(toIndentedString(tokenType)).append("\n"); sb.append("}"); return sb.toString(); diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/GlobalKeyManagersApiServiceImpl.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/GlobalKeyManagersApiServiceImpl.java index f72ec8f91766..c198799da668 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/GlobalKeyManagersApiServiceImpl.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/GlobalKeyManagersApiServiceImpl.java @@ -59,7 +59,8 @@ public class GlobalKeyManagersApiServiceImpl implements GlobalKeyManagersApiServ public Response globalKeyManagersGet(MessageContext messageContext) throws APIManagementException { APIAdmin apiAdmin = new APIAdminImpl(); - List globalKeyManagerConfigurations = apiAdmin.getGlobalKeyManagerConfigurations(); + String tenantDomain = RestApiCommonUtil.getLoggedInUserTenantDomain(); + List globalKeyManagerConfigurations = apiAdmin.getGlobalKeyManagerConfigurations(tenantDomain); KeyManagerListDTO keyManagerListDTO = KeyManagerMappingUtil.toKeyManagerListDTO(globalKeyManagerConfigurations); return Response.ok().entity(keyManagerListDTO).build(); diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/KeyManagersApiServiceImpl.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/KeyManagersApiServiceImpl.java index fcbeed53a084..8097b6ec0478 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/KeyManagersApiServiceImpl.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/KeyManagersApiServiceImpl.java @@ -14,6 +14,8 @@ import org.wso2.carbon.apimgt.api.ExceptionCodes; import org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO; import org.wso2.carbon.apimgt.api.dto.KeyManagerPermissionConfigurationDTO; +import org.wso2.carbon.apimgt.api.model.ApplicationInfoKeyManager; +import org.wso2.carbon.apimgt.api.model.KeyManagerApplicationUsages; import org.wso2.carbon.apimgt.impl.APIAdminImpl; import org.wso2.carbon.apimgt.impl.APIConstants; import org.wso2.carbon.apimgt.impl.kmclient.ApacheFeignHttpClient; @@ -21,6 +23,7 @@ import org.wso2.carbon.apimgt.impl.kmclient.model.OpenIDConnectDiscoveryClient; import org.wso2.carbon.apimgt.impl.kmclient.model.OpenIdConnectConfiguration; import org.wso2.carbon.apimgt.impl.utils.APIUtil; +import org.wso2.carbon.apimgt.persistence.dto.AdminContentSearchResult; import org.wso2.carbon.apimgt.rest.api.admin.v1.KeyManagersApiService; import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerDTO; import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerListDTO; @@ -36,8 +39,6 @@ import java.util.List; import javax.ws.rs.core.Response; -import static org.wso2.carbon.utils.multitenancy.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME; - public class KeyManagersApiServiceImpl implements KeyManagersApiService { private static final Log log = LogFactory.getLog(KeyManagersApiServiceImpl.class); @@ -71,7 +72,7 @@ public Response keyManagersGet(MessageContext messageContext) throws APIManageme String organization = RestApiUtil.getOrganization(messageContext); APIAdmin apiAdmin = new APIAdminImpl(); List keyManagerConfigurationsByOrganization = - apiAdmin.getKeyManagerConfigurationsByOrganization(organization); + apiAdmin.getKeyManagerConfigurationsByOrganization(organization, true); KeyManagerListDTO keyManagerListDTO = KeyManagerMappingUtil.toKeyManagerListDTO(keyManagerConfigurationsByOrganization); return Response.ok().entity(keyManagerListDTO).build(); @@ -150,6 +151,48 @@ public Response keyManagersKeyManagerIdPut(String keyManagerId, KeyManagerDTO bo } } + @Override + public Response keyManagersKeyManagerIdApiUsagesGet(String keyManagerId, Integer offset, Integer limit, + MessageContext messageContext) throws APIManagementException { + + String organization = RestApiUtil.getOrganization(messageContext); + offset = offset != null ? offset : RestApiConstants.PAGINATION_OFFSET_DEFAULT; + APIAdminImpl apiAdmin = new APIAdminImpl(); + KeyManagerConfigurationDTO keyManager = apiAdmin.getKeyManagerConfigurationById(organization, keyManagerId); + if (keyManager == null) { + keyManager = apiAdmin.getGlobalKeyManagerConfigurationById(keyManagerId); + } + String KeyManagerName; + if (keyManager != null) { + KeyManagerName = keyManager.getName(); + } else { + throw new APIManagementException("Requested KeyManager not found", ExceptionCodes.KEY_MANAGER_NOT_FOUND); + } + AdminContentSearchResult result = apiAdmin.getAPIUsagesByKeyManagerNameAndOrganization(organization, + KeyManagerName, offset, limit); + + return Response.ok().entity(KeyManagerMappingUtil.toKeyManagerAPIUsagesDTO(result)).build(); + } + + @Override + public Response keyManagersKeyManagerIdAppUsagesGet(String keyManagerId, Integer offset, Integer limit, + MessageContext messageContext) throws APIManagementException { + + String organization = RestApiUtil.getOrganization(messageContext); + offset = offset != null ? offset : RestApiConstants.PAGINATION_OFFSET_DEFAULT; + limit = limit != null ? limit : Integer.MAX_VALUE; + APIAdminImpl apiAdmin = new APIAdminImpl(); + KeyManagerConfigurationDTO keyManager = apiAdmin.getKeyManagerConfigurationById(organization, keyManagerId); + if (keyManager == null) { + keyManager = apiAdmin.getGlobalKeyManagerConfigurationById(keyManagerId); + } + if (keyManager == null) { + throw new APIManagementException("Requested KeyManager not found", ExceptionCodes.KEY_MANAGER_NOT_FOUND); + } + KeyManagerApplicationUsages result = apiAdmin.getApplicationsOfKeyManager(keyManagerId, offset, limit); + return Response.ok().entity(KeyManagerMappingUtil.toKeyManagerAppUsagesDTO(result)).build(); + } + public Response keyManagersPost(KeyManagerDTO body, MessageContext messageContext) throws APIManagementException { String organization = RestApiUtil.getOrganization(messageContext); diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/mappings/KeyManagerMappingUtil.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/mappings/KeyManagerMappingUtil.java index f2bacd21caf2..42ec4fb3673c 100755 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/mappings/KeyManagerMappingUtil.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/mappings/KeyManagerMappingUtil.java @@ -9,9 +9,18 @@ import org.apache.commons.lang.StringUtils; import org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO; import org.wso2.carbon.apimgt.api.dto.KeyManagerPermissionConfigurationDTO; +import org.wso2.carbon.apimgt.api.model.ApplicationInfoKeyManager; +import org.wso2.carbon.apimgt.api.model.KeyManagerApplicationUsages; import org.wso2.carbon.apimgt.impl.APIConstants; import org.wso2.carbon.apimgt.impl.kmclient.model.OpenIdConnectConfiguration; +import org.wso2.carbon.apimgt.persistence.dto.AdminApiSearchContent; +import org.wso2.carbon.apimgt.persistence.dto.AdminContentSearchResult; +import org.wso2.carbon.apimgt.persistence.dto.SearchContent; +import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.APIInfoKeyManagerDTO; +import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ApplicationInfoKeyManagerDTO; import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ClaimMappingEntryDTO; +import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerAPIUsagesDTO; +import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerAppUsagesDTO; import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerCertificatesDTO; import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerDTO; import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerEndpointDTO; @@ -53,6 +62,7 @@ public static KeyManagerInfoDTO toKeyManagerInfoDTO(KeyManagerConfigurationDTO k keyManagerConfigurationDTO.getOrganization().equals(APIConstants.GLOBAL_KEY_MANAGER_TENANT_DOMAIN)); keyManagerInfoDTO.setTokenType(KeyManagerInfoDTO.TokenTypeEnum. fromValue(keyManagerConfigurationDTO.getTokenType())); + keyManagerInfoDTO.setIsUsed(keyManagerConfigurationDTO.getIsUsed()); return keyManagerInfoDTO; } @@ -374,4 +384,72 @@ public static KeyManagerWellKnownResponseDTO fromOpenIdConnectConfigurationToKey } return keyManagerWellKnownResponseDTO; } + + public static KeyManagerAPIUsagesDTO toKeyManagerAPIUsagesDTO(AdminContentSearchResult result) { + + KeyManagerAPIUsagesDTO keyManagerAPIUsagesDTO = new KeyManagerAPIUsagesDTO(); + List apis = new ArrayList<>(); + if (result != null) { + List searchContents = result.getApis(); + for (SearchContent searchContent : searchContents) { + if (searchContent instanceof AdminApiSearchContent) { + APIInfoKeyManagerDTO apiInfoKeyManagerDTO = toAPIInfoKeyManagerDTO( + (AdminApiSearchContent) searchContent); + apis.add(apiInfoKeyManagerDTO); + } + } + keyManagerAPIUsagesDTO.setApiCount(result.getApiTotal()); + keyManagerAPIUsagesDTO.setApis(apis); + } + return keyManagerAPIUsagesDTO; + } + + public static APIInfoKeyManagerDTO toAPIInfoKeyManagerDTO(AdminApiSearchContent adminApiSearchContent) { + + APIInfoKeyManagerDTO apiInfoKeyManagerDTO = new APIInfoKeyManagerDTO(); + apiInfoKeyManagerDTO.setId(adminApiSearchContent.getId()); + apiInfoKeyManagerDTO.setType(adminApiSearchContent.getType()); + apiInfoKeyManagerDTO.setName(adminApiSearchContent.getName()); + apiInfoKeyManagerDTO.setTransportType(adminApiSearchContent.getTransportType()); + apiInfoKeyManagerDTO.setDescription(adminApiSearchContent.getDescription()); + apiInfoKeyManagerDTO.setContext(adminApiSearchContent.getContext()); + apiInfoKeyManagerDTO.setVersion(adminApiSearchContent.getVersion()); + apiInfoKeyManagerDTO.setProvider(adminApiSearchContent.getProvider()); + apiInfoKeyManagerDTO.setStatus(adminApiSearchContent.getStatus()); + apiInfoKeyManagerDTO.setThumbnailUri(adminApiSearchContent.getThumbnailUri()); + apiInfoKeyManagerDTO.setAdvertiseOnly(adminApiSearchContent.getAdvertiseOnly()); + apiInfoKeyManagerDTO.setKeyManagerEntry(adminApiSearchContent.getKeyManagerEntry()); + + return apiInfoKeyManagerDTO; + } + + public static KeyManagerAppUsagesDTO toKeyManagerAppUsagesDTO( + KeyManagerApplicationUsages keyManagerApplicationUsages) { + + KeyManagerAppUsagesDTO keyManagerAppUsagesDTO = new KeyManagerAppUsagesDTO(); + List applicationDTOs = new ArrayList<>(); + if (keyManagerApplicationUsages != null) { + List applications = keyManagerApplicationUsages.getApplications(); + for (ApplicationInfoKeyManager application : applications) { + ApplicationInfoKeyManagerDTO applicationInfoKeyManagerDTO = toApplicationInfoKeyManagerDTO(application); + applicationDTOs.add(applicationInfoKeyManagerDTO); + } + keyManagerAppUsagesDTO.setApplicationCount(keyManagerApplicationUsages.getApplicationCount()); + keyManagerAppUsagesDTO.setApplications(applicationDTOs); + } + return keyManagerAppUsagesDTO; + } + + public static ApplicationInfoKeyManagerDTO toApplicationInfoKeyManagerDTO( + ApplicationInfoKeyManager applicationInfoKeyManager) { + + ApplicationInfoKeyManagerDTO applicationInfoKeyManagerDTO = new ApplicationInfoKeyManagerDTO(); + applicationInfoKeyManagerDTO.setName(applicationInfoKeyManager.getName()); + applicationInfoKeyManagerDTO.setUuid(applicationInfoKeyManager.getUuid()); + applicationInfoKeyManagerDTO.setOrganization(applicationInfoKeyManager.getOrganization()); + applicationInfoKeyManagerDTO.setOrganizationId(applicationInfoKeyManager.getOrganizationId()); + applicationInfoKeyManagerDTO.setOwner(applicationInfoKeyManager.getOwner()); + + return applicationInfoKeyManagerDTO; + } } diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/resources/admin-api.yaml b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/resources/admin-api.yaml index 9ab2731e5ae0..b41dbbd40989 100755 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/resources/admin-api.yaml +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/resources/admin-api.yaml @@ -3397,6 +3397,86 @@ paths: source: 'curl -k -X POST -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" -F "type=WSO2-IS" "https://127.0.0.1:9443/api/am/admin/v4/key-managers/discover"' + /key-managers/{keyManagerId}/api-usages: + get: + tags: + - Key Manager (Individual) + summary: Retrieve Key Manager Usages (APIs) + description: | + Retrieves a list of APIs that are specifically utilizing the Key Manager identified by the provided ID. + The Key Manager ID should be provided as a path parameter. + parameters: + - $ref: '#/components/parameters/offset' + - $ref: '#/components/parameters/limit' + - $ref: '#/components/parameters/keyManagerId' + responses: + 200: + description: | + OK. + KeyManager API usages returned. + headers: + Content-Type: + description: | + The content type of the body. + schema: + type: string + content: + application/json: + schema: + $ref: '#/components/schemas/KeyManagerAPIUsages' + 404: + $ref: '#/components/responses/NotFound' + 406: + $ref: '#/components/responses/NotAcceptable' + security: + - OAuth2Security: + - apim:admin + - apim:admin_operations + x-code-samples: + - lang: Curl + source: 'curl -k -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" + "https://127.0.0.1:9443/api/am/admin/v4/key-managers/8d263942-a6df-4cc2-a804-7a2525501450/api-usages"' + + /key-managers/{keyManagerId}/app-usages: + get: + tags: + - Key Manager (Individual) + summary: Retrieve Key Manager Usages (Appilcations) + description: | + Retrieves a list of Applications that are specifically utilizing the Key Manager identified by the provided ID. + The Key Manager ID should be provided as a path parameter. + parameters: + - $ref: '#/components/parameters/offset' + - $ref: '#/components/parameters/limit' + - $ref: '#/components/parameters/keyManagerId' + responses: + 200: + description: | + OK. + KeyManager application usages returned. + headers: + Content-Type: + description: | + The content type of the body. + schema: + type: string + content: + application/json: + schema: + $ref: '#/components/schemas/KeyManagerAppUsages' + 404: + $ref: '#/components/responses/NotFound' + 406: + $ref: '#/components/responses/NotAcceptable' + security: + - OAuth2Security: + - apim:admin + - apim:admin_operations + x-code-samples: + - lang: Curl + source: 'curl -k -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" + "https://127.0.0.1:9443/api/am/admin/v4/key-managers/8d263942-a6df-4cc2-a804-7a2525501450/app-usages"' + ###################################################### # The "API Collection" resource APIs ###################################################### @@ -4893,6 +4973,9 @@ components: isGlobal: type: boolean example: true + isUsed: + type: boolean + example: true tokenType: type: string description: The type of the tokens to be used (exchanged or without exchanged). @@ -4950,6 +5033,109 @@ components: type: array items: $ref: '#/components/schemas/KeyManagerInfo' + + KeyManagerAppUsages: + title: Key Manager Application Usages. + required: + - applicationCount + - applications + type: object + properties: + applicationCount: + type: integer + description: The total count of applications. + applications: + type: array + items: + $ref: '#/components/schemas/ApplicationInfoKeyManager' + + ApplicationInfoKeyManager: + type: object + properties: + name: + type: string + description: The name of the application. + uuid: + type: string + description: The UUID of the application. + organizationId: + type: string + nullable: true + description: The ID of the organization to which the application belongs. + owner: + type: string + description: The owner of the application. + organization: + type: string + description: The organization of the application. + required: + - name + - uuid + - owner + - organization + + KeyManagerAPIUsages: + title: Key Manager API Usages. + required: + - apiCount + - apis + type: object + properties: + apiCount: + type: integer + description: The total count of APIs. + apis: + type: array + items: + $ref: '#/components/schemas/APIInfoKeyManager' + + APIInfoKeyManager: + type: object + properties: + id: + type: string + description: The ID of the API. + type: + type: string + description: The type of the entry (e.g., "API"). + name: + type: string + description: The name of the API. + transportType: + type: string + description: The transport type of the API. + description: + type: string + nullable: true + description: The description of the API. + context: + type: string + description: The context of the API. + version: + type: string + description: The version of the API. + provider: + type: string + description: The provider of the API. + status: + type: string + description: The status of the API. + thumbnailUri: + type: string + nullable: true + description: The URI of the thumbnail of the API. + advertiseOnly: + type: boolean + description: Indicates if the API is advertised only. + keyManagerEntry: + type: string + description: The key manager entry related to the API. + required: + - id + - name + - version + - provider + ClaimMappingEntry: title: Claim Mapping Configuration type: object diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/admin-api.yaml b/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/admin-api.yaml index 9ab2731e5ae0..b41dbbd40989 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/admin-api.yaml +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/admin-api.yaml @@ -3397,6 +3397,86 @@ paths: source: 'curl -k -X POST -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" -F "type=WSO2-IS" "https://127.0.0.1:9443/api/am/admin/v4/key-managers/discover"' + /key-managers/{keyManagerId}/api-usages: + get: + tags: + - Key Manager (Individual) + summary: Retrieve Key Manager Usages (APIs) + description: | + Retrieves a list of APIs that are specifically utilizing the Key Manager identified by the provided ID. + The Key Manager ID should be provided as a path parameter. + parameters: + - $ref: '#/components/parameters/offset' + - $ref: '#/components/parameters/limit' + - $ref: '#/components/parameters/keyManagerId' + responses: + 200: + description: | + OK. + KeyManager API usages returned. + headers: + Content-Type: + description: | + The content type of the body. + schema: + type: string + content: + application/json: + schema: + $ref: '#/components/schemas/KeyManagerAPIUsages' + 404: + $ref: '#/components/responses/NotFound' + 406: + $ref: '#/components/responses/NotAcceptable' + security: + - OAuth2Security: + - apim:admin + - apim:admin_operations + x-code-samples: + - lang: Curl + source: 'curl -k -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" + "https://127.0.0.1:9443/api/am/admin/v4/key-managers/8d263942-a6df-4cc2-a804-7a2525501450/api-usages"' + + /key-managers/{keyManagerId}/app-usages: + get: + tags: + - Key Manager (Individual) + summary: Retrieve Key Manager Usages (Appilcations) + description: | + Retrieves a list of Applications that are specifically utilizing the Key Manager identified by the provided ID. + The Key Manager ID should be provided as a path parameter. + parameters: + - $ref: '#/components/parameters/offset' + - $ref: '#/components/parameters/limit' + - $ref: '#/components/parameters/keyManagerId' + responses: + 200: + description: | + OK. + KeyManager application usages returned. + headers: + Content-Type: + description: | + The content type of the body. + schema: + type: string + content: + application/json: + schema: + $ref: '#/components/schemas/KeyManagerAppUsages' + 404: + $ref: '#/components/responses/NotFound' + 406: + $ref: '#/components/responses/NotAcceptable' + security: + - OAuth2Security: + - apim:admin + - apim:admin_operations + x-code-samples: + - lang: Curl + source: 'curl -k -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" + "https://127.0.0.1:9443/api/am/admin/v4/key-managers/8d263942-a6df-4cc2-a804-7a2525501450/app-usages"' + ###################################################### # The "API Collection" resource APIs ###################################################### @@ -4893,6 +4973,9 @@ components: isGlobal: type: boolean example: true + isUsed: + type: boolean + example: true tokenType: type: string description: The type of the tokens to be used (exchanged or without exchanged). @@ -4950,6 +5033,109 @@ components: type: array items: $ref: '#/components/schemas/KeyManagerInfo' + + KeyManagerAppUsages: + title: Key Manager Application Usages. + required: + - applicationCount + - applications + type: object + properties: + applicationCount: + type: integer + description: The total count of applications. + applications: + type: array + items: + $ref: '#/components/schemas/ApplicationInfoKeyManager' + + ApplicationInfoKeyManager: + type: object + properties: + name: + type: string + description: The name of the application. + uuid: + type: string + description: The UUID of the application. + organizationId: + type: string + nullable: true + description: The ID of the organization to which the application belongs. + owner: + type: string + description: The owner of the application. + organization: + type: string + description: The organization of the application. + required: + - name + - uuid + - owner + - organization + + KeyManagerAPIUsages: + title: Key Manager API Usages. + required: + - apiCount + - apis + type: object + properties: + apiCount: + type: integer + description: The total count of APIs. + apis: + type: array + items: + $ref: '#/components/schemas/APIInfoKeyManager' + + APIInfoKeyManager: + type: object + properties: + id: + type: string + description: The ID of the API. + type: + type: string + description: The type of the entry (e.g., "API"). + name: + type: string + description: The name of the API. + transportType: + type: string + description: The transport type of the API. + description: + type: string + nullable: true + description: The description of the API. + context: + type: string + description: The context of the API. + version: + type: string + description: The version of the API. + provider: + type: string + description: The provider of the API. + status: + type: string + description: The status of the API. + thumbnailUri: + type: string + nullable: true + description: The URI of the thumbnail of the API. + advertiseOnly: + type: boolean + description: Indicates if the API is advertised only. + keyManagerEntry: + type: string + description: The key manager entry related to the API. + required: + - id + - name + - version + - provider + ClaimMappingEntry: title: Claim Mapping Configuration type: object diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/devportal-api.yaml b/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/devportal-api.yaml index bcc658caffba..36a958c7f45f 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/devportal-api.yaml +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/devportal-api.yaml @@ -2185,6 +2185,38 @@ paths: source: 'curl -k -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" -H "Content-Type: application/json" -X PUT -d @data.json "https://localhost:9443/api/am/devportal/v3/applications/16cd2684-9657-4a01-a956-4efd89e96077/oauth-keys/df972173-c957-46d4-96ac-99be8e303584"' + delete: + tags: + - Application Keys + summary: Remove Generated Application Keys + description: | + Remove generated application keys from dev portal rest api + parameters: + - $ref: '#/components/parameters/applicationId' + - $ref: '#/components/parameters/keyMappingId' + - $ref: '#/components/parameters/requestedTenant' + responses: + 200: + description: | + OK. + Key removed successfully. + content: { } + 400: + $ref: '#/components/responses/BadRequest' + 404: + $ref: '#/components/responses/NotFound' + 412: + $ref: '#/components/responses/PreconditionFailed' + security: + - OAuth2Security: + - apim:subscribe + - apim:app_manage + x-code-samples: + - lang: Curl + source: 'curl -k -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" + -H "Content-Type: application/json" -X DELETE "https://localhost:9443/api/am/devportal/v3/applications/16cd2684-9657-4a01-a956-4efd89e96077/oauth-keys/df972173-c957-46d4-96ac-99be8e303584"' + + /applications/{applicationId}/oauth-keys/{keyMappingId}/regenerate-secret: post: tags: diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/impl/KeyManagersApiServiceImpl.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/impl/KeyManagersApiServiceImpl.java index 406470d72579..dbecf0620521 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/impl/KeyManagersApiServiceImpl.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/impl/KeyManagersApiServiceImpl.java @@ -40,7 +40,7 @@ public Response getAllKeyManagers(MessageContext messageContext) throws APIManag String organization = RestApiUtil.getOrganization(messageContext); APIAdmin apiAdmin = new APIAdminImpl(); List keyManagerConfigurations = - apiAdmin.getKeyManagerConfigurationsByOrganization(organization); + apiAdmin.getKeyManagerConfigurationsByOrganization(organization, false); List globalKeyManagerConfigurations = apiAdmin.getGlobalKeyManagerConfigurations(); keyManagerConfigurations.addAll(globalKeyManagerConfigurations); return Response.ok(KeyManagerMappingUtil.toKeyManagerListDto(keyManagerConfigurations)).build(); diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/store/v1/ApplicationsApi.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/store/v1/ApplicationsApi.java index be26588c01e7..a6150706f789 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/store/v1/ApplicationsApi.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/store/v1/ApplicationsApi.java @@ -319,6 +319,25 @@ public Response applicationsApplicationIdOauthKeysGet(@ApiParam(value = "Applica return delegate.applicationsApplicationIdOauthKeysKeyMappingIdCleanUpPost(applicationId, keyMappingId, ifMatch, securityContext); } + @DELETE + @Path("/{applicationId}/oauth-keys/{keyMappingId}") + + @Produces({ "application/json" }) + @ApiOperation(value = "Remove Generated Application Keys", notes = "Remove generated application keys from dev portal rest api ", response = Void.class, authorizations = { + @Authorization(value = "OAuth2Security", scopes = { + @AuthorizationScope(scope = "apim:subscribe", description = "Subscribe API"), + @AuthorizationScope(scope = "apim:app_manage", description = "Retrieve, Manage and Import, Export applications") + }) + }, tags={ "Application Keys", }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "OK. Key removed successfully. ", response = Void.class), + @ApiResponse(code = 400, message = "Bad Request. Invalid request or validation error.", response = ErrorDTO.class), + @ApiResponse(code = 404, message = "Not Found. The specified resource does not exist.", response = ErrorDTO.class), + @ApiResponse(code = 412, message = "Precondition Failed. The request has not been performed because one of the preconditions is not met.", response = ErrorDTO.class) }) + public Response applicationsApplicationIdOauthKeysKeyMappingIdDelete(@ApiParam(value = "Application Identifier consisting of the UUID of the Application. ",required=true) @PathParam("applicationId") String applicationId, @ApiParam(value = "OAuth Key Identifier consisting of the UUID of the Oauth Key Mapping. ",required=true) @PathParam("keyMappingId") String keyMappingId, @ApiParam(value = "For cross-tenant invocations, this is used to specify the tenant domain, where the resource need to be retrieved from. " )@HeaderParam("X-WSO2-Tenant") String xWSO2Tenant) throws APIManagementException{ + return delegate.applicationsApplicationIdOauthKeysKeyMappingIdDelete(applicationId, keyMappingId, xWSO2Tenant, securityContext); + } + @POST @Path("/{applicationId}/oauth-keys/{keyMappingId}/generate-token") @Consumes({ "application/json" }) diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/store/v1/ApplicationsApiService.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/store/v1/ApplicationsApiService.java index cf3d21f493c1..965e308306f4 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/store/v1/ApplicationsApiService.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/store/v1/ApplicationsApiService.java @@ -50,6 +50,7 @@ public interface ApplicationsApiService { public Response applicationsApplicationIdMapKeysPost(String applicationId, ApplicationKeyMappingRequestDTO applicationKeyMappingRequestDTO, String xWSO2Tenant, MessageContext messageContext) throws APIManagementException; public Response applicationsApplicationIdOauthKeysGet(String applicationId, String xWSO2Tenant, MessageContext messageContext) throws APIManagementException; public Response applicationsApplicationIdOauthKeysKeyMappingIdCleanUpPost(String applicationId, String keyMappingId, String ifMatch, MessageContext messageContext) throws APIManagementException; + public Response applicationsApplicationIdOauthKeysKeyMappingIdDelete(String applicationId, String keyMappingId, String xWSO2Tenant, MessageContext messageContext) throws APIManagementException; public Response applicationsApplicationIdOauthKeysKeyMappingIdGenerateTokenPost(String applicationId, String keyMappingId, ApplicationTokenGenerateRequestDTO applicationTokenGenerateRequestDTO, String ifMatch, MessageContext messageContext) throws APIManagementException; public Response applicationsApplicationIdOauthKeysKeyMappingIdGet(String applicationId, String keyMappingId, String groupId, MessageContext messageContext) throws APIManagementException; public Response applicationsApplicationIdOauthKeysKeyMappingIdPut(String applicationId, String keyMappingId, ApplicationKeyDTO applicationKeyDTO, MessageContext messageContext) throws APIManagementException; diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/impl/ApplicationsApiServiceImpl.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/impl/ApplicationsApiServiceImpl.java index 4896b4c5eabf..42882fdc900e 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/impl/ApplicationsApiServiceImpl.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/impl/ApplicationsApiServiceImpl.java @@ -1200,6 +1200,27 @@ public Response applicationsApplicationIdOauthKeysKeyMappingIdCleanUpPost(String return null; } + @Override + public Response applicationsApplicationIdOauthKeysKeyMappingIdDelete(String applicationId, String keyMappingId, + String xWSO2Tenant, MessageContext messageContext) throws APIManagementException { + + String username = RestApiCommonUtil.getLoggedInUsername(); + try { + APIConsumer apiConsumer = APIManagerFactory.getInstance().getAPIConsumer(username); + Application application = apiConsumer.getLightweightApplicationByUUID(applicationId); + boolean result = apiConsumer.removalKeys(application, keyMappingId, xWSO2Tenant); + if (result) { + return Response.ok().build(); + } else { + RestApiUtil.handleResourceNotFoundError(ExceptionCodes.KEYS_DELETE_FAILED.getErrorMessage(), + keyMappingId, log); + } + } catch (APIManagementException e) { + RestApiUtil.handleInternalServerError("Error occurred while application key delete process", e, log); + } + return null; + } + @Override public Response applicationsApplicationIdOauthKeysKeyMappingIdGenerateTokenPost(String applicationId, String keyMappingId, diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/resources/devportal-api.yaml b/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/resources/devportal-api.yaml index bcc658caffba..36a958c7f45f 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/resources/devportal-api.yaml +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/resources/devportal-api.yaml @@ -2185,6 +2185,38 @@ paths: source: 'curl -k -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" -H "Content-Type: application/json" -X PUT -d @data.json "https://localhost:9443/api/am/devportal/v3/applications/16cd2684-9657-4a01-a956-4efd89e96077/oauth-keys/df972173-c957-46d4-96ac-99be8e303584"' + delete: + tags: + - Application Keys + summary: Remove Generated Application Keys + description: | + Remove generated application keys from dev portal rest api + parameters: + - $ref: '#/components/parameters/applicationId' + - $ref: '#/components/parameters/keyMappingId' + - $ref: '#/components/parameters/requestedTenant' + responses: + 200: + description: | + OK. + Key removed successfully. + content: { } + 400: + $ref: '#/components/responses/BadRequest' + 404: + $ref: '#/components/responses/NotFound' + 412: + $ref: '#/components/responses/PreconditionFailed' + security: + - OAuth2Security: + - apim:subscribe + - apim:app_manage + x-code-samples: + - lang: Curl + source: 'curl -k -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" + -H "Content-Type: application/json" -X DELETE "https://localhost:9443/api/am/devportal/v3/applications/16cd2684-9657-4a01-a956-4efd89e96077/oauth-keys/df972173-c957-46d4-96ac-99be8e303584"' + + /applications/{applicationId}/oauth-keys/{keyMappingId}/regenerate-secret: post: tags: