Skip to content

Commit

Permalink
adding API Read Only Mode configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
CrowleyRajapakse committed Mar 21, 2024
1 parent 047ffd0 commit 49aba2f
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(

Check warning on line 2061 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java#L2060-L2061

Added lines #L2060 - L2061 were not covered by tests
APIConstants.API_PUBLISHER_ENABLE_PORTAL_CONFIGURATION_ONLY_MODE);
if (StringUtils.isNotEmpty(isPortalConfigurationOnlyModeEnabled)) {
return Boolean.parseBoolean(isPortalConfigurationOnlyModeEnabled);

Check warning on line 2064 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java#L2064

Added line #L2064 was not covered by tests
}
return false;

Check warning on line 2066 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java#L2066

Added line #L2066 was not covered by tests
}

/**
* Returns the External API Store Configuration with the given Store Name
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class SettingsDTO {
private Object securityAuditProperties = null;
private Boolean externalStoresEnabled = null;
private Boolean docVisibilityEnabled = null;
private Boolean portalConfigurationOnlyModeEnabled = false;

Check warning on line 38 in 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

View check run for this annotation

Codecov / codecov/patch

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#L38

Added line #L38 was not covered by tests
private Boolean crossTenantSubscriptionEnabled = false;
private String defaultAdvancePolicy = null;
private String defaultSubscriptionPolicy = null;
Expand Down Expand Up @@ -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;

Check warning on line 211 in 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

View check run for this annotation

Codecov / codecov/patch

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#L210-L211

Added lines #L210 - L211 were not covered by tests
}


@ApiModelProperty(example = "false", value = "Is Portal Configuration Only Mode enabled ")
@JsonProperty("portalConfigurationOnlyModeEnabled")
public Boolean isPortalConfigurationOnlyModeEnabled() {
return portalConfigurationOnlyModeEnabled;

Check warning on line 218 in 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

View check run for this annotation

Codecov / codecov/patch

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#L218

Added line #L218 was not covered by tests
}
public void setPortalConfigurationOnlyModeEnabled(Boolean portalConfigurationOnlyModeEnabled) {
this.portalConfigurationOnlyModeEnabled = portalConfigurationOnlyModeEnabled;
}

Check warning on line 222 in 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

View check run for this annotation

Codecov / codecov/patch

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#L221-L222

Added lines #L221 - L222 were not covered by tests

/**
* Is Cross Tenant Subscriptions Enabled
**/
Expand Down Expand Up @@ -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) &&
Expand All @@ -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);

Check warning on line 361 in 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

View check run for this annotation

Codecov / codecov/patch

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#L361

Added line #L361 was not covered by tests
}

@Override
Expand All @@ -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");

Check warning on line 378 in 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

View check run for this annotation

Codecov / codecov/patch

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#L378

Added line #L378 was not covered by tests
sb.append(" crossTenantSubscriptionEnabled: ").append(toIndentedString(crossTenantSubscriptionEnabled)).append("\n");
sb.append(" defaultAdvancePolicy: ").append(toIndentedString(defaultAdvancePolicy)).append("\n");
sb.append(" defaultSubscriptionPolicy: ").append(toIndentedString(defaultSubscriptionPolicy)).append("\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Check warning on line 90 in 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

View check run for this annotation

Codecov / codecov/patch

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#L90

Added line #L90 was not covered by tests
settingsDTO.setCrossTenantSubscriptionEnabled(APIUtil.isCrossTenantSubscriptionsEnabled());
Map<String, Environment> gatewayEnvironments = APIUtil.getReadOnlyGatewayEnvironments();
String authorizationHeader = APIUtil.getOAuthConfiguration(loggedInUserTenantDomain,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->
<EnableAPIDocVisibilityLevels>{{apim.publisher.enable_api_doc_visibility}}</EnableAPIDocVisibilityLevels>
<EnablePortalConfigurationOnlyMode>{{apim.publisher.enable_portal_configuration_only_mode}}</EnablePortalConfigurationOnlyMode>
<!-- Uncomment this to limit the number of APIs in api the API Publisher -->
<!--APIsPerPage>30</APIsPerPage-->
<!-- This property need to be enabled to enable the publisher access control support -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->
<!--EnableAPIDocVisibilityLevels>true</EnableAPIDocVisibilityLevels-->
<!--EnablePortalConfigurationOnlyMode>false</EnablePortalConfigurationOnlyMode-->
<!-- Uncomment this to limit the number of APIs in api the API Publisher -->
<!--APIsPerPage>30</APIsPerPage-->
<!-- This property need to be enabled to enable the publisher access control support -->
Expand Down

0 comments on commit 49aba2f

Please sign in to comment.