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 6eea68bd1114..dec825f7d235 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 @@ -5033,14 +5033,21 @@ public static Set extractEnvironmentsForAPI(String environments) throws public static Set extractVisibleEnvironmentsForUser(List environments, String organization, String userName) throws APIManagementException { Set environmentStringSet = new HashSet(); - String[] userRoles = APIUtil.getListOfRoles(userName); + List userRolesList; + if (userName == null) { + userRolesList = new ArrayList() {{ + add(APIConstants.NULL_USER_ROLE_LIST); + }}; + } else { + userRolesList = new ArrayList(Arrays.asList(APIUtil.getListOfRoles(userName))); + } if (environments != null) { for (Environment environment : environments) { String[] permittedRoles = environment.getVisibilityRoles(); if (permittedRoles[0].equals("all")) { environmentStringSet.add(environment.toString()); } else { - for (String role : userRoles) { + for (String role : userRolesList) { for (String permission : permittedRoles) { if (role.equals(permission)) { environmentStringSet.add(environment.toString()); @@ -5056,7 +5063,7 @@ public static Set extractVisibleEnvironmentsForUser(List en if (permittedRoles != null && permittedRoles[0].equals("all")) { environmentStringSet.add(environment.toString()); } else if (permittedRoles != null) { - for (String role : userRoles) { + for (String role : userRolesList) { for (String permission : permittedRoles) { if (role.equals(permission)) { environmentStringSet.add(environment.toString()); @@ -5074,14 +5081,21 @@ public static Set extractVisibleEnvironmentsForUser(List en public static Map extractVisibleEnvironmentsForUser(String organization, String userName) throws APIManagementException { Map returnEnvironments = new LinkedHashMap<>(); - String[] userRoles = APIUtil.getListOfRoles(userName); + List userRolesList; + if (userName == null) { + userRolesList = new ArrayList() {{ + add(APIConstants.NULL_USER_ROLE_LIST); + }}; + } else { + userRolesList = new ArrayList(Arrays.asList(APIUtil.getListOfRoles(userName))); + } Map environmentsMap = getEnvironments(organization); for (Environment environment : environmentsMap.values()) { String[] permittedRoles = environment.getVisibilityRoles(); if (permittedRoles != null && permittedRoles[0].equals("all")) { returnEnvironments.put(environment.getName(), environment); } else if (permittedRoles != null) { - for (String role : userRoles) { + for (String role : userRolesList) { for (String permission : permittedRoles) { if (role.equals(permission)) { returnEnvironments.put(environment.getName(), environment); 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/EnvironmentDTO.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/EnvironmentDTO.java index ca3f79bf419a..1df0e1f0e62f 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/EnvironmentDTO.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/EnvironmentDTO.java @@ -30,6 +30,7 @@ public class EnvironmentDTO { private String displayName = null; private String provider = null; private String type = "hybrid"; + private String visibility = "all"; private String gatewayType = "Regular"; private String description = null; private Boolean isReadOnly = null; @@ -123,6 +124,23 @@ public void setType(String type) { this.type = type; } + /** + **/ + public EnvironmentDTO visibility(String visibility) { + this.visibility = visibility; + return this; + } + + + @ApiModelProperty(example = "role1, role2", value = "") + @JsonProperty("visibility") + public String getVisibility() { + return visibility; + } + public void setVisibility(String visibility) { + this.visibility = visibility; + } + /** **/ public EnvironmentDTO gatewayType(String gatewayType) { @@ -244,6 +262,7 @@ public boolean equals(java.lang.Object o) { Objects.equals(displayName, environment.displayName) && Objects.equals(provider, environment.provider) && Objects.equals(type, environment.type) && + Objects.equals(visibility, environment.visibility) && Objects.equals(gatewayType, environment.gatewayType) && Objects.equals(description, environment.description) && Objects.equals(isReadOnly, environment.isReadOnly) && @@ -254,7 +273,7 @@ public boolean equals(java.lang.Object o) { @Override public int hashCode() { - return Objects.hash(id, name, displayName, provider, type, gatewayType, description, isReadOnly, vhosts, endpointURIs, additionalProperties); + return Objects.hash(id, name, displayName, provider, type, visibility, gatewayType, description, isReadOnly, vhosts, endpointURIs, additionalProperties); } @Override @@ -267,6 +286,7 @@ public String toString() { sb.append(" displayName: ").append(toIndentedString(displayName)).append("\n"); sb.append(" provider: ").append(toIndentedString(provider)).append("\n"); sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" visibility: ").append(toIndentedString(visibility)).append("\n"); sb.append(" gatewayType: ").append(toIndentedString(gatewayType)).append("\n"); sb.append(" description: ").append(toIndentedString(description)).append("\n"); sb.append(" isReadOnly: ").append(toIndentedString(isReadOnly)).append("\n"); 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/EnvironmentMappingUtil.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/EnvironmentMappingUtil.java index a4a6ef1f9e77..b64facf77c46 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/mappings/EnvironmentMappingUtil.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/EnvironmentMappingUtil.java @@ -63,6 +63,7 @@ public static EnvironmentDTO fromEnvToEnvDTO(Environment env) { envDTO.setDescription(env.getDescription()); envDTO.setProvider(env.getProvider()); envDTO.setGatewayType(env.getGatewayType()); + envDTO.setVisibility(env.getVisibility()); envDTO.setIsReadOnly(env.isReadOnly()); envDTO.setVhosts(env.getVhosts().stream().map(EnvironmentMappingUtil::fromVHostToVHostDTO) .collect(Collectors.toList())); @@ -134,6 +135,7 @@ public static Environment fromEnvDtoToEnv(EnvironmentDTO envDTO) { env.setDescription(envDTO.getDescription()); env.setProvider(envDTO.getProvider()); env.setGatewayType(envDTO.getGatewayType()); + env.setVisibility(envDTO.getVisibility()); env.setReadOnly(false); env.setVhosts(envDTO.getVhosts().stream().map(EnvironmentMappingUtil::fromVHostDtoToVHost) .collect(Collectors.toList())); 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 4905e5824783..28005fc5c5db 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 @@ -4674,6 +4674,10 @@ components: type: string default: hybrid example: hybrid + visibility: + type: string + default: all + example: role1, role2 gatewayType: type: string example: Regular 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 4905e5824783..28005fc5c5db 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 @@ -4674,6 +4674,10 @@ components: type: string default: hybrid example: hybrid + visibility: + type: string + default: all + example: role1, role2 gatewayType: type: string example: Regular