From 49aba2fc93611e7ddab0552710a38db66e812b30 Mon Sep 17 00:00:00 2001 From: CrowleyRajapakse Date: Thu, 21 Mar 2024 12:03:59 +0530 Subject: [PATCH] adding API Read Only Mode configuration --- .../wso2/carbon/apimgt/impl/APIConstants.java | 1 + .../carbon/apimgt/impl/utils/APIUtil.java | 16 +++++++++++++ .../src/main/resources/publisher-api.yaml | 6 +++++ .../api/publisher/v1/dto/SettingsDTO.java | 23 ++++++++++++++++++- .../common/mappings/SettingsMappingUtil.java | 1 + .../src/main/resources/publisher-api.yaml | 6 +++++ .../repository/conf/api-manager.xml.j2 | 1 + .../src/main/resources/config/api-manager.xml | 1 + 8 files changed, 54 insertions(+), 1 deletion(-) 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 54025328e251..d83e0ae63c09 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 @@ -859,6 +859,7 @@ private Permissions() { public static final String API_PUBLISHER_URL = API_PUBLISHER + "URL"; public static final String API_PUBLISHER_ENABLE_API_DOC_VISIBILITY_LEVELS = API_PUBLISHER + "EnableAPIDocVisibilityLevels"; + public static final String API_PUBLISHER_ENABLE_PORTAL_CONFIGURATION_ONLY_MODE = API_PUBLISHER + "EnablePortalConfigurationOnlyMode"; // Configuration that need to enable to add access control to APIs in publisher public static final String API_PUBLISHER_ENABLE_ACCESS_CONTROL_LEVELS = API_PUBLISHER + "EnableAccessControl"; 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 6a43f7b4444d..a4de89e0841f 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 @@ -2050,6 +2050,22 @@ public static boolean isDocVisibilityLevelsEnabled() { APIConstants.API_PUBLISHER_ENABLE_API_DOC_VISIBILITY_LEVELS).equals("true"); } + /** + * Check if Portal Configuration Only Mode is enabled + * + * @return True if Portal Configuration Only Mode is enabled + */ + public static boolean isPortalConfigurationOnlyModeEnabled() { + // checking if API Read Only Mode is enabled in api-manager.xml + String isPortalConfigurationOnlyModeEnabled = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService(). + getAPIManagerConfiguration().getFirstProperty( + APIConstants.API_PUBLISHER_ENABLE_PORTAL_CONFIGURATION_ONLY_MODE); + if (StringUtils.isNotEmpty(isPortalConfigurationOnlyModeEnabled)) { + return Boolean.parseBoolean(isPortalConfigurationOnlyModeEnabled); + } + return false; + } + /** * Returns the External API Store Configuration with the given Store Name * diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/publisher-api.yaml b/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/publisher-api.yaml index 75eab8f574dd..aaf9ca9c34fc 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/publisher-api.yaml +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/publisher-api.yaml @@ -11906,6 +11906,12 @@ components: description: | Is Document Visibility configuration enabled example: false + portalConfigurationOnlyModeEnabled: + type: boolean + description: | + Is Portal Configuration Only Mode enabled + example: false + default: false crossTenantSubscriptionEnabled: type: boolean description: | diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/dto/SettingsDTO.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/dto/SettingsDTO.java index 61018a6dfad7..fd6c63149aaf 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/dto/SettingsDTO.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/dto/SettingsDTO.java @@ -35,6 +35,7 @@ public class SettingsDTO { private Object securityAuditProperties = null; private Boolean externalStoresEnabled = null; private Boolean docVisibilityEnabled = null; + private Boolean portalConfigurationOnlyModeEnabled = false; private Boolean crossTenantSubscriptionEnabled = false; private String defaultAdvancePolicy = null; private String defaultSubscriptionPolicy = null; @@ -202,6 +203,24 @@ public void setDocVisibilityEnabled(Boolean docVisibilityEnabled) { this.docVisibilityEnabled = docVisibilityEnabled; } + /** + * Is Portal Configuration Only Mode enabled + **/ + public SettingsDTO portalConfigurationOnlyModeEnabled(Boolean portalConfigurationOnlyModeEnabled) { + this.portalConfigurationOnlyModeEnabled = portalConfigurationOnlyModeEnabled; + return this; + } + + + @ApiModelProperty(example = "false", value = "Is Portal Configuration Only Mode enabled ") + @JsonProperty("portalConfigurationOnlyModeEnabled") + public Boolean isPortalConfigurationOnlyModeEnabled() { + return portalConfigurationOnlyModeEnabled; + } + public void setPortalConfigurationOnlyModeEnabled(Boolean portalConfigurationOnlyModeEnabled) { + this.portalConfigurationOnlyModeEnabled = portalConfigurationOnlyModeEnabled; + } + /** * Is Cross Tenant Subscriptions Enabled **/ @@ -328,6 +347,7 @@ public boolean equals(java.lang.Object o) { Objects.equals(securityAuditProperties, settings.securityAuditProperties) && Objects.equals(externalStoresEnabled, settings.externalStoresEnabled) && Objects.equals(docVisibilityEnabled, settings.docVisibilityEnabled) && + Objects.equals(portalConfigurationOnlyModeEnabled, settings.portalConfigurationOnlyModeEnabled) && Objects.equals(crossTenantSubscriptionEnabled, settings.crossTenantSubscriptionEnabled) && Objects.equals(defaultAdvancePolicy, settings.defaultAdvancePolicy) && Objects.equals(defaultSubscriptionPolicy, settings.defaultSubscriptionPolicy) && @@ -338,7 +358,7 @@ public boolean equals(java.lang.Object o) { @Override public int hashCode() { - return Objects.hash(devportalUrl, environment, gatewayTypes, scopes, monetizationAttributes, subscriberContactAttributes, securityAuditProperties, externalStoresEnabled, docVisibilityEnabled, crossTenantSubscriptionEnabled, defaultAdvancePolicy, defaultSubscriptionPolicy, authorizationHeader, isJWTEnabledForLoginTokens, customProperties); + return Objects.hash(devportalUrl, environment, gatewayTypes, scopes, monetizationAttributes, subscriberContactAttributes, securityAuditProperties, externalStoresEnabled, docVisibilityEnabled, portalConfigurationOnlyModeEnabled, crossTenantSubscriptionEnabled, defaultAdvancePolicy, defaultSubscriptionPolicy, authorizationHeader, isJWTEnabledForLoginTokens, customProperties); } @Override @@ -355,6 +375,7 @@ public String toString() { sb.append(" securityAuditProperties: ").append(toIndentedString(securityAuditProperties)).append("\n"); sb.append(" externalStoresEnabled: ").append(toIndentedString(externalStoresEnabled)).append("\n"); sb.append(" docVisibilityEnabled: ").append(toIndentedString(docVisibilityEnabled)).append("\n"); + sb.append(" portalConfigurationOnlyModeEnabled: ").append(toIndentedString(portalConfigurationOnlyModeEnabled)).append("\n"); sb.append(" crossTenantSubscriptionEnabled: ").append(toIndentedString(crossTenantSubscriptionEnabled)).append("\n"); sb.append(" defaultAdvancePolicy: ").append(toIndentedString(defaultAdvancePolicy)).append("\n"); sb.append(" defaultSubscriptionPolicy: ").append(toIndentedString(defaultSubscriptionPolicy)).append("\n"); diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/SettingsMappingUtil.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/SettingsMappingUtil.java index 14ca2cc316bb..87156e0d8958 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/SettingsMappingUtil.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/SettingsMappingUtil.java @@ -87,6 +87,7 @@ public SettingsDTO fromSettingstoDTO(Boolean isUserAvailable, String organizatio settingsDTO.setExternalStoresEnabled( APIUtil.isExternalStoresEnabled(RestApiCommonUtil.getLoggedInUserTenantDomain())); settingsDTO.setDocVisibilityEnabled(APIUtil.isDocVisibilityLevelsEnabled()); + settingsDTO.setPortalConfigurationOnlyModeEnabled(APIUtil.isPortalConfigurationOnlyModeEnabled()); settingsDTO.setCrossTenantSubscriptionEnabled(APIUtil.isCrossTenantSubscriptionsEnabled()); Map gatewayEnvironments = APIUtil.getReadOnlyGatewayEnvironments(); String authorizationHeader = APIUtil.getOAuthConfiguration(loggedInUserTenantDomain, diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/resources/publisher-api.yaml b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/resources/publisher-api.yaml index 75eab8f574dd..aaf9ca9c34fc 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/resources/publisher-api.yaml +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/resources/publisher-api.yaml @@ -11906,6 +11906,12 @@ components: description: | Is Document Visibility configuration enabled example: false + portalConfigurationOnlyModeEnabled: + type: boolean + description: | + Is Portal Configuration Only Mode enabled + example: false + default: false crossTenantSubscriptionEnabled: type: boolean description: | diff --git a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/conf_templates/templates/repository/conf/api-manager.xml.j2 b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/conf_templates/templates/repository/conf/api-manager.xml.j2 index 11248a7067b8..3b95d7839494 100644 --- a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/conf_templates/templates/repository/conf/api-manager.xml.j2 +++ b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/conf_templates/templates/repository/conf/api-manager.xml.j2 @@ -539,6 +539,7 @@ property,it will show two additional permission levels as visible only to all registered users in a particular domain or only visible to API doc creator --> {{apim.publisher.enable_api_doc_visibility}} + {{apim.publisher.enable_portal_configuration_only_mode}} diff --git a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/config/api-manager.xml b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/config/api-manager.xml index 633f4015d05a..9432cf9260c4 100644 --- a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/config/api-manager.xml +++ b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/config/api-manager.xml @@ -327,6 +327,7 @@ property,it will show two additional permission levels as visible only to all registered users in a particular domain or only visible to API doc creator --> +