From 52fc742ec399ad5b290754c294fb264483139b8f Mon Sep 17 00:00:00 2001 From: SujanSanjula96 Date: Wed, 18 Oct 2023 21:34:36 +0530 Subject: [PATCH 1/3] Add support for API Resource properties --- .../api/resource/v1/APIResourceListItem.java | 35 ++++- .../api/resource/v1/APIResourceResponse.java | 33 ++++- .../api/resource/v1/ApiResourcesApi.java | 44 ++++--- .../resource/v1/ApiResourcesApiService.java | 16 ++- .../api/server/api/resource/v1/Property.java | 123 ++++++++++++++++++ .../api/server/api/resource/v1/ScopesApi.java | 2 +- .../APIResourceMgtEndpointConstants.java | 10 ++ .../ServerAPIResourceManagementService.java | 64 ++++++++- .../v1/impl/ApiResourcesApiServiceImpl.java | 6 +- .../src/main/resources/APIResources.yaml | 27 +++- 10 files changed, 329 insertions(+), 31 deletions(-) create mode 100644 components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/Property.java diff --git a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/APIResourceListItem.java b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/APIResourceListItem.java index ef343a122c..58d543d566 100644 --- a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/APIResourceListItem.java +++ b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/APIResourceListItem.java @@ -22,6 +22,9 @@ import com.fasterxml.jackson.annotation.JsonCreator; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import java.util.ArrayList; +import java.util.List; +import org.wso2.carbon.identity.api.server.api.resource.v1.Property; import javax.validation.constraints.*; @@ -37,6 +40,8 @@ public class APIResourceListItem { private String identifier; private String type; private Boolean requiresAuthorization; + private List properties = null; + private String self; /** @@ -137,6 +142,32 @@ public void setRequiresAuthorization(Boolean requiresAuthorization) { /** **/ + public APIResourceListItem properties(List properties) { + + this.properties = properties; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("properties") + @Valid + public List getProperties() { + return properties; + } + public void setProperties(List properties) { + this.properties = properties; + } + + public APIResourceListItem addPropertiesItem(Property propertiesItem) { + if (this.properties == null) { + this.properties = new ArrayList(); + } + this.properties.add(propertiesItem); + return this; + } + + /** + **/ public APIResourceListItem self(String self) { this.self = self; @@ -172,12 +203,13 @@ public boolean equals(java.lang.Object o) { Objects.equals(this.identifier, apIResourceListItem.identifier) && Objects.equals(this.type, apIResourceListItem.type) && Objects.equals(this.requiresAuthorization, apIResourceListItem.requiresAuthorization) && + Objects.equals(this.properties, apIResourceListItem.properties) && Objects.equals(this.self, apIResourceListItem.self); } @Override public int hashCode() { - return Objects.hash(id, name, identifier, type, requiresAuthorization, self); + return Objects.hash(id, name, identifier, type, requiresAuthorization, properties, self); } @Override @@ -191,6 +223,7 @@ public String toString() { sb.append(" identifier: ").append(toIndentedString(identifier)).append("\n"); sb.append(" type: ").append(toIndentedString(type)).append("\n"); sb.append(" requiresAuthorization: ").append(toIndentedString(requiresAuthorization)).append("\n"); + sb.append(" properties: ").append(toIndentedString(properties)).append("\n"); sb.append(" self: ").append(toIndentedString(self)).append("\n"); sb.append("}"); return sb.toString(); diff --git a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/APIResourceResponse.java b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/APIResourceResponse.java index 22b3d7b93e..a2c360f259 100644 --- a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/APIResourceResponse.java +++ b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/APIResourceResponse.java @@ -24,6 +24,7 @@ import io.swagger.annotations.ApiModelProperty; import java.util.ArrayList; import java.util.List; +import org.wso2.carbon.identity.api.server.api.resource.v1.Property; import org.wso2.carbon.identity.api.server.api.resource.v1.ScopeGetModel; import org.wso2.carbon.identity.api.server.api.resource.v1.SubscribedApplicationGetModel; import javax.validation.constraints.*; @@ -46,6 +47,8 @@ public class APIResourceResponse { private List subscribedApplications = null; + private List properties = null; + private String self; /** @@ -216,6 +219,32 @@ public APIResourceResponse addSubscribedApplicationsItem(SubscribedApplicationGe /** **/ + public APIResourceResponse properties(List properties) { + + this.properties = properties; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("properties") + @Valid + public List getProperties() { + return properties; + } + public void setProperties(List properties) { + this.properties = properties; + } + + public APIResourceResponse addPropertiesItem(Property propertiesItem) { + if (this.properties == null) { + this.properties = new ArrayList(); + } + this.properties.add(propertiesItem); + return this; + } + + /** + **/ public APIResourceResponse self(String self) { this.self = self; @@ -254,12 +283,13 @@ public boolean equals(java.lang.Object o) { Objects.equals(this.requiresAuthorization, apIResourceResponse.requiresAuthorization) && Objects.equals(this.scopes, apIResourceResponse.scopes) && Objects.equals(this.subscribedApplications, apIResourceResponse.subscribedApplications) && + Objects.equals(this.properties, apIResourceResponse.properties) && Objects.equals(this.self, apIResourceResponse.self); } @Override public int hashCode() { - return Objects.hash(id, name, description, identifier, type, requiresAuthorization, scopes, subscribedApplications, self); + return Objects.hash(id, name, description, identifier, type, requiresAuthorization, scopes, subscribedApplications, properties, self); } @Override @@ -276,6 +306,7 @@ public String toString() { sb.append(" requiresAuthorization: ").append(toIndentedString(requiresAuthorization)).append("\n"); sb.append(" scopes: ").append(toIndentedString(scopes)).append("\n"); sb.append(" subscribedApplications: ").append(toIndentedString(subscribedApplications)).append("\n"); + sb.append(" properties: ").append(toIndentedString(properties)).append("\n"); sb.append(" self: ").append(toIndentedString(self)).append("\n"); sb.append("}"); return sb.toString(); diff --git a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/ApiResourcesApi.java b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/ApiResourcesApi.java index 0bc88af4c9..38c6be4cc0 100644 --- a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/ApiResourcesApi.java +++ b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/ApiResourcesApi.java @@ -19,14 +19,28 @@ package org.wso2.carbon.identity.api.server.api.resource.v1; import org.springframework.beans.factory.annotation.Autowired; +import org.apache.cxf.jaxrs.ext.multipart.Attachment; +import org.apache.cxf.jaxrs.ext.multipart.Multipart; +import java.io.InputStream; +import java.util.List; +import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceCreationModel; +import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceListResponse; +import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourcePatchModel; +import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceResponse; +import org.wso2.carbon.identity.api.server.api.resource.v1.Error; import java.util.List; +import org.wso2.carbon.identity.api.server.api.resource.v1.ScopeCreationModel; +import org.wso2.carbon.identity.api.server.api.resource.v1.ScopeGetModel; +import org.wso2.carbon.identity.api.server.api.resource.v1.ApiResourcesApiService; import javax.validation.Valid; import javax.ws.rs.*; import javax.ws.rs.core.Response; import io.swagger.annotations.*; +import javax.validation.constraints.*; + @Path("/api-resources") @Api(description = "The api-resources API") @@ -40,7 +54,7 @@ public class ApiResourcesApi { @Consumes({ "application/json" }) @Produces({ "application/json", "application/xml", }) - @ApiOperation(value = "Add a new API resource", notes = "Add a new API resource", response = APIResourceResponse.class, authorizations = { + @ApiOperation(value = "Add a new API resource", notes = "Add a new API resource Permission required:
* /permission/admin/manage/identity/apiresourcemgt/create
Scope required:
* internal_api_resource_create ", response = APIResourceResponse.class, authorizations = { @Authorization(value = "BasicAuth"), @Authorization(value = "OAuth2", scopes = { @@ -65,7 +79,7 @@ public Response addAPIResource(@ApiParam(value = "This represents the API resour @Path("/{apiResourceId}") @Produces({ "application/json" }) - @ApiOperation(value = "Delete API resource specified by the id", notes = "Delete API resource specified by the id", response = Void.class, authorizations = { + @ApiOperation(value = "Delete API resource specified by the id", notes = "Delete API resource specified by the id Permission required:
* /permission/admin/manage/identity/apiresourcemgt/delete
Scope required:
* internal_api_resource_delete ", response = Void.class, authorizations = { @Authorization(value = "BasicAuth"), @Authorization(value = "OAuth2", scopes = { @@ -87,7 +101,7 @@ public Response apiResourcesApiResourceIdDelete(@ApiParam(value = "ID of the API @Path("/{apiResourceId}") @Produces({ "application/json" }) - @ApiOperation(value = "Get API resource specified by the id", notes = "Get API resource specified by the id", response = APIResourceResponse.class, authorizations = { + @ApiOperation(value = "Get API resource specified by the id", notes = "Get API resource specified by the id Permission required:
* /permission/admin/manage/identity/apiresourcemgt/view
Scope required:
* internal_api_resource_view ", response = APIResourceResponse.class, authorizations = { @Authorization(value = "BasicAuth"), @Authorization(value = "OAuth2", scopes = { @@ -109,14 +123,14 @@ public Response apiResourcesApiResourceIdGet(@ApiParam(value = "ID of the API Re @Path("/{apiResourceId}") @Consumes({ "application/json" }) @Produces({ "application/json", "application/xml", }) - @ApiOperation(value = "Patch API resource specified by the id", notes = "Patch API resource specified by the id. Patch operation only supports \"name\", \"description\" updating and \"addedScopes\" fields at the moment.", response = APIResourceResponse.class, authorizations = { + @ApiOperation(value = "Patch API resource specified by the id", notes = "Patch API resource specified by the id. Patch operation only supports \"name\", \"description\" updating and \"addedScopes\" fields at the moment. Permission required:
* /permission/admin/manage/identity/apiresourcemgt/update
Scope required:
* internal_api_resource_update ", response = Void.class, authorizations = { @Authorization(value = "BasicAuth"), @Authorization(value = "OAuth2", scopes = { }) }, tags={ "API Resources", }) @ApiResponses(value = { - @ApiResponse(code = 200, message = "OK", response = APIResourceResponse.class), + @ApiResponse(code = 204, message = "Not Content", response = Void.class), @ApiResponse(code = 400, message = "Bad Request", response = Error.class), @ApiResponse(code = 401, message = "Unauthorized", response = Void.class), @ApiResponse(code = 403, message = "Forbidden", response = Void.class), @@ -135,7 +149,7 @@ public Response apiResourcesApiResourceIdPatch(@ApiParam(value = "ID of the API @Path("/{apiResourceId}/scopes") @Produces({ "application/json" }) - @ApiOperation(value = "Get API resource scopes", notes = "Get API resource scopes specified by the id", response = ScopeGetModel.class, responseContainer = "List", authorizations = { + @ApiOperation(value = "Get API resource scopes", notes = "Get API resource scopes specified by the id Permission required:
* /permission/admin/manage/identity/apiresourcemgt/view
Scope required:
* internal_api_resource_view ", response = ScopeGetModel.class, responseContainer = "List", authorizations = { @Authorization(value = "BasicAuth"), @Authorization(value = "OAuth2", scopes = { @@ -158,7 +172,7 @@ public Response apiResourcesApiResourceIdScopesGet(@ApiParam(value = "ID of the @Path("/{apiResourceId}/scopes") @Consumes({ "application/json" }) @Produces({ "application/json", "application/xml", }) - @ApiOperation(value = "Add scopes to API resource", notes = "Put scopes API resource specified by the id", response = Void.class, authorizations = { + @ApiOperation(value = "Add scopes to API resource", notes = "Put scopes API resource specified by the id Permission required:
* /permission/admin/manage/identity/apiresourcemgt/update
Scope required:
* internal_api_resource_update ", response = Void.class, authorizations = { @Authorization(value = "BasicAuth"), @Authorization(value = "OAuth2", scopes = { @@ -180,10 +194,10 @@ public Response apiResourcesApiResourceIdScopesPut(@ApiParam(value = "ID of the @Valid @DELETE - @Path("/{apiResourceId}/scopes/{scopeId}") + @Path("/{apiResourceId}/scopes/{scopeName}") @Produces({ "application/json" }) - @ApiOperation(value = "Delete API resource specified by the id", notes = "Delete API resource specified by the id", response = Void.class, authorizations = { + @ApiOperation(value = "Delete API scope specified by the name", notes = "Delete API scope specified by the name Permission required:
* /permission/admin/manage/identity/apiresourcemgt/delete
Scope required:
* internal_api_resource_delete ", response = Void.class, authorizations = { @Authorization(value = "BasicAuth"), @Authorization(value = "OAuth2", scopes = { @@ -194,9 +208,9 @@ public Response apiResourcesApiResourceIdScopesPut(@ApiParam(value = "ID of the @ApiResponse(code = 403, message = "Forbidden", response = Void.class), @ApiResponse(code = 500, message = "Server Error", response = Error.class) }) - public Response apiResourcesApiResourceIdScopesScopeIdDelete(@ApiParam(value = "ID of the API Resource.",required=true) @PathParam("apiResourceId") String apiResourceId, @ApiParam(value = "ID of the Scope.",required=true) @PathParam("scopeId") String scopeId) { + public Response apiResourcesApiResourceIdScopesScopeNameDelete(@ApiParam(value = "ID of the API Resource.",required=true) @PathParam("apiResourceId") String apiResourceId, @ApiParam(value = "Name of the Scope.",required=true) @PathParam("scopeName") String scopeName) { - return delegate.apiResourcesApiResourceIdScopesScopeNameDelete(apiResourceId, scopeId ); + return delegate.apiResourcesApiResourceIdScopesScopeNameDelete(apiResourceId, scopeName ); } @Valid @@ -204,21 +218,21 @@ public Response apiResourcesApiResourceIdScopesScopeIdDelete(@ApiParam(value = " @Produces({ "application/json" }) - @ApiOperation(value = "List all API resources in the server", notes = "List all API resources in the server", response = APIResourceListResponse.class, authorizations = { + @ApiOperation(value = "List all API resources in the server", notes = "List all API resources in the server Permission required:
* /permission/admin/manage/identity/apiresourcemgt/view
Scope required:
* internal_api_resource_view ", response = APIResourceListResponse.class, authorizations = { @Authorization(value = "BasicAuth"), @Authorization(value = "OAuth2", scopes = { }) - }, tags={ "API Resources", }) + }, tags={ "API Resources" }) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = APIResourceListResponse.class), @ApiResponse(code = 401, message = "Unauthorized", response = Void.class), @ApiResponse(code = 403, message = "Forbidden", response = Void.class), @ApiResponse(code = 500, message = "Server Error", response = Error.class) }) - public Response getAPIResources( @Valid@ApiParam(value = "Base64 encoded cursor value for backward pagination. ") @QueryParam("before") String before, @Valid@ApiParam(value = "Base64 encoded cursor value for forward pagination. ") @QueryParam("after") String after, @Valid@ApiParam(value = "Condition to filter the retrieval of records. Supports 'sw', 'co', 'ew' and 'eq' operations. ") @QueryParam("filter") String filter, @Valid@ApiParam(value = "Maximum number of records to return. ") @QueryParam("limit") Integer limit, @Valid@ApiParam(value = "Specifies the required parameters in the response. This parameter is not supported yet") @QueryParam("requiredAttributes") String requiredAttributes) { + public Response getAPIResources( @Valid@ApiParam(value = "Base64 encoded cursor value for backward pagination. ") @QueryParam("before") String before, @Valid@ApiParam(value = "Base64 encoded cursor value for forward pagination. ") @QueryParam("after") String after, @Valid@ApiParam(value = "Condition to filter the retrieval of records. Supports 'sw', 'co', 'ew' and 'eq' operations. ") @QueryParam("filter") String filter, @Valid@ApiParam(value = "Maximum number of records to return. ") @QueryParam("limit") Integer limit, @Valid@ApiParam(value = "Specifies the required parameters in the response. This parameter is not supported yet") @QueryParam("attributes") String attributes) { - return delegate.getAPIResources(before, after, filter, limit, requiredAttributes ); + return delegate.getAPIResources(before, after, filter, limit, attributes ); } } diff --git a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/ApiResourcesApiService.java b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/ApiResourcesApiService.java index d7d087d2d5..b42b8cbea5 100644 --- a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/ApiResourcesApiService.java +++ b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/ApiResourcesApiService.java @@ -18,8 +18,20 @@ package org.wso2.carbon.identity.api.server.api.resource.v1; +import org.wso2.carbon.identity.api.server.api.resource.v1.*; +import org.wso2.carbon.identity.api.server.api.resource.v1.*; +import org.apache.cxf.jaxrs.ext.multipart.Attachment; +import org.apache.cxf.jaxrs.ext.multipart.Multipart; +import java.io.InputStream; import java.util.List; - +import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceCreationModel; +import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceListResponse; +import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourcePatchModel; +import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceResponse; +import org.wso2.carbon.identity.api.server.api.resource.v1.Error; +import java.util.List; +import org.wso2.carbon.identity.api.server.api.resource.v1.ScopeCreationModel; +import org.wso2.carbon.identity.api.server.api.resource.v1.ScopeGetModel; import javax.ws.rs.core.Response; @@ -39,5 +51,5 @@ public interface ApiResourcesApiService { public Response apiResourcesApiResourceIdScopesScopeNameDelete(String apiResourceId, String scopeName); - public Response getAPIResources(String before, String after, String filter, Integer limit, String requiredAttributes); + public Response getAPIResources(String before, String after, String filter, Integer limit, String attributes); } diff --git a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/Property.java b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/Property.java new file mode 100644 index 0000000000..665a3bc98e --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/Property.java @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * 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.identity.api.server.api.resource.v1; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.*; + + +import io.swagger.annotations.*; +import java.util.Objects; +import javax.validation.Valid; +import javax.xml.bind.annotation.*; + +public class Property { + + private String name; + private String value; + + /** + **/ + public Property name(String name) { + + this.name = name; + return this; + } + + @ApiModelProperty(example = "label", required = true, value = "") + @JsonProperty("name") + @Valid + @NotNull(message = "Property name cannot be null.") + + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + /** + **/ + public Property value(String value) { + + this.value = value; + return this; + } + + @ApiModelProperty(example = "Internal", required = true, value = "") + @JsonProperty("value") + @Valid + @NotNull(message = "Property value cannot be null.") + + public String getValue() { + return value; + } + public void setValue(String value) { + this.value = value; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Property property = (Property) o; + return Objects.equals(this.name, property.name) && + Objects.equals(this.value, property.value); + } + + @Override + public int hashCode() { + return Objects.hash(name, value); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class Property {\n"); + + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" value: ").append(toIndentedString(value)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n"); + } +} + diff --git a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/ScopesApi.java b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/ScopesApi.java index e44caef832..83564b4976 100644 --- a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/ScopesApi.java +++ b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/ScopesApi.java @@ -48,7 +48,7 @@ public class ScopesApi { @Produces({ "application/json" }) - @ApiOperation(value = "Get all scopes in the tenant", notes = "Get all scopes in the tenant", response = ScopeGetModel.class, responseContainer = "List", authorizations = { + @ApiOperation(value = "Get all scopes in the tenant", notes = "Get all scopes in the tenant Permission required:
* /permission/admin/manage/identity/apiresourcemgt/view
Scope required:
* internal_api_resource_view ", response = ScopeGetModel.class, responseContainer = "List", authorizations = { @Authorization(value = "BasicAuth"), @Authorization(value = "OAuth2", scopes = { diff --git a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/constants/APIResourceMgtEndpointConstants.java b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/constants/APIResourceMgtEndpointConstants.java index 6e212893ae..effd165c5b 100644 --- a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/constants/APIResourceMgtEndpointConstants.java +++ b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/constants/APIResourceMgtEndpointConstants.java @@ -33,8 +33,14 @@ private APIResourceMgtEndpointConstants() { public static final String API_RESOURCE_TYPE = "BUSINESS"; public static final String API_RESOURCE_MANAGEMENT_PREFIX = "API-RESOURCE-"; public static final String API_RESOURCE_PATH_COMPONENT = "/api-resources"; + private static final List allowedAttributeList = new ArrayList<>(); public static final List ALLOWED_SEARCH_ATTRIBUTES = Collections.unmodifiableList(allowedAttributeList); + + private static final List supportedRequiredAttributeList = new ArrayList<>(); + public static final List SUPPORTED_REQUIRED_ATTRIBUTES = Collections + .unmodifiableList(supportedRequiredAttributeList); + public static final String RESTRICTED_OAUTH2_SCOPES = "OAuth.RestrictedScopes.RestrictedScope"; public static final Integer DEFAULT_LIMIT = 10; public static final String ASC_SORT_ORDER = "ASC"; @@ -45,6 +51,8 @@ private APIResourceMgtEndpointConstants() { allowedAttributeList.add("type"); allowedAttributeList.add("requires_authorization"); allowedAttributeList.add("scopes"); + + supportedRequiredAttributeList.add("properties"); } /** @@ -79,6 +87,8 @@ public enum ErrorMessage { "Limit should be a positive integer."), ERROR_CODE_BOTH_BEFORE_AFTER_PROVIDED("60011", "Invalid before/after provided.", "Both before and after parameters cannot be provided at the same time."), + ERROR_CODE_INVALID_REQ_ATTRIBUTES("60012", "Invalid attribute name.", + "Invalid attribute name provided as required attribute."), // Server errors. ERROR_CODE_ADD_API_RESOURCE("65001", "Error while adding api resource.", "Server encountered an error while " + diff --git a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/core/ServerAPIResourceManagementService.java b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/core/ServerAPIResourceManagementService.java index 175260a62e..a1f4f24e21 100644 --- a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/core/ServerAPIResourceManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/core/ServerAPIResourceManagementService.java @@ -32,6 +32,7 @@ import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourcePatchModel; import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceResponse; import org.wso2.carbon.identity.api.server.api.resource.v1.PaginationLink; +import org.wso2.carbon.identity.api.server.api.resource.v1.Property; import org.wso2.carbon.identity.api.server.api.resource.v1.ScopeCreationModel; import org.wso2.carbon.identity.api.server.api.resource.v1.ScopeGetModel; import org.wso2.carbon.identity.api.server.api.resource.v1.constants.APIResourceMgtEndpointConstants; @@ -40,12 +41,14 @@ import org.wso2.carbon.identity.api.server.common.ContextLoader; import org.wso2.carbon.identity.api.server.common.error.APIError; import org.wso2.carbon.identity.application.common.model.APIResource; +import org.wso2.carbon.identity.application.common.model.APIResourceProperty; import org.wso2.carbon.identity.application.common.model.Scope; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Arrays; import java.util.Base64; import java.util.Collections; import java.util.List; @@ -99,7 +102,8 @@ public APIResourceResponse addAPIResourceWithResourceId(APIResourceCreationModel * @param filter filter parameter. * @return Response with API Resources list. */ - public APIResourceListResponse getAPIResources(String before, String after, String filter, Integer limit) { + public APIResourceListResponse getAPIResources(String before, String after, String filter, Integer limit, + String requiredAttributes) { APIResourceListResponse apiResourceListResponse = new APIResourceListResponse(); @@ -116,9 +120,23 @@ public APIResourceListResponse getAPIResources(String before, String after, Stri // Set the pagination sort order. String paginationSortOrder = StringUtils.isNotBlank(before) ? DESC_SORT_ORDER : ASC_SORT_ORDER; - APIResourceSearchResult apiResourceSearchResult = APIResourceManagementServiceHolder.getApiResourceManager() - .getAPIResources(before, after, limit + 1, filter, paginationSortOrder, - CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); + // Validate the required attributes. + List requestedAttributeList = new ArrayList<>(); + if (StringUtils.isNotEmpty(requiredAttributes)) { + requestedAttributeList = new ArrayList<>(Arrays.asList(requiredAttributes.split(","))); + validateRequiredAttributes(requestedAttributeList); + } + + APIResourceSearchResult apiResourceSearchResult; + if (CollectionUtils.isNotEmpty(requestedAttributeList)) { + apiResourceSearchResult = APIResourceManagementServiceHolder.getApiResourceManager() + .getAPIResourcesWithRequiredAttributes(before, after, limit + 1, filter, paginationSortOrder, + CarbonContext.getThreadLocalCarbonContext().getTenantDomain(), requestedAttributeList); + } else { + apiResourceSearchResult = APIResourceManagementServiceHolder.getApiResourceManager() + .getAPIResources(before, after, limit + 1, filter, paginationSortOrder, + CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); + } List apiResources = apiResourceSearchResult.getAPIResources(); if (CollectionUtils.isNotEmpty(apiResources)) { @@ -346,7 +364,22 @@ private APIResourceResponse buildAPIResourceResponse(APIResource apiResource) { .description(apiResource.getDescription()) .scopes(apiResource.getScopes().stream().map(this::buildScopeGetResponse) .collect(Collectors.toList())) - .requiresAuthorization(apiResource.isAuthorizationRequired()); + .requiresAuthorization(apiResource.isAuthorizationRequired()) + .properties(apiResource.getProperties().stream().map(this::buildAPIResourceProperty) + .collect(Collectors.toList())); + } + + /** + * Build Property from APIResourceProperty. + * + * @param apiResourceProperty APIResourceProperty object. + * @return Property object. + */ + private Property buildAPIResourceProperty(APIResourceProperty apiResourceProperty) { + + return new Property() + .name(apiResourceProperty.getName()) + .value(apiResourceProperty.getValue()); } /** @@ -418,12 +451,17 @@ private List createScopes(List scopeCreationModels) */ private APIResourceListItem buildAPIResourceListItem(APIResource apiResource) { + List properties = apiResource.getProperties() != null ? + apiResource.getProperties().stream().map(this::buildAPIResourceProperty).collect(Collectors.toList()) : + null; + return new APIResourceListItem() .id(apiResource.getId()) .name(apiResource.getName()) .identifier(apiResource.getIdentifier()) .type(apiResource.getType()) .requiresAuthorization(apiResource.isAuthorizationRequired()) + .properties(properties) .self(V1_API_PATH_COMPONENT + APIResourceMgtEndpointConstants.API_RESOURCE_PATH_COMPONENT + "/" + apiResource.getId()); } @@ -459,4 +497,20 @@ private static Integer validatedLimit(Integer limit) throws APIError { } return limit; } + + /** + * Validate required attributes. + * + * @param requiredAttributeList Requested attribute list. + * @throws APIError if the requested attributes are invalid. + */ + private void validateRequiredAttributes(List requiredAttributeList) throws APIError { + + for (String attribute : requiredAttributeList) { + if (!(APIResourceMgtEndpointConstants.SUPPORTED_REQUIRED_ATTRIBUTES.contains(attribute))) { + throw APIResourceMgtEndpointUtil.handleException(Response.Status.BAD_REQUEST, + ErrorMessage.ERROR_CODE_INVALID_REQ_ATTRIBUTES); + } + } + } } diff --git a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/impl/ApiResourcesApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/impl/ApiResourcesApiServiceImpl.java index 97008c6793..8b6472e26a 100644 --- a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/impl/ApiResourcesApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/impl/ApiResourcesApiServiceImpl.java @@ -96,9 +96,9 @@ public Response apiResourcesApiResourceIdScopesScopeNameDelete(String apiResourc } @Override - public Response getAPIResources(String before, String after, String filter, Integer limit, String sortOrder) { + public Response getAPIResources(String before, String after, String filter, Integer limit, String attributes) { - return Response.ok().entity(serverAPIResourceManagementService.getAPIResources(before, after, filter, limit)) - .build(); + return Response.ok().entity(serverAPIResourceManagementService.getAPIResources(before, after, filter, limit, + attributes)).build(); } } diff --git a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/resources/APIResources.yaml b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/resources/APIResources.yaml index aae71fe967..996ed0c4d9 100644 --- a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/resources/APIResources.yaml +++ b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/resources/APIResources.yaml @@ -100,7 +100,7 @@ paths: - $ref: '#/components/parameters/after' - $ref: '#/components/parameters/filter' - $ref: '#/components/parameters/limit' - - $ref: '#/components/parameters/requiredAttributes' + - $ref: '#/components/parameters/attributes' responses: 200: description: OK @@ -481,8 +481,8 @@ components: type: integer example: 10 - requiredAttributes: - name: requiredAttributes + attributes: + name: attributes in: query required: false description: Specifies the required parameters in the response. This parameter is not supported yet @@ -529,6 +529,10 @@ components: requiresAuthorization: type: boolean example: true + properties: + type: array + items: + $ref: '#/components/schemas/Property' self: type: string example: /t/carbon.super/api/server/v1/api-resources/eDUwOUNlcnRpZmljYXRlQXV0aGVudGljYXRvcg @@ -567,6 +571,10 @@ components: type: array items: $ref: '#/components/schemas/SubscribedApplicationGetModel' + properties: + type: array + items: + $ref: '#/components/schemas/Property' self: type: string example: /t/carbon.super/api/server/v1/api-resources/eDUwOUNlcnRpZmljYXRlQXV0aGVudGljYXRvcg @@ -685,6 +693,19 @@ components: type: string example: 23fd-23gd-54vv-sdhf + Property: + type: object + required: + - name + - value + properties: + name: + type: string + example: "label" + value: + type: string + example: "Internal" + responses: BadRequest: description: Bad Request. Invalid request or validation error. From a554f52ff09da65532f69df35742292f62212fe4 Mon Sep 17 00:00:00 2001 From: SujanSanjula96 Date: Fri, 20 Oct 2023 09:31:56 +0530 Subject: [PATCH 2/3] Fix review comments --- .../identity/api/server/api/resource/v1/ApiResourcesApi.java | 2 +- .../resource/v1/constants/APIResourceMgtEndpointConstants.java | 2 +- .../src/main/resources/APIResources.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/ApiResourcesApi.java b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/ApiResourcesApi.java index 38c6be4cc0..5345ffa8ee 100644 --- a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/ApiResourcesApi.java +++ b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/ApiResourcesApi.java @@ -230,7 +230,7 @@ public Response apiResourcesApiResourceIdScopesScopeNameDelete(@ApiParam(value = @ApiResponse(code = 403, message = "Forbidden", response = Void.class), @ApiResponse(code = 500, message = "Server Error", response = Error.class) }) - public Response getAPIResources( @Valid@ApiParam(value = "Base64 encoded cursor value for backward pagination. ") @QueryParam("before") String before, @Valid@ApiParam(value = "Base64 encoded cursor value for forward pagination. ") @QueryParam("after") String after, @Valid@ApiParam(value = "Condition to filter the retrieval of records. Supports 'sw', 'co', 'ew' and 'eq' operations. ") @QueryParam("filter") String filter, @Valid@ApiParam(value = "Maximum number of records to return. ") @QueryParam("limit") Integer limit, @Valid@ApiParam(value = "Specifies the required parameters in the response. This parameter is not supported yet") @QueryParam("attributes") String attributes) { + public Response getAPIResources( @Valid@ApiParam(value = "Base64 encoded cursor value for backward pagination. ") @QueryParam("before") String before, @Valid@ApiParam(value = "Base64 encoded cursor value for forward pagination. ") @QueryParam("after") String after, @Valid@ApiParam(value = "Condition to filter the retrieval of records. Supports 'sw', 'co', 'ew' and 'eq' operations. ") @QueryParam("filter") String filter, @Valid@ApiParam(value = "Maximum number of records to return. ") @QueryParam("limit") Integer limit, @Valid@ApiParam(value = "Specifies the required attributes in the response. Only 'properties' attribute is currently supported.") @QueryParam("attributes") String attributes) { return delegate.getAPIResources(before, after, filter, limit, attributes ); } diff --git a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/constants/APIResourceMgtEndpointConstants.java b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/constants/APIResourceMgtEndpointConstants.java index 8de7d1a435..ac88b391de 100644 --- a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/constants/APIResourceMgtEndpointConstants.java +++ b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/constants/APIResourceMgtEndpointConstants.java @@ -90,7 +90,7 @@ public enum ErrorMessage { "Both before and after parameters cannot be provided at the same time."), ERROR_CODE_SYSTEM_API_RESOURCE_NOT_MODIFIABLE("60012", "Cannot modify or delete System APIs.", "Cannot modify or delete the read-only System APIs."), - ERROR_CODE_INVALID_REQ_ATTRIBUTES("60012", "Invalid attribute name.", + ERROR_CODE_INVALID_REQ_ATTRIBUTES("60013", "Invalid attribute name.", "Invalid attribute name provided as required attribute."), // Server errors. diff --git a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/resources/APIResources.yaml b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/resources/APIResources.yaml index 996ed0c4d9..71022af4da 100644 --- a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/resources/APIResources.yaml +++ b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/resources/APIResources.yaml @@ -485,7 +485,7 @@ components: name: attributes in: query required: false - description: Specifies the required parameters in the response. This parameter is not supported yet + description: Specifies the required attributes in the response. Only 'properties' attribute is currently supported. schema: type: string From 4cbdac72d5fe9ce8d89044db5c624d4f1d495370 Mon Sep 17 00:00:00 2001 From: SujanSanjula96 Date: Sat, 21 Oct 2023 16:44:36 +0530 Subject: [PATCH 3/3] Bump framework version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 68b7dee6b4..1b3ec51cde 100644 --- a/pom.xml +++ b/pom.xml @@ -760,7 +760,7 @@ 1.4 1.2.4 1.8.62 - 5.25.383 + 5.25.416 3.0.5 5.2.0 **/gen/**/*