Skip to content

Commit

Permalink
Introduce config to enable org related visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
chamilaadhi committed Sep 18, 2024
1 parent 1fa232f commit e28bc64
Show file tree
Hide file tree
Showing 16 changed files with 215 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1962,6 +1962,7 @@ public enum RegistryResourceTypesForUI {

public static final String BILLING_PLAN_FREE = "FREE";
public static final String ALLOWED_ORGANIZATIONS_DEFAULT = "ALL";
public static final String DEFAULT_VISIBLE_ORG = "all";
public static final String POLICY_RESET = "reset";

public static final String BLOCKING_EVENT_TYPE = "wso2event";
Expand Down Expand Up @@ -3177,4 +3178,8 @@ public static class TokenValidationConstants {
public static final String TOKEN_VALIDATION_CONFIG = "TokenValidation";
public static final String ENFORCE_JWT_TYPE_HEADER_VALIDATION = "EnforceTypeHeaderValidation";
}

// For Organization access control Configuration
public static final String ORG_BASED_ACCESS_CONTROL = "OrganizationBasedAccessControl";
public static final String ORG_BASED_ACCESS_CONTROL_ENABLE = "Enable";
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.wso2.carbon.apimgt.impl.dto.ExtendedJWTConfigurationDto;
import org.wso2.carbon.apimgt.impl.dto.GatewayArtifactSynchronizerProperties;
import org.wso2.carbon.apimgt.impl.dto.GatewayCleanupSkipList;
import org.wso2.carbon.apimgt.impl.dto.OrgAccessControl;
import org.wso2.carbon.apimgt.impl.dto.RedisConfig;
import org.wso2.carbon.apimgt.impl.dto.ThrottleProperties;
import org.wso2.carbon.apimgt.impl.dto.TokenValidationDto;
Expand Down Expand Up @@ -131,6 +132,15 @@ public class APIManagerConfiguration {
private static String certificateBoundAccessEnabled;
private GatewayCleanupSkipList gatewayCleanupSkipList = new GatewayCleanupSkipList();
private RedisConfig redisConfig = new RedisConfig();
private OrgAccessControl orgAccessControl = new OrgAccessControl();
public OrgAccessControl getOrgAccessControl() {
return orgAccessControl;
}

public void setOrgAccessControl(OrgAccessControl orgAccessControl) {
this.orgAccessControl = orgAccessControl;
}

private Map<String, List<String>> restApiJWTAuthAudiences = new HashMap<>();
private JSONObject subscriberAttributes = new JSONObject();
private static Map<String, String> analyticsMaskProps;
Expand Down Expand Up @@ -660,12 +670,23 @@ private void readChildElements(OMElement serverConfig,
setApiChatConfiguration(element);
} else if (APIConstants.TokenValidationConstants.TOKEN_VALIDATION_CONFIG.equals(localName)) {
setTokenValidation(element);
} else if (APIConstants.ORG_BASED_ACCESS_CONTROL.equals(localName)) {
setOrgBasedAccessControlConfigs(element);
}
readChildElements(element, nameStack);
nameStack.pop();
}
}

private void setOrgBasedAccessControlConfigs(OMElement element) {
OMElement orgEnableElement =
element.getFirstChildWithName(new QName(APIConstants.ORG_BASED_ACCESS_CONTROL_ENABLE));
if (orgEnableElement != null) {
orgAccessControl.setEnabled(Boolean.parseBoolean(orgEnableElement.getText()));
}

}

