Skip to content

Commit

Permalink
Fix api overview page visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
chamilaadhi committed Oct 16, 2024
1 parent 763494a commit 1c6916b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class DevPortalAPI extends DevPortalAPIInfo {

private String subscriptionAvailability; // need to decide isSubscriptionAvailable
private String subscriptionAvailableOrgs; // (subscriptionAvailableTenants): need to decide the value of "isSubscriptionAvailable"
private String visibleOrganizations; //visible organizations
private String authorizationHeader;
private String apiKeyHeader;
private List<String> securityScheme = new ArrayList<>();
Expand Down Expand Up @@ -340,13 +341,20 @@ public void setGatewayVendor(String gatewayVendor) {
this.gatewayVendor = gatewayVendor;
}

public String getVisibleOrganizations() {
return visibleOrganizations;
}

public void setVisibleOrganizations(String visibleOrganizations) {
this.visibleOrganizations = visibleOrganizations;
}

public String getAsyncTransportProtocols() { return asyncTransportProtocols; }

public void setAsyncTransportProtocols(String asyncTransportProtocols) {
this.asyncTransportProtocols = asyncTransportProtocols;
}


@Override
public String toString() {
return "DevPortalAPI [status=" + status + ", isDefaultVersion=" + isDefaultVersion + ", description="
Expand All @@ -355,16 +363,17 @@ public String toString() {
+ businessOwnerEmail + ", transports=" + transports + ", redirectURL=" + redirectURL
+ ", apiExternalProductionEndpoint=" + apiExternalProductionEndpoint + ", apiExternalSandboxEndpoint="
+ apiExternalSandboxEndpoint + ", apiOwner=" + apiOwner + ", advertiseOnly=" + advertiseOnly
+ ", subscriptionAvailability=" + subscriptionAvailability + ", subscriptionAvailableOrgs="
+ subscriptionAvailableOrgs + ", authorizationHeader=" + authorizationHeader + ", securityScheme="
+ securityScheme + ", environments=" + environments + ", gatewayVendor=" + gatewayVendor
+ ", asyncTransportProtocols=" + asyncTransportProtocols + ", apiCategories=" + apiCategories
+ ", isMonetizationEnabled=" + isMonetizationEnabled + ", keyManagers=" + keyManagers
+ ", deploymentEnvironments=" + deploymentEnvironments + ", tags=" + tags + ", additionalProperties="
+ additionalProperties + ", endpointConfig=" + endpointConfig + ", type=" + type + ", advertisedOnly="
+ advertisedOnly + ", swaggerDefinition=" + swaggerDefinition + ", contextTemplate=" + contextTemplate
+ ", apiSecurity=" + apiSecurity + ", visibility=" + visibility + ", visibleRoles=" + visibleRoles
+ "]";
+ ", vendor=" + vendor + ", subscriptionAvailability=" + subscriptionAvailability
+ ", subscriptionAvailableOrgs=" + subscriptionAvailableOrgs + ", visibleOrganizations="
+ visibleOrganizations + ", authorizationHeader=" + authorizationHeader + ", apiKeyHeader="
+ apiKeyHeader + ", securityScheme=" + securityScheme + ", environments=" + environments
+ ", apiCategories=" + apiCategories + ", isMonetizationEnabled=" + isMonetizationEnabled
+ ", keyManagers=" + keyManagers + ", deploymentEnvironments=" + deploymentEnvironments + ", tags="
+ tags + ", additionalProperties=" + additionalProperties + ", endpointConfig=" + endpointConfig
+ ", type=" + type + ", advertisedOnly=" + advertisedOnly + ", swaggerDefinition=" + swaggerDefinition
+ ", contextTemplate=" + contextTemplate + ", apiSecurity=" + apiSecurity + ", visibility=" + visibility
+ ", visibleRoles=" + visibleRoles + ", gatewayVendor=" + gatewayVendor + ", asyncTransportProtocols="
+ asyncTransportProtocols + "]";
}

public String getApiSecurity() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,12 @@ private APIDTO getAPIByAPIId(String apiId, String organization, OrganizationInfo
APIConsumer apiConsumer = RestApiCommonUtil.getLoggedInUserConsumer();
ApiTypeWrapper api = apiConsumer.getAPIorAPIProductByUUID(apiId, organization);
String status = api.getStatus();
String visibleOrgs = api.getApi().getVisibleOrganizations();
String userOrg = userOrgInfo.getOrganizationSelector();

if (!api.isAPIProduct() && !RestApiUtil.isOrganizationVisibilityAllowed(visibleOrgs, userOrg)) {
RestApiUtil.handleAuthorizationFailure(RestApiConstants.RESOURCE_API, apiId, log);
}

// Extracting clicked API name by the user, for the recommendation system
String userName = RestApiCommonUtil.getLoggedInUsername();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1297,9 +1297,11 @@ public Response applicationsApplicationIdOauthKeysKeyMappingIdGenerateTokenPost(
String username = RestApiCommonUtil.getLoggedInUsername();
APIConsumer apiConsumer = RestApiCommonUtil.getConsumer(username);
Application application = apiConsumer.getApplicationByUUID(applicationId);
OrganizationInfo orgInfo = RestApiUtil.getOrganizationInfo(messageContext);

if (application != null) {
if (RestAPIStoreUtils.isUserAccessAllowedForApplication(application)) {
if (RestAPIStoreUtils.isUserAccessAllowedForApplication(application) || (orgInfo.getOrganizationSelector() != null
&& orgInfo.getOrganizationSelector().equals(application.getSharedOrganization()))) {
ApplicationKeyDTO appKey = getApplicationKeyByAppIDAndKeyMapping(applicationId, keyMappingId);
if (appKey != null) {
String jsonInput = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1293,4 +1293,21 @@ public static String resolveOrganization (HashMap<String,Object> message) throws
String organization = resolver.resolve(properties);
return organization;
}

public static boolean isOrganizationVisibilityAllowed(String visibleOrgs, String userOrg) {
boolean allowed = false;

if (StringUtils.isEmpty(visibleOrgs) || APIConstants.DEFAULT_VISIBLE_ORG.equals(visibleOrgs)) {
allowed = true;
} else {
List<String> visibleOrgList = Arrays.asList(visibleOrgs.split(","));

if(visibleOrgList.contains(userOrg)) {
allowed = true;
} else {
allowed = false;
}
}
return allowed;
}
}

0 comments on commit 1c6916b

Please sign in to comment.