public JSONObject getSubscriberAttributes() {
return subscriberAttributes;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2024, WSO2 LLc. (http://www.wso2.org) 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.impl.dto;

public class OrgAccessControl {
private boolean isEnabled;
private String orgNameLocalClaim;
private String orgIdLocalClaim;
public boolean isEnabled() {
return isEnabled;
}
public void setEnabled(boolean isEnabled) {
this.isEnabled = isEnabled;
}
public String getOrgNameLocalClaim() {
return orgNameLocalClaim;
}
public void setOrgNameLocalClaim(String orgNameLocalClaim) {
this.orgNameLocalClaim = orgNameLocalClaim;
}
public String getOrgIdLocalClaim() {
return orgIdLocalClaim;
}
public void setOrgIdLocalClaim(String orgIdLocalClaim) {
this.orgIdLocalClaim = orgIdLocalClaim;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9863,6 +9863,15 @@ public static ExternalEnvironment getExternalEnvironment(String providerName) {
return ServiceReferenceHolder.getInstance().getExternalEnvironment(providerName);
}

/**
* Get org access control enabled status
*
* @return true or false
*/
public static boolean isOrganizationAccessControlEnabled() {
return ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration()
.getOrgAccessControl().isEnabled();
}
/**
* Get registered API Definition Parsers as a Map
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class SettingsDTO {
private List<String> scopes = new ArrayList<String>();
private List<String> gatewayTypes = new ArrayList<String>();
private Boolean isJWTEnabledForLoginTokens = false;
private Boolean orgAccessControlEnabled = null;
private List<SettingsKeyManagerConfigurationDTO> keyManagerConfiguration = new ArrayList<SettingsKeyManagerConfigurationDTO>();
private Boolean analyticsEnabled = null;

Expand Down Expand Up @@ -80,6 +81,24 @@ public void setIsJWTEnabledForLoginTokens(Boolean isJWTEnabledForLoginTokens) {
this.isJWTEnabledForLoginTokens = isJWTEnabledForLoginTokens;
}

/**
* Is Organization-based access control configuration enabled
**/
public SettingsDTO orgAccessControlEnabled(Boolean orgAccessControlEnabled) {
this.orgAccessControlEnabled = orgAccessControlEnabled;
return this;
}


@ApiModelProperty(example = "true", value = "Is Organization-based access control configuration enabled ")
@JsonProperty("orgAccessControlEnabled")
public Boolean isOrgAccessControlEnabled() {
return orgAccessControlEnabled;
}
public void setOrgAccessControlEnabled(Boolean orgAccessControlEnabled) {
this.orgAccessControlEnabled = orgAccessControlEnabled;
}

/**
**/
public SettingsDTO keyManagerConfiguration(List<SettingsKeyManagerConfigurationDTO> keyManagerConfiguration) {
Expand Down Expand Up @@ -129,13 +148,14 @@ public boolean equals(java.lang.Object o) {
return Objects.equals(scopes, settings.scopes) &&
Objects.equals(gatewayTypes, settings.gatewayTypes) &&
Objects.equals(isJWTEnabledForLoginTokens, settings.isJWTEnabledForLoginTokens) &&
Objects.equals(orgAccessControlEnabled, settings.orgAccessControlEnabled) &&
Objects.equals(keyManagerConfiguration, settings.keyManagerConfiguration) &&
Objects.equals(analyticsEnabled, settings.analyticsEnabled);
}

@Override
public int hashCode() {
return Objects.hash(scopes, gatewayTypes, isJWTEnabledForLoginTokens, keyManagerConfiguration, analyticsEnabled);
return Objects.hash(scopes, gatewayTypes, isJWTEnabledForLoginTokens, orgAccessControlEnabled, keyManagerConfiguration, analyticsEnabled);
}

@Override
Expand All @@ -146,6 +166,7 @@ public String toString() {
sb.append(" scopes: ").append(toIndentedString(scopes)).append("\n");
sb.append(" gatewayTypes: ").append(toIndentedString(gatewayTypes)).append("\n");
sb.append(" isJWTEnabledForLoginTokens: ").append(toIndentedString(isJWTEnabledForLoginTokens)).append("\n");
sb.append(" orgAccessControlEnabled: ").append(toIndentedString(orgAccessControlEnabled)).append("\n");
sb.append(" keyManagerConfiguration: ").append(toIndentedString(keyManagerConfiguration)).append("\n");
sb.append(" analyticsEnabled: ").append(toIndentedString(analyticsEnabled)).append("\n");
sb.append("}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public SettingsDTO fromSettingsToDTO(Boolean isUserAvailable) throws APIManageme
settingsDTO.setScopes(getScopeList());
settingsDTO.setGatewayTypes(APIUtil.getGatewayTypes());
settingsDTO.setIsJWTEnabledForLoginTokens(APIUtil.isJWTEnabledForPortals());
settingsDTO.setOrgAccessControlEnabled(APIUtil.isOrganizationAccessControlEnabled());
return settingsDTO;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4696,6 +4696,11 @@ components:
IsJWTEnabledForLoginTokens:
type: boolean
default: false
orgAccessControlEnabled:
type: boolean
description: |
Is Organization-based access control configuration enabled
example: true
keyManagerConfiguration:
type: array
items:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3858,6 +3858,10 @@ components:
example: FREE
permissions:
$ref: '#/components/schemas/SubscriptionThrottlePolicyPermission'
allowedOrganizations:
type: array
items:
type: string
SubscriptionThrottlePolicyPermission:
title: SubscriptionThrottlePolicyPermission
required:
Expand Down Expand Up @@ -4692,6 +4696,11 @@ components:
IsJWTEnabledForLoginTokens:
type: boolean
default: false
orgAccessControlEnabled:
type: boolean
description: |
Is Organization-based access control configuration enabled
example: true
keyManagerConfiguration:
type: array
items:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4363,6 +4363,11 @@ components:
type: string
readOnly: true
example: 1651555310208
visibility:
type: string
enum:
- PRIVATE
- SHARED_WITH_ORG
ApplicationInfo:
title: Application info object with basic application details
type: object
Expand Down Expand Up @@ -5518,6 +5523,11 @@ components:
IsJWTEnabledForLoginTokens:
type: boolean
default: false
orgAccessControlEnabled:
type: boolean
description: |
Is Organization-based access control configuration enabled
example: true
userStorePasswordPattern:
type: string
description: The 'PasswordJavaRegEx' cofigured in the UserStoreManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8167,7 +8167,7 @@ paths:
x-code-samples:
- lang: Curl
source: 'curl -k -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8"
-H "Content-Type: multipart/form-data" -F policySpecFile=@setHeader.yaml -F policyDefinitionFile=@setHeader.j2
-H "Content-Type: multipart/form-data" -F policySpecFile=@setHeader.yaml -F synapsePolicyDefinitionFile=@setHeader.j2
"https://127.0.0.1:9443/api/am/publisher/v4/apis/96077508-fd01-4fae-bc64-5de0e2baf43c/operation-policies"'


Expand Down Expand Up @@ -8411,7 +8411,7 @@ paths:
x-code-samples:
- lang: Curl
source: 'curl -k -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8"
-H "Content-Type: multipart/form-data" -F policySpecFile=@setHeader.yaml -F policyDefinitionFile=@setHeader.j2
-H "Content-Type: multipart/form-data" -F policySpecFile=@setHeader.yaml -F synapsePolicyDefinitionFile=@setHeader.j2
"https://127.0.0.1:9443/api/am/publisher/v4/operation-policies"'

/operation-policies/export:
Expand Down Expand Up @@ -9365,6 +9365,12 @@ components:
enum:
- PUBLIC
- SINGLE
audiences:
type: array
description: The audiences of the API for jwt validation. Accepted values are any String values
items:
type: string
example: [ "aud1","aud2","aud3" ]
lifeCycleStatus:
type: string
example: CREATED
Expand Down Expand Up @@ -9684,6 +9690,12 @@ components:
enum:
- PUBLIC
- SINGLE
audiences:
type: array
description: The audiences of the API for jwt validation. Accepted values are any String values
items:
type: string
example: [ "aud1","aud2","aud3" ]
transport:
type: array
description: |
Expand Down Expand Up @@ -9754,7 +9766,6 @@ components:
- PUBLIC
- PRIVATE
- RESTRICTED
- RESTRICTED_BY_ORG
x-otherScopes:
- apim:api_publish
- apim:api_manage
Expand Down Expand Up @@ -10283,6 +10294,12 @@ components:
gatewayVendor:
type: string
example: wso2
audiences:
type: array
description: The audiences of the API product for jwt validation. Accepted values are any String values
items:
type: string
example: [ "aud1","aud2","aud3" ]
monetizedInfo:
type: boolean
example: true
Expand Down Expand Up @@ -10556,6 +10573,12 @@ components:
workflowStatus:
type: string
example: APPROVED
audiences:
type: array
description: The audiences of the API for jwt validation. Accepted values are any String values
items:
type: string
example: [ "aud1","aud2","aud3" ]
ProductAPI:
title: ProductAPI
required:
Expand Down Expand Up @@ -12585,6 +12608,11 @@ components:
IsJWTEnabledForLoginTokens:
type: boolean
default: false
orgAccessControlEnabled:
type: boolean
description: |
Is Organization-based access control configuration enabled
example: true
customProperties:
type: array
items:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class SettingsDTO {
private String defaultSubscriptionPolicy = null;
private String authorizationHeader = null;
private Boolean isJWTEnabledForLoginTokens = false;
private Boolean orgAccessControlEnabled = null;
private List<SettingsCustomPropertiesDTO> customProperties = new ArrayList<SettingsCustomPropertiesDTO>();

/**
Expand Down Expand Up @@ -310,6 +311,24 @@ public void setIsJWTEnabledForLoginTokens(Boolean isJWTEnabledForLoginTokens) {
this.isJWTEnabledForLoginTokens = isJWTEnabledForLoginTokens;
}

/**
* Is Organization-based access control configuration enabled
**/
public SettingsDTO orgAccessControlEnabled(Boolean orgAccessControlEnabled) {
this.orgAccessControlEnabled = orgAccessControlEnabled;
return this;
}


@ApiModelProperty(example = "true", value = "Is Organization-based access control configuration enabled ")
@JsonProperty("orgAccessControlEnabled")
public Boolean isOrgAccessControlEnabled() {
return orgAccessControlEnabled;
}
public void setOrgAccessControlEnabled(Boolean orgAccessControlEnabled) {
this.orgAccessControlEnabled = orgAccessControlEnabled;
}

/**
**/
public SettingsDTO customProperties(List<SettingsCustomPropertiesDTO> customProperties) {
Expand Down Expand Up @@ -353,12 +372,13 @@ public boolean equals(java.lang.Object o) {
Objects.equals(defaultSubscriptionPolicy, settings.defaultSubscriptionPolicy) &&
Objects.equals(authorizationHeader, settings.authorizationHeader) &&
Objects.equals(isJWTEnabledForLoginTokens, settings.isJWTEnabledForLoginTokens) &&
Objects.equals(orgAccessControlEnabled, settings.orgAccessControlEnabled) &&
Objects.equals(customProperties, settings.customProperties);
}

@Override
public int hashCode() {
return Objects.hash(devportalUrl, environment, gatewayTypes, scopes, monetizationAttributes, subscriberContactAttributes, securityAuditProperties, externalStoresEnabled, docVisibilityEnabled, portalConfigurationOnlyModeEnabled, crossTenantSubscriptionEnabled, defaultAdvancePolicy, defaultSubscriptionPolicy, authorizationHeader, isJWTEnabledForLoginTokens, customProperties);
return Objects.hash(devportalUrl, environment, gatewayTypes, scopes, monetizationAttributes, subscriberContactAttributes, securityAuditProperties, externalStoresEnabled, docVisibilityEnabled, portalConfigurationOnlyModeEnabled, crossTenantSubscriptionEnabled, defaultAdvancePolicy, defaultSubscriptionPolicy, authorizationHeader, isJWTEnabledForLoginTokens, orgAccessControlEnabled, customProperties);
}

@Override
Expand All @@ -381,6 +401,7 @@ public String toString() {
sb.append(" defaultSubscriptionPolicy: ").append(toIndentedString(defaultSubscriptionPolicy)).append("\n");
sb.append(" authorizationHeader: ").append(toIndentedString(authorizationHeader)).append("\n");
sb.append(" isJWTEnabledForLoginTokens: ").append(toIndentedString(isJWTEnabledForLoginTokens)).append("\n");
sb.append(" orgAccessControlEnabled: ").append(toIndentedString(orgAccessControlEnabled)).append("\n");
sb.append(" customProperties: ").append(toIndentedString(customProperties)).append("\n");
sb.append("}");
return sb.toString();
Expand Down
Loading

0 comments on commit e28bc64

Please sign in to comment.