From f4fa5a926a553a653dda57baa1d89b4d7b12ce21 Mon Sep 17 00:00:00 2001 From: Pasindu Yeshan Date: Thu, 2 Nov 2023 17:23:09 +0530 Subject: [PATCH 01/15] Generate API resource collection API --- .../v1/APIResourceCollectionListItem.java | 190 +++++++++++++++++ .../v1/APIResourceCollectionListResponse.java | 131 ++++++++++++ .../v1/APIResourceCollectionResponse.java | 200 ++++++++++++++++++ .../v1/ApiResourceCollectionsApi.java | 91 ++++++++ .../v1/ApiResourceCollectionsApiService.java | 38 ++++ .../api/resource/v1/PaginationLink.java | 2 +- ...iResourceCollectionsApiServiceFactory.java | 32 +++ .../ApiResourceCollectionsApiServiceImpl.java | 43 ++++ .../src/main/resources/APIResources.yaml | 154 +++++++++++++- 9 files changed, 870 insertions(+), 11 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/APIResourceCollectionListItem.java 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/APIResourceCollectionListResponse.java 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/APIResourceCollectionResponse.java 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/ApiResourceCollectionsApi.java 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/ApiResourceCollectionsApiService.java 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/factories/ApiResourceCollectionsApiServiceFactory.java create mode 100644 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/ApiResourceCollectionsApiServiceImpl.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/APIResourceCollectionListItem.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/APIResourceCollectionListItem.java new file mode 100644 index 0000000000..f038bc910e --- /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/APIResourceCollectionListItem.java @@ -0,0 +1,190 @@ +/* + * 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 APIResourceCollectionListItem { + + private String id; + private String name; + private String displayName; + private String type; + private String self; + + /** + **/ + public APIResourceCollectionListItem id(String id) { + + this.id = id; + return this; + } + + @ApiModelProperty(example = "gh43-jk34-vb34-df67", required = true, value = "") + @JsonProperty("id") + @Valid + @NotNull(message = "Property id cannot be null.") + + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + + /** + **/ + public APIResourceCollectionListItem name(String name) { + + this.name = name; + return this; + } + + @ApiModelProperty(example = "bulkUserImport", 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 APIResourceCollectionListItem displayName(String displayName) { + + this.displayName = displayName; + return this; + } + + @ApiModelProperty(example = "Bulk User Import", required = true, value = "") + @JsonProperty("displayName") + @Valid + @NotNull(message = "Property displayName cannot be null.") + + public String getDisplayName() { + return displayName; + } + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + /** + **/ + public APIResourceCollectionListItem type(String type) { + + this.type = type; + return this; + } + + @ApiModelProperty(example = "SYSTEM", value = "") + @JsonProperty("type") + @Valid + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + + /** + **/ + public APIResourceCollectionListItem self(String self) { + + this.self = self; + return this; + } + + @ApiModelProperty(example = "/t/carbon.super/api/server/v1/api-resource-collections/eDUwOUNlcnRpZmljYXRlQXV0aGVudGljYXRvcg", required = true, value = "") + @JsonProperty("self") + @Valid + @NotNull(message = "Property self cannot be null.") + + public String getSelf() { + return self; + } + public void setSelf(String self) { + this.self = self; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + APIResourceCollectionListItem apIResourceCollectionListItem = (APIResourceCollectionListItem) o; + return Objects.equals(this.id, apIResourceCollectionListItem.id) && + Objects.equals(this.name, apIResourceCollectionListItem.name) && + Objects.equals(this.displayName, apIResourceCollectionListItem.displayName) && + Objects.equals(this.type, apIResourceCollectionListItem.type) && + Objects.equals(this.self, apIResourceCollectionListItem.self); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, displayName, type, self); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class APIResourceCollectionListItem {\n"); + + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" displayName: ").append(toIndentedString(displayName)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" self: ").append(toIndentedString(self)).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/APIResourceCollectionListResponse.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/APIResourceCollectionListResponse.java new file mode 100644 index 0000000000..12e7633237 --- /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/APIResourceCollectionListResponse.java @@ -0,0 +1,131 @@ +/* + * 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 java.util.ArrayList; +import java.util.List; +import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceCollectionListItem; +import javax.validation.constraints.*; + + +import io.swagger.annotations.*; +import java.util.Objects; +import javax.validation.Valid; +import javax.xml.bind.annotation.*; + +public class APIResourceCollectionListResponse { + + private Integer totalResults; + private List apIResourceCollections = null; + + + /** + **/ + public APIResourceCollectionListResponse totalResults(Integer totalResults) { + + this.totalResults = totalResults; + return this; + } + + @ApiModelProperty(example = "1", value = "") + @JsonProperty("totalResults") + @Valid + public Integer getTotalResults() { + return totalResults; + } + public void setTotalResults(Integer totalResults) { + this.totalResults = totalResults; + } + + /** + **/ + public APIResourceCollectionListResponse apIResourceCollections(List apIResourceCollections) { + + this.apIResourceCollections = apIResourceCollections; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("APIResourceCollections") + @Valid + public List getApIResourceCollections() { + return apIResourceCollections; + } + public void setApIResourceCollections(List apIResourceCollections) { + this.apIResourceCollections = apIResourceCollections; + } + + public APIResourceCollectionListResponse addApIResourceCollectionsItem(APIResourceCollectionListItem apIResourceCollectionsItem) { + if (this.apIResourceCollections == null) { + this.apIResourceCollections = new ArrayList(); + } + this.apIResourceCollections.add(apIResourceCollectionsItem); + return this; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + APIResourceCollectionListResponse apIResourceCollectionListResponse = (APIResourceCollectionListResponse) o; + return Objects.equals(this.totalResults, apIResourceCollectionListResponse.totalResults) && + Objects.equals(this.apIResourceCollections, apIResourceCollectionListResponse.apIResourceCollections); + } + + @Override + public int hashCode() { + return Objects.hash(totalResults, apIResourceCollections); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class APIResourceCollectionListResponse {\n"); + + sb.append(" totalResults: ").append(toIndentedString(totalResults)).append("\n"); + sb.append(" apIResourceCollections: ").append(toIndentedString(apIResourceCollections)).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/APIResourceCollectionResponse.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/APIResourceCollectionResponse.java new file mode 100644 index 0000000000..f6811b0437 --- /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/APIResourceCollectionResponse.java @@ -0,0 +1,200 @@ +/* + * 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 java.util.ArrayList; +import java.util.List; +import org.wso2.carbon.identity.api.server.api.resource.v1.ScopeGetModel; +import javax.validation.constraints.*; + + +import io.swagger.annotations.*; +import java.util.Objects; +import javax.validation.Valid; +import javax.xml.bind.annotation.*; + +public class APIResourceCollectionResponse { + + private String id; + private String name; + private String displayName; + private String type; + private List scopes = null; + + + /** + **/ + public APIResourceCollectionResponse id(String id) { + + this.id = id; + return this; + } + + @ApiModelProperty(example = "gh43-jk34-vb34-df67", required = true, value = "") + @JsonProperty("id") + @Valid + @NotNull(message = "Property id cannot be null.") + + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + + /** + **/ + public APIResourceCollectionResponse name(String name) { + + this.name = name; + return this; + } + + @ApiModelProperty(example = "bulkUserImport", 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 APIResourceCollectionResponse displayName(String displayName) { + + this.displayName = displayName; + return this; + } + + @ApiModelProperty(example = "Bulk User Import", required = true, value = "") + @JsonProperty("displayName") + @Valid + @NotNull(message = "Property displayName cannot be null.") + + public String getDisplayName() { + return displayName; + } + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + /** + **/ + public APIResourceCollectionResponse type(String type) { + + this.type = type; + return this; + } + + @ApiModelProperty(example = "SYSTEM", value = "") + @JsonProperty("type") + @Valid + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + + /** + **/ + public APIResourceCollectionResponse scopes(List scopes) { + + this.scopes = scopes; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("scopes") + @Valid + public List getScopes() { + return scopes; + } + public void setScopes(List scopes) { + this.scopes = scopes; + } + + public APIResourceCollectionResponse addScopesItem(ScopeGetModel scopesItem) { + if (this.scopes == null) { + this.scopes = new ArrayList(); + } + this.scopes.add(scopesItem); + return this; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + APIResourceCollectionResponse apIResourceCollectionResponse = (APIResourceCollectionResponse) o; + return Objects.equals(this.id, apIResourceCollectionResponse.id) && + Objects.equals(this.name, apIResourceCollectionResponse.name) && + Objects.equals(this.displayName, apIResourceCollectionResponse.displayName) && + Objects.equals(this.type, apIResourceCollectionResponse.type) && + Objects.equals(this.scopes, apIResourceCollectionResponse.scopes); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, displayName, type, scopes); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class APIResourceCollectionResponse {\n"); + + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" displayName: ").append(toIndentedString(displayName)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" scopes: ").append(toIndentedString(scopes)).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/ApiResourceCollectionsApi.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/ApiResourceCollectionsApi.java new file mode 100644 index 0000000000..d1369caadd --- /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/ApiResourceCollectionsApi.java @@ -0,0 +1,91 @@ +/* + * 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 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.APIResourceCollectionListResponse; +import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceCollectionResponse; +import org.wso2.carbon.identity.api.server.api.resource.v1.Error; +import org.wso2.carbon.identity.api.server.api.resource.v1.ApiResourceCollectionsApiService; + +import javax.validation.Valid; +import javax.ws.rs.*; +import javax.ws.rs.core.Response; +import io.swagger.annotations.*; + +import javax.validation.constraints.*; + +@Path("/api-resource-collections") +@Api(description = "The api-resource-collections API") + +public class ApiResourceCollectionsApi { + + @Autowired + private ApiResourceCollectionsApiService delegate; + + @Valid + @GET + @Path("/{collectionId}") + + @Produces({ "application/json" }) + @ApiOperation(value = "Get API resource collection specified by the id", notes = "Get API resource collection specified by the id Permission required:
* /permission/admin/manage/identity/apiresourcemgt/view
Scope required:
* internal_api_resource_view ", response = APIResourceCollectionResponse.class, authorizations = { + @Authorization(value = "BasicAuth"), + @Authorization(value = "OAuth2", scopes = { + + }) + }, tags={ "API Resource Collections", }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "OK", response = APIResourceCollectionResponse.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 apiResourceCollectionsCollectionIdGet(@ApiParam(value = "ID of the API Resource Collection.",required=true) @PathParam("collectionId") String collectionId) { + + return delegate.apiResourceCollectionsCollectionIdGet(collectionId ); + } + + @Valid + @GET + + + @Produces({ "application/json" }) + @ApiOperation(value = "List all API resource collections in the server", notes = "List all API resource collections in the server Permission required:
* /permission/admin/manage/identity/apiresourcemgt/view
Scope required:
* internal_api_resource_view ", response = APIResourceCollectionListResponse.class, authorizations = { + @Authorization(value = "BasicAuth"), + @Authorization(value = "OAuth2", scopes = { + + }) + }, tags={ "API Resource Collections" }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "OK", response = APIResourceCollectionListResponse.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 getAPIResourceCollections( @Valid@ApiParam(value = "Condition to filter the retrieval of records. Supports 'sw', 'co', 'ew' and 'eq' operations. ") @QueryParam("filter") String filter) { + + return delegate.getAPIResourceCollections(filter ); + } + +} 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/ApiResourceCollectionsApiService.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/ApiResourceCollectionsApiService.java new file mode 100644 index 0000000000..840bc259ca --- /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/ApiResourceCollectionsApiService.java @@ -0,0 +1,38 @@ +/* + * 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 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.APIResourceCollectionListResponse; +import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceCollectionResponse; +import org.wso2.carbon.identity.api.server.api.resource.v1.Error; +import javax.ws.rs.core.Response; + + +public interface ApiResourceCollectionsApiService { + + public Response apiResourceCollectionsCollectionIdGet(String collectionId); + + public Response getAPIResourceCollections(String filter); +} 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/PaginationLink.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/PaginationLink.java index 3403c2f707..92099b2caf 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/PaginationLink.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/PaginationLink.java @@ -61,7 +61,7 @@ public PaginationLink href(String href) { return this; } - @ApiModelProperty(example = "/o/orgName/api-resources?after=NDoy", value = "") + @ApiModelProperty(example = "/t/carbon.super/api/server/v1/api-resources?after=NDoy", value = "") @JsonProperty("href") @Valid public String getHref() { 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/factories/ApiResourceCollectionsApiServiceFactory.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/factories/ApiResourceCollectionsApiServiceFactory.java new file mode 100644 index 0000000000..1998e08afe --- /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/factories/ApiResourceCollectionsApiServiceFactory.java @@ -0,0 +1,32 @@ +/* + * 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.factories; + +import org.wso2.carbon.identity.api.server.api.resource.v1.ApiResourceCollectionsApiService; +import org.wso2.carbon.identity.api.server.api.resource.v1.impl.ApiResourceCollectionsApiServiceImpl; + +public class ApiResourceCollectionsApiServiceFactory { + + private final static ApiResourceCollectionsApiService service = new ApiResourceCollectionsApiServiceImpl(); + + public static ApiResourceCollectionsApiService getApiResourceCollectionsApi() + { + return service; + } +} 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/ApiResourceCollectionsApiServiceImpl.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/ApiResourceCollectionsApiServiceImpl.java new file mode 100644 index 0000000000..a2fff9b327 --- /dev/null +++ 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/ApiResourceCollectionsApiServiceImpl.java @@ -0,0 +1,43 @@ +/* + * 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.impl; + +import org.wso2.carbon.identity.api.server.api.resource.v1.ApiResourceCollectionsApiService; + +import javax.ws.rs.core.Response; + +/** + * Implementation of the Api resource collection REST Api. + */ +public class ApiResourceCollectionsApiServiceImpl implements ApiResourceCollectionsApiService { + + @Override + public Response apiResourceCollectionsCollectionIdGet(String collectionId) { + + // do some magic! + return Response.ok().entity("magic!").build(); + } + + @Override + public Response getAPIResourceCollections(String filter) { + + // do some magic! + return Response.ok().entity("magic!").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 71022af4da..fc1a0f956d 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 @@ -33,7 +33,7 @@ paths: - API Resources operationId: addAPIResource summary: Add a new API resource - description: > + description: > Add a new API resource Permission required:
* /permission/admin/manage/identity/apiresourcemgt/create
@@ -88,7 +88,7 @@ paths: tags: - API Resources summary: List all API resources in the server - description: > + description: > List all API resources in the server Permission required:
* /permission/admin/manage/identity/apiresourcemgt/view
@@ -124,7 +124,7 @@ paths: tags: - API Resources summary: Get API resource specified by the id - description: > + description: > Get API resource specified by the id Permission required:
* /permission/admin/manage/identity/apiresourcemgt/view
@@ -154,7 +154,7 @@ paths: tags: - API Resources summary: Patch API resource specified by the id - description: > + description: > 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
@@ -214,7 +214,7 @@ paths: tags: - API Resources summary: Delete API resource specified by the id - description: > + description: > Delete API resource specified by the id Permission required:
* /permission/admin/manage/identity/apiresourcemgt/delete
@@ -241,7 +241,7 @@ paths: tags: - API Resource Scopes summary: Get API resource scopes - description: > + description: > Get API resource scopes specified by the id Permission required:
* /permission/admin/manage/identity/apiresourcemgt/view
@@ -279,7 +279,7 @@ paths: tags: - API Resource Scopes summary: Add scopes to API resource - description: > + description: > Put scopes API resource specified by the id Permission required:
* /permission/admin/manage/identity/apiresourcemgt/update
@@ -337,7 +337,7 @@ paths: tags: - API Resource Scopes summary: Delete API scope specified by the name - description: > + description: > Delete API scope specified by the name Permission required:
* /permission/admin/manage/identity/apiresourcemgt/delete
@@ -363,7 +363,7 @@ paths: tags: - API Resource Scopes summary: Get all scopes in the tenant - description: > + description: > Get all scopes in the tenant Permission required:
* /permission/admin/manage/identity/apiresourcemgt/view
@@ -397,6 +397,69 @@ paths: schema: $ref: '#/components/schemas/Error' + /api-resource-collections: + get: + tags: + - API Resource Collections + summary: List all API resource collections in the server + description: > + List all API resource collections in the server + Permission required:
+ * /permission/admin/manage/identity/apiresourcemgt/view
+ Scope required:
+ * internal_api_resource_view + operationId: getAPIResourceCollections + parameters: + - $ref: '#/components/parameters/filter' + responses: + 200: + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/APIResourceCollectionListResponse' + 401: + description: Unauthorized + 403: + description: Forbidden + 500: + description: Server Error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + + /api-resource-collections/{collectionId}: + get: + tags: + - API Resource Collections + summary: Get API resource collection specified by the id + description: > + Get API resource collection specified by the id + Permission required:
+ * /permission/admin/manage/identity/apiresourcemgt/view
+ Scope required:
+ * internal_api_resource_view + parameters: + - $ref: '#/components/parameters/collectionId' + responses: + 200: + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/APIResourceCollectionResponse' + 401: + description: Unauthorized + 403: + description: Forbidden + 500: + description: Server Error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + components: parameters: organizationId: @@ -417,6 +480,15 @@ components: type: string example: er34-gf23-bv54-vb90 + collectionId: + name: collectionId + in: path + description: ID of the API Resource Collection. + required: true + schema: + type: string + example: er34-gf23-bv54-vb90 + scopeName: name: scopeName in: path @@ -629,7 +701,7 @@ components: example: before href: type: string - example: /o/orgName/api-resources?after=NDoy + example: /t/carbon.super/api/server/v1/api-resources?after=NDoy APIResourceListResponse: type: object @@ -648,6 +720,68 @@ components: items: $ref: '#/components/schemas/APIResourceListItem' + APIResourceCollectionListItem: + type: object + required: + - id + - name + - displayName + - self + properties: + id: + type: string + example: gh43-jk34-vb34-df67 + name: + type: string + example: bulkUserImport + displayName: + type: string + example: Bulk User Import + type: + type: string + example: SYSTEM + self: + type: string + example: /t/carbon.super/api/server/v1/api-resource-collections/eDUwOUNlcnRpZmljYXRlQXV0aGVudGljYXRvcg + + APIResourceCollectionListResponse: + type: object + required: + - links + properties: + totalResults: + type: integer + example: 1 + APIResourceCollections: + type: array + items: + $ref: '#/components/schemas/APIResourceCollectionListItem' + + APIResourceCollectionResponse: + type: object + required: + - id + - name + - displayName + - self + properties: + id: + type: string + example: gh43-jk34-vb34-df67 + name: + type: string + example: bulkUserImport + displayName: + type: string + example: Bulk User Import + type: + type: string + example: SYSTEM + scopes: + type: array + items: + $ref: '#/components/schemas/ScopeGetModel' + ScopeGetModel: type: object required: From b8d6693b010d3e88b9dee0d599c024a1f346dfdd Mon Sep 17 00:00:00 2001 From: Pasindu Yeshan Date: Thu, 2 Nov 2023 17:36:43 +0530 Subject: [PATCH 02/15] Add new method --- .../api/server/api/resource/v1/ApiResourceCollectionsApi.java | 4 ++-- .../api/resource/v1/ApiResourceCollectionsApiService.java | 2 +- .../v1/impl/ApiResourceCollectionsApiServiceImpl.java | 4 ++-- .../src/main/resources/APIResources.yaml | 1 + 4 files changed, 6 insertions(+), 5 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/ApiResourceCollectionsApi.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/ApiResourceCollectionsApi.java index d1369caadd..6d9c564bb6 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/ApiResourceCollectionsApi.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/ApiResourceCollectionsApi.java @@ -61,9 +61,9 @@ public class ApiResourceCollectionsApi { @ApiResponse(code = 403, message = "Forbidden", response = Void.class), @ApiResponse(code = 500, message = "Server Error", response = Error.class) }) - public Response apiResourceCollectionsCollectionIdGet(@ApiParam(value = "ID of the API Resource Collection.",required=true) @PathParam("collectionId") String collectionId) { + public Response getAPIResourceCollectionByCollectionId(@ApiParam(value = "ID of the API Resource Collection.",required=true) @PathParam("collectionId") String collectionId) { - return delegate.apiResourceCollectionsCollectionIdGet(collectionId ); + return delegate.getAPIResourceCollectionByCollectionId(collectionId ); } @Valid 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/ApiResourceCollectionsApiService.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/ApiResourceCollectionsApiService.java index 840bc259ca..2dd823a503 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/ApiResourceCollectionsApiService.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/ApiResourceCollectionsApiService.java @@ -32,7 +32,7 @@ public interface ApiResourceCollectionsApiService { - public Response apiResourceCollectionsCollectionIdGet(String collectionId); + public Response getAPIResourceCollectionByCollectionId(String collectionId); public Response getAPIResourceCollections(String filter); } 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/ApiResourceCollectionsApiServiceImpl.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/ApiResourceCollectionsApiServiceImpl.java index a2fff9b327..bcbc0a3ce3 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/ApiResourceCollectionsApiServiceImpl.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/ApiResourceCollectionsApiServiceImpl.java @@ -23,12 +23,12 @@ import javax.ws.rs.core.Response; /** - * Implementation of the Api resource collection REST Api. + * Implementation of the API resource collections REST API. */ public class ApiResourceCollectionsApiServiceImpl implements ApiResourceCollectionsApiService { @Override - public Response apiResourceCollectionsCollectionIdGet(String collectionId) { + public Response getAPIResourceCollectionByCollectionId(String collectionId) { // do some magic! return Response.ok().entity("magic!").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 fc1a0f956d..196932179f 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 @@ -440,6 +440,7 @@ paths: * /permission/admin/manage/identity/apiresourcemgt/view
Scope required:
* internal_api_resource_view + operationId: getAPIResourceCollectionByCollectionId parameters: - $ref: '#/components/parameters/collectionId' responses: From fbb89b29d3eb587989e3a437848c964272af58e4 Mon Sep 17 00:00:00 2001 From: Pasindu Yeshan Date: Sat, 4 Nov 2023 19:35:17 +0530 Subject: [PATCH 03/15] Add APIs --- .../pom.xml | 5 + .../APIResourceManagementServiceHolder.java | 22 ++ .../pom.xml | 5 + .../v1/APIResourceCollectionItem.java | 237 ++++++++++++++++++ .../v1/APIResourceCollectionListResponse.java | 30 +-- .../v1/APIResourceCollectionResponse.java | 32 +-- .../APIResourceMgtEndpointConstants.java | 6 +- ...PIResourceCollectionManagementService.java | 171 +++++++++++++ .../ApiResourceCollectionsApiServiceImpl.java | 12 +- .../v1/util/APIResourceMgtEndpointUtil.java | 17 ++ .../src/main/resources/APIResources.yaml | 37 ++- .../cxf/api-resource-server-v1-cxf.xml | 6 + 12 files changed, 541 insertions(+), 39 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/APIResourceCollectionItem.java create mode 100644 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/ServerAPIResourceCollectionManagementService.java diff --git a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.common/pom.xml b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.common/pom.xml index e31df154b7..4e55780413 100644 --- a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.common/pom.xml +++ b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.common/pom.xml @@ -68,5 +68,10 @@ org.wso2.carbon.identity.oauth provided + + org.wso2.carbon.identity.framework + org.wso2.carbon.identity.api.resource.collection.mgt + provided + diff --git a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.common/src/main/java/org/wso2/carbon/identity/api/server/api/resource/common/APIResourceManagementServiceHolder.java b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.common/src/main/java/org/wso2/carbon/identity/api/server/api/resource/common/APIResourceManagementServiceHolder.java index 01042f8d08..005b76a655 100644 --- a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.common/src/main/java/org/wso2/carbon/identity/api/server/api/resource/common/APIResourceManagementServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.common/src/main/java/org/wso2/carbon/identity/api/server/api/resource/common/APIResourceManagementServiceHolder.java @@ -18,6 +18,7 @@ package org.wso2.carbon.identity.api.server.api.resource.common; +import org.wso2.carbon.identity.api.resource.collection.mgt.APIResourceCollectionManager; import org.wso2.carbon.identity.api.resource.mgt.APIResourceManager; import org.wso2.carbon.identity.oauth.OAuthAdminServiceImpl; @@ -27,6 +28,7 @@ public class APIResourceManagementServiceHolder { private static APIResourceManager apiResourceManager; + private static APIResourceCollectionManager apiResourceCollectionManager; private static OAuthAdminServiceImpl oAuthAdminServiceImpl; /** @@ -49,6 +51,26 @@ public static void setApiResourceManager(APIResourceManager apiResourceManager) APIResourceManagementServiceHolder.apiResourceManager = apiResourceManager; } + /** + * Get APIResourceCollectionManager osgi service. + * + * @return APIResourceCollectionManager. + */ + public static APIResourceCollectionManager getApiResourceCollectionManager() { + + return apiResourceCollectionManager; + } + + /** + * Set APIResourceCollectionManager osgi service. + * + * @param apiResourceCollectionManager APIResourceCollectionManager. + */ + public static void setApiResourceCollectionManager(APIResourceCollectionManager apiResourceCollectionManager) { + + APIResourceManagementServiceHolder.apiResourceCollectionManager = apiResourceCollectionManager; + } + /** * Get OAuthAdminServiceImpl instance. * diff --git a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/pom.xml b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/pom.xml index c34ff62dbc..c1dc1f71c1 100644 --- a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/pom.xml +++ b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/pom.xml @@ -97,6 +97,11 @@ org.wso2.carbon.identity.api.resource.mgt provided + + org.wso2.carbon.identity.framework + org.wso2.carbon.identity.api.resource.collection.mgt + provided + org.wso2.carbon.identity.server.api org.wso2.carbon.identity.api.server.common 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/APIResourceCollectionItem.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/APIResourceCollectionItem.java new file mode 100644 index 0000000000..e06a9f54f3 --- /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/APIResourceCollectionItem.java @@ -0,0 +1,237 @@ +/* + * 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 io.swagger.annotations.ApiModelProperty; +import java.util.ArrayList; +import java.util.List; +import javax.validation.constraints.*; + + +import java.util.Objects; +import javax.validation.Valid; + +public class APIResourceCollectionItem { + + private String id; + private String name; + private String description; + private String identifier; + private String type; + private List scopes = null; + + private String self; + + /** + **/ + public APIResourceCollectionItem id(String id) { + + this.id = id; + return this; + } + + @ApiModelProperty(example = "gh43-jk34-vb34-df67", required = true, value = "") + @JsonProperty("id") + @Valid + @NotNull(message = "Property id cannot be null.") + + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + + /** + **/ + public APIResourceCollectionItem name(String name) { + + this.name = name; + return this; + } + + @ApiModelProperty(example = "Greetings API", 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 APIResourceCollectionItem description(String description) { + + this.description = description; + return this; + } + + @ApiModelProperty(example = "Greeting API representation", value = "") + @JsonProperty("description") + @Valid + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + + /** + **/ + public APIResourceCollectionItem identifier(String identifier) { + + this.identifier = identifier; + return this; + } + + @ApiModelProperty(example = "greetings_api", value = "") + @JsonProperty("identifier") + @Valid + public String getIdentifier() { + return identifier; + } + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + /** + **/ + public APIResourceCollectionItem type(String type) { + + this.type = type; + return this; + } + + @ApiModelProperty(example = "SYSTEM", value = "") + @JsonProperty("type") + @Valid + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + + /** + **/ + public APIResourceCollectionItem scopes(List scopes) { + + this.scopes = scopes; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("scopes") + @Valid + public List getScopes() { + return scopes; + } + public void setScopes(List scopes) { + this.scopes = scopes; + } + + public APIResourceCollectionItem addScopesItem(ScopeGetModel scopesItem) { + if (this.scopes == null) { + this.scopes = new ArrayList(); + } + this.scopes.add(scopesItem); + return this; + } + + /** + **/ + public APIResourceCollectionItem self(String self) { + + this.self = self; + return this; + } + + @ApiModelProperty(example = "/t/carbon.super/api/server/v1/api-resources/eDUwOUNlcnRpZmljYXRlQXV0aGVudGljYXRvcg", required = true, value = "") + @JsonProperty("self") + @Valid + @NotNull(message = "Property self cannot be null.") + + public String getSelf() { + return self; + } + public void setSelf(String self) { + this.self = self; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + APIResourceCollectionItem apIResourceCollectionItem = (APIResourceCollectionItem) o; + return Objects.equals(this.id, apIResourceCollectionItem.id) && + Objects.equals(this.name, apIResourceCollectionItem.name) && + Objects.equals(this.description, apIResourceCollectionItem.description) && + Objects.equals(this.identifier, apIResourceCollectionItem.identifier) && + Objects.equals(this.type, apIResourceCollectionItem.type) && + Objects.equals(this.scopes, apIResourceCollectionItem.scopes) && + Objects.equals(this.self, apIResourceCollectionItem.self); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, description, identifier, type, scopes, self); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class APIResourceCollectionItem {\n"); + + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" description: ").append(toIndentedString(description)).append("\n"); + sb.append(" identifier: ").append(toIndentedString(identifier)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" scopes: ").append(toIndentedString(scopes)).append("\n"); + sb.append(" self: ").append(toIndentedString(self)).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/APIResourceCollectionListResponse.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/APIResourceCollectionListResponse.java index 12e7633237..0d6675d214 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/APIResourceCollectionListResponse.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/APIResourceCollectionListResponse.java @@ -36,7 +36,7 @@ public class APIResourceCollectionListResponse { private Integer totalResults; - private List apIResourceCollections = null; + private List apiResourceCollections = null; /** @@ -59,27 +59,27 @@ public void setTotalResults(Integer totalResults) { /** **/ - public APIResourceCollectionListResponse apIResourceCollections(List apIResourceCollections) { + public APIResourceCollectionListResponse apiResourceCollections(List apiResourceCollections) { - this.apIResourceCollections = apIResourceCollections; + this.apiResourceCollections = apiResourceCollections; return this; } @ApiModelProperty(value = "") - @JsonProperty("APIResourceCollections") + @JsonProperty("apiResourceCollections") @Valid - public List getApIResourceCollections() { - return apIResourceCollections; + public List getApiResourceCollections() { + return apiResourceCollections; } - public void setApIResourceCollections(List apIResourceCollections) { - this.apIResourceCollections = apIResourceCollections; + public void setApiResourceCollections(List apiResourceCollections) { + this.apiResourceCollections = apiResourceCollections; } - public APIResourceCollectionListResponse addApIResourceCollectionsItem(APIResourceCollectionListItem apIResourceCollectionsItem) { - if (this.apIResourceCollections == null) { - this.apIResourceCollections = new ArrayList(); + public APIResourceCollectionListResponse addApiResourceCollectionsItem(APIResourceCollectionListItem apiResourceCollectionsItem) { + if (this.apiResourceCollections == null) { + this.apiResourceCollections = new ArrayList(); } - this.apIResourceCollections.add(apIResourceCollectionsItem); + this.apiResourceCollections.add(apiResourceCollectionsItem); return this; } @@ -96,12 +96,12 @@ public boolean equals(java.lang.Object o) { } APIResourceCollectionListResponse apIResourceCollectionListResponse = (APIResourceCollectionListResponse) o; return Objects.equals(this.totalResults, apIResourceCollectionListResponse.totalResults) && - Objects.equals(this.apIResourceCollections, apIResourceCollectionListResponse.apIResourceCollections); + Objects.equals(this.apiResourceCollections, apIResourceCollectionListResponse.apiResourceCollections); } @Override public int hashCode() { - return Objects.hash(totalResults, apIResourceCollections); + return Objects.hash(totalResults, apiResourceCollections); } @Override @@ -111,7 +111,7 @@ public String toString() { sb.append("class APIResourceCollectionListResponse {\n"); sb.append(" totalResults: ").append(toIndentedString(totalResults)).append("\n"); - sb.append(" apIResourceCollections: ").append(toIndentedString(apIResourceCollections)).append("\n"); + sb.append(" apiResourceCollections: ").append(toIndentedString(apiResourceCollections)).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/APIResourceCollectionResponse.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/APIResourceCollectionResponse.java index f6811b0437..6748350830 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/APIResourceCollectionResponse.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/APIResourceCollectionResponse.java @@ -24,7 +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.ScopeGetModel; +import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceCollectionItem; import javax.validation.constraints.*; @@ -39,7 +39,7 @@ public class APIResourceCollectionResponse { private String name; private String displayName; private String type; - private List scopes = null; + private List apiResources = null; /** @@ -122,27 +122,27 @@ public void setType(String type) { /** **/ - public APIResourceCollectionResponse scopes(List scopes) { + public APIResourceCollectionResponse apiResources(List apiResources) { - this.scopes = scopes; + this.apiResources = apiResources; return this; } @ApiModelProperty(value = "") - @JsonProperty("scopes") + @JsonProperty("apiResources") @Valid - public List getScopes() { - return scopes; + public List getApiResources() { + return apiResources; } - public void setScopes(List scopes) { - this.scopes = scopes; + public void setApiResources(List apiResources) { + this.apiResources = apiResources; } - public APIResourceCollectionResponse addScopesItem(ScopeGetModel scopesItem) { - if (this.scopes == null) { - this.scopes = new ArrayList(); + public APIResourceCollectionResponse addApiResourcesItem(APIResourceCollectionItem apiResourcesItem) { + if (this.apiResources == null) { + this.apiResources = new ArrayList(); } - this.scopes.add(scopesItem); + this.apiResources.add(apiResourcesItem); return this; } @@ -162,12 +162,12 @@ public boolean equals(java.lang.Object o) { Objects.equals(this.name, apIResourceCollectionResponse.name) && Objects.equals(this.displayName, apIResourceCollectionResponse.displayName) && Objects.equals(this.type, apIResourceCollectionResponse.type) && - Objects.equals(this.scopes, apIResourceCollectionResponse.scopes); + Objects.equals(this.apiResources, apIResourceCollectionResponse.apiResources); } @Override public int hashCode() { - return Objects.hash(id, name, displayName, type, scopes); + return Objects.hash(id, name, displayName, type, apiResources); } @Override @@ -180,7 +180,7 @@ public String toString() { sb.append(" name: ").append(toIndentedString(name)).append("\n"); sb.append(" displayName: ").append(toIndentedString(displayName)).append("\n"); sb.append(" type: ").append(toIndentedString(type)).append("\n"); - sb.append(" scopes: ").append(toIndentedString(scopes)).append("\n"); + sb.append(" apiResources: ").append(toIndentedString(apiResources)).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/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 ac88b391de..fb12151099 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 @@ -34,6 +34,7 @@ private APIResourceMgtEndpointConstants() { public static final String SYSTEM_API_RESOURCE_TYPE = "SYSTEM"; public static final String API_RESOURCE_MANAGEMENT_PREFIX = "API-RESOURCE-"; public static final String API_RESOURCE_PATH_COMPONENT = "/api-resources"; + public static final String API_RESOURCE_COLLECTION_PATH_COMPONENT = "/api-resource-collections"; private static final List allowedAttributeList = new ArrayList<>(); public static final List ALLOWED_SEARCH_ATTRIBUTES = Collections.unmodifiableList(allowedAttributeList); @@ -99,7 +100,10 @@ public enum ErrorMessage { ERROR_CODE_VALIDATE_SCOPES("65002", "Error while validating scopes.", "Server encountered an error while " + "validating the scopes."), - ; + ERROR_CODE_API_RESOURCE_COLLECTION_NOT_FOUND("600014", + "Unable to find the API resource collection.", + "Unable to find the API resource collection with the id: %s in the tenant domain."), + ; // TODO: Change code. private final String code; private final String message; private final String description; 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/ServerAPIResourceCollectionManagementService.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/ServerAPIResourceCollectionManagementService.java new file mode 100644 index 0000000000..093c63409d --- /dev/null +++ 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/ServerAPIResourceCollectionManagementService.java @@ -0,0 +1,171 @@ +/* + * 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.core; + +import org.wso2.carbon.context.CarbonContext; +import org.wso2.carbon.identity.api.resource.collection.mgt.exception.APIResourceCollectionMgtException; +import org.wso2.carbon.identity.api.resource.collection.mgt.model.APIResourceCollection; +import org.wso2.carbon.identity.api.resource.collection.mgt.model.APIResourceCollectionSearchResult; +import org.wso2.carbon.identity.api.server.api.resource.common.APIResourceManagementServiceHolder; +import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceCollectionItem; +import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceCollectionListItem; +import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceCollectionListResponse; +import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceCollectionResponse; +import org.wso2.carbon.identity.api.server.api.resource.v1.ScopeGetModel; +import org.wso2.carbon.identity.api.server.api.resource.v1.constants.APIResourceMgtEndpointConstants; +import org.wso2.carbon.identity.api.server.api.resource.v1.util.APIResourceMgtEndpointUtil; +import org.wso2.carbon.identity.application.common.model.APIResource; +import org.wso2.carbon.identity.application.common.model.Scope; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import javax.ws.rs.core.Response; + +import static org.wso2.carbon.identity.api.server.common.Constants.V1_API_PATH_COMPONENT; + +/** + * Server API Resource Collection Management Service. + */ +public class ServerAPIResourceCollectionManagementService { + + /** + * Get API Resource Collections List. + * + * @param filter filter string. + * @return API Resource Collections List. + */ + public APIResourceCollectionListResponse getAPIResourceCollections(String filter) { + + APIResourceCollectionListResponse apiResourceCollectionListResponse = new APIResourceCollectionListResponse(); + + try { + APIResourceCollectionSearchResult apiResourceCollectionSearchResult = APIResourceManagementServiceHolder + .getApiResourceCollectionManager().getAPIResourceCollections(filter); + + List apiResourceCollections = apiResourceCollectionSearchResult + .getAPIResourceCollections(); + if (apiResourceCollections == null || apiResourceCollections.isEmpty()) { + apiResourceCollectionListResponse.setTotalResults(0); + apiResourceCollectionListResponse.setApiResourceCollections(new ArrayList<>()); + return apiResourceCollectionListResponse; + } + apiResourceCollectionListResponse.setTotalResults(apiResourceCollectionSearchResult.getTotalCount()); + apiResourceCollectionListResponse.setApiResourceCollections( + apiResourceCollections.stream().map(this::buildAPIResourceCollectionListItem) + .collect(Collectors.toList())); + } catch (APIResourceCollectionMgtException e) { + throw APIResourceMgtEndpointUtil.handleAPIResourceCollectionMgtException(e); + } + return apiResourceCollectionListResponse; + } + + /** + * Get API Resource Collection by collection id. + * + * @param collectionId API Resource Collection id. + * @return API Resource Collection. + */ + public APIResourceCollectionResponse getAPIResourceCollectionByCollectionId(String collectionId) { + + APIResourceCollectionResponse apiResourceCollectionResponse = new APIResourceCollectionResponse(); + + try { + APIResourceCollection apiResourceCollection = APIResourceManagementServiceHolder + .getApiResourceCollectionManager().getAPIResourceCollectionById(collectionId, + CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); + if (apiResourceCollection == null) { + throw APIResourceMgtEndpointUtil.handleException(Response.Status.NOT_FOUND, + APIResourceMgtEndpointConstants.ErrorMessage.ERROR_CODE_API_RESOURCE_COLLECTION_NOT_FOUND, + collectionId); + } + apiResourceCollectionResponse.setId(apiResourceCollection.getId()); + apiResourceCollectionResponse.setName(apiResourceCollection.getName()); + apiResourceCollectionResponse.setDisplayName(apiResourceCollection.getDisplayName()); + apiResourceCollectionResponse.setType(apiResourceCollection.getType()); + + List apiResourceCollectionItems = + (apiResourceCollection.getApiResources() != null) + ? apiResourceCollection.getApiResources().stream() + .map(this::buildAPIResourceCollectionItem).collect(Collectors.toList()) + : Collections.emptyList(); + apiResourceCollectionResponse.setApiResources(apiResourceCollectionItems); + } catch (APIResourceCollectionMgtException e) { + throw APIResourceMgtEndpointUtil.handleAPIResourceCollectionMgtException(e); + } + return apiResourceCollectionResponse; + } + + /** + * Build API Resource Collection List Item from API Resource Collection. + * + * @param apiResourceCollection API Resource Collection. + * @return API Resource Collection List Item. + */ + private APIResourceCollectionListItem buildAPIResourceCollectionListItem( + APIResourceCollection apiResourceCollection) { + + return new APIResourceCollectionListItem() + .id(apiResourceCollection.getId()) + .name(apiResourceCollection.getName()) + .displayName(apiResourceCollection.getDisplayName()) + .type(apiResourceCollection.getType()) + .self(V1_API_PATH_COMPONENT + APIResourceMgtEndpointConstants.API_RESOURCE_COLLECTION_PATH_COMPONENT + + "/" + apiResourceCollection.getId()); + } + + /** + * Build ScopeGetModel from Scope. + * + * @param scope Scope object. + * @return ScopeGetModel object. + */ + private ScopeGetModel buildScopeGetResponse(Scope scope) { + + return new ScopeGetModel() + .id(scope.getId()) + .name(scope.getName()) + .displayName(scope.getDisplayName()) + .description(scope.getDescription()); + } + + /** + * Build API Resource List Item from API Resource. + * + * @param apiResource API Resource. + * @return API Resource List Item. + */ + private APIResourceCollectionItem buildAPIResourceCollectionItem(APIResource apiResource) { + + List scopesList = (apiResource.getScopes() != null) + ? apiResource.getScopes().stream().map(this::buildScopeGetResponse).collect(Collectors.toList()) + : Collections.emptyList(); + + return new APIResourceCollectionItem() + .id(apiResource.getId()) + .name(apiResource.getName()) + .description(apiResource.getDescription()) + .type(apiResource.getType()) + .scopes(scopesList) + .self(V1_API_PATH_COMPONENT + APIResourceMgtEndpointConstants.API_RESOURCE_PATH_COMPONENT + + "/" + apiResource.getId()); + } +} 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/ApiResourceCollectionsApiServiceImpl.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/ApiResourceCollectionsApiServiceImpl.java index bcbc0a3ce3..351825c78e 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/ApiResourceCollectionsApiServiceImpl.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/ApiResourceCollectionsApiServiceImpl.java @@ -18,7 +18,9 @@ package org.wso2.carbon.identity.api.server.api.resource.v1.impl; +import org.springframework.beans.factory.annotation.Autowired; import org.wso2.carbon.identity.api.server.api.resource.v1.ApiResourceCollectionsApiService; +import org.wso2.carbon.identity.api.server.api.resource.v1.core.ServerAPIResourceCollectionManagementService; import javax.ws.rs.core.Response; @@ -27,17 +29,19 @@ */ public class ApiResourceCollectionsApiServiceImpl implements ApiResourceCollectionsApiService { + @Autowired + ServerAPIResourceCollectionManagementService serverAPIResourceManagementService; + @Override public Response getAPIResourceCollectionByCollectionId(String collectionId) { - // do some magic! - return Response.ok().entity("magic!").build(); + return Response.ok().entity( + serverAPIResourceManagementService.getAPIResourceCollectionByCollectionId(collectionId)).build(); } @Override public Response getAPIResourceCollections(String filter) { - // do some magic! - return Response.ok().entity("magic!").build(); + return Response.ok().entity(serverAPIResourceManagementService.getAPIResourceCollections(filter)).build(); } } 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/util/APIResourceMgtEndpointUtil.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/util/APIResourceMgtEndpointUtil.java index e039b5b17c..2075f05c4a 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/util/APIResourceMgtEndpointUtil.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/util/APIResourceMgtEndpointUtil.java @@ -21,6 +21,8 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.identity.api.resource.collection.mgt.exception.APIResourceCollectionMgtClientException; +import org.wso2.carbon.identity.api.resource.collection.mgt.exception.APIResourceCollectionMgtException; import org.wso2.carbon.identity.api.resource.mgt.APIResourceMgtClientException; import org.wso2.carbon.identity.api.resource.mgt.APIResourceMgtException; import org.wso2.carbon.identity.api.server.api.resource.common.APIResourceManagementServiceHolder; @@ -166,6 +168,21 @@ public static APIError handleAPIResourceMgtException(APIResourceMgtException e) return handleException(status, errorCode, e.getMessage(), e.getDescription()); } + public static APIError handleAPIResourceCollectionMgtException(APIResourceCollectionMgtException e) { + + Response.Status status = Response.Status.INTERNAL_SERVER_ERROR; + if (e instanceof APIResourceCollectionMgtClientException) { + LOG.debug(e.getMessage(), e); + status = Response.Status.BAD_REQUEST; + } else { + LOG.error(e.getMessage(), e); + } + String errorCode = e.getErrorCode(); //TODO: Update this + errorCode = errorCode.contains(ERROR_CODE_DELIMITER) ? errorCode : + APIResourceMgtEndpointConstants.API_RESOURCE_MANAGEMENT_PREFIX + errorCode; + return handleException(status, errorCode, e.getMessage(), e.getDescription()); + } + /** * Returns a generic error object. * 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 196932179f..d488458401 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 @@ -753,11 +753,42 @@ components: totalResults: type: integer example: 1 - APIResourceCollections: + apiResourceCollections: type: array items: $ref: '#/components/schemas/APIResourceCollectionListItem' + APIResourceCollectionItem: + type: object + required: + - id + - name + - displayName + - self + properties: + id: + type: string + example: gh43-jk34-vb34-df67 + name: + type: string + example: Greetings API + description: + type: string + example: Greeting API representation + identifier: + type: string + example: greetings_api + type: + type: string + example: SYSTEM + scopes: + type: array + items: + $ref: '#/components/schemas/ScopeGetModel' + self: + type: string + example: /t/carbon.super/api/server/v1/api-resources/eDUwOUNlcnRpZmljYXRlQXV0aGVudGljYXRvcg + APIResourceCollectionResponse: type: object required: @@ -778,10 +809,10 @@ components: type: type: string example: SYSTEM - scopes: + apiResources: type: array items: - $ref: '#/components/schemas/ScopeGetModel' + $ref: '#/components/schemas/APIResourceCollectionItem' ScopeGetModel: type: object diff --git a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/resources/META-INF/cxf/api-resource-server-v1-cxf.xml b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/resources/META-INF/cxf/api-resource-server-v1-cxf.xml index d0e3e969ba..d764bb9534 100644 --- a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/resources/META-INF/cxf/api-resource-server-v1-cxf.xml +++ b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/resources/META-INF/cxf/api-resource-server-v1-cxf.xml @@ -21,13 +21,16 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> + + + + + From 0ab59cda72de09dd5d902fdb74735df1b3fe1bc0 Mon Sep 17 00:00:00 2001 From: Pasindu Yeshan Date: Mon, 6 Nov 2023 15:13:28 +0530 Subject: [PATCH 04/15] Changed error code --- .../v1/constants/APIResourceMgtEndpointConstants.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 fb12151099..73c023d3a7 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 @@ -93,6 +93,9 @@ public enum ErrorMessage { "Cannot modify or delete the read-only System APIs."), ERROR_CODE_INVALID_REQ_ATTRIBUTES("60013", "Invalid attribute name.", "Invalid attribute name provided as required attribute."), + ERROR_CODE_API_RESOURCE_COLLECTION_NOT_FOUND("60014", + "Unable to find the API resource collection.", + "Unable to find the API resource collection with the id: %s in the tenant domain."), // Server errors. ERROR_CODE_ADD_API_RESOURCE("65001", "Error while adding api resource.", "Server encountered an error while " + @@ -100,10 +103,7 @@ public enum ErrorMessage { ERROR_CODE_VALIDATE_SCOPES("65002", "Error while validating scopes.", "Server encountered an error while " + "validating the scopes."), - ERROR_CODE_API_RESOURCE_COLLECTION_NOT_FOUND("600014", - "Unable to find the API resource collection.", - "Unable to find the API resource collection with the id: %s in the tenant domain."), - ; // TODO: Change code. + ; private final String code; private final String message; private final String description; From 97674700cb905dce18f73d3b564551ba75c921eb Mon Sep 17 00:00:00 2001 From: Pasindu Yeshan Date: Thu, 9 Nov 2023 17:14:17 +0530 Subject: [PATCH 05/15] Add API resource map feature --- .../v1/APIResourceCollectionResponse.java | 21 +-- ...esourceCollectionResponseApiResources.java | 140 ++++++++++++++++++ ...PIResourceCollectionManagementService.java | 36 ++++- .../src/main/resources/APIResources.yaml | 14 +- 4 files changed, 185 insertions(+), 26 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/APIResourceCollectionResponseApiResources.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/APIResourceCollectionResponse.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/APIResourceCollectionResponse.java index 6748350830..a21f1fa309 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/APIResourceCollectionResponse.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/APIResourceCollectionResponse.java @@ -22,9 +22,7 @@ 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.APIResourceCollectionItem; +import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceCollectionResponseApiResources; import javax.validation.constraints.*; @@ -39,8 +37,7 @@ public class APIResourceCollectionResponse { private String name; private String displayName; private String type; - private List apiResources = null; - + private APIResourceCollectionResponseApiResources apiResources; /** **/ @@ -122,7 +119,7 @@ public void setType(String type) { /** **/ - public APIResourceCollectionResponse apiResources(List apiResources) { + public APIResourceCollectionResponse apiResources(APIResourceCollectionResponseApiResources apiResources) { this.apiResources = apiResources; return this; @@ -131,22 +128,14 @@ public APIResourceCollectionResponse apiResources(List getApiResources() { + public APIResourceCollectionResponseApiResources getApiResources() { return apiResources; } - public void setApiResources(List apiResources) { + public void setApiResources(APIResourceCollectionResponseApiResources apiResources) { this.apiResources = apiResources; } - public APIResourceCollectionResponse addApiResourcesItem(APIResourceCollectionItem apiResourcesItem) { - if (this.apiResources == null) { - this.apiResources = new ArrayList(); - } - this.apiResources.add(apiResourcesItem); - return this; - } - @Override public boolean equals(java.lang.Object o) { 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/APIResourceCollectionResponseApiResources.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/APIResourceCollectionResponseApiResources.java new file mode 100644 index 0000000000..f6c6ba5215 --- /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/APIResourceCollectionResponseApiResources.java @@ -0,0 +1,140 @@ +/* + * 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 java.util.ArrayList; +import java.util.List; +import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceCollectionItem; +import javax.validation.constraints.*; + + +import io.swagger.annotations.*; +import java.util.Objects; +import javax.validation.Valid; +import javax.xml.bind.annotation.*; + +public class APIResourceCollectionResponseApiResources { + + private List read = null; + + private List write = null; + + + /** + **/ + public APIResourceCollectionResponseApiResources read(List read) { + + this.read = read; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("read") + @Valid + public List getRead() { + return read; + } + public void setRead(List read) { + this.read = read; + } + + public APIResourceCollectionResponseApiResources addReadItem(APIResourceCollectionItem readItem) { + if (this.read == null) { + this.read = new ArrayList(); + } + this.read.add(readItem); + return this; + } + + /** + **/ + public APIResourceCollectionResponseApiResources write(List write) { + + this.write = write; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("write") + @Valid + public List getWrite() { + return write; + } + public void setWrite(List write) { + this.write = write; + } + + public APIResourceCollectionResponseApiResources addWriteItem(APIResourceCollectionItem writeItem) { + if (this.write == null) { + this.write = new ArrayList(); + } + this.write.add(writeItem); + return this; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + APIResourceCollectionResponseApiResources apIResourceCollectionResponseApiResources = (APIResourceCollectionResponseApiResources) o; + return Objects.equals(this.read, apIResourceCollectionResponseApiResources.read) && + Objects.equals(this.write, apIResourceCollectionResponseApiResources.write); + } + + @Override + public int hashCode() { + return Objects.hash(read, write); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class APIResourceCollectionResponseApiResources {\n"); + + sb.append(" read: ").append(toIndentedString(read)).append("\n"); + sb.append(" write: ").append(toIndentedString(write)).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/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/core/ServerAPIResourceCollectionManagementService.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/ServerAPIResourceCollectionManagementService.java index 093c63409d..6630ddcb35 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/ServerAPIResourceCollectionManagementService.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/ServerAPIResourceCollectionManagementService.java @@ -19,6 +19,7 @@ package org.wso2.carbon.identity.api.server.api.resource.v1.core; import org.wso2.carbon.context.CarbonContext; +import org.wso2.carbon.identity.api.resource.collection.mgt.constant.APIResourceCollectionManagementConstants; import org.wso2.carbon.identity.api.resource.collection.mgt.exception.APIResourceCollectionMgtException; import org.wso2.carbon.identity.api.resource.collection.mgt.model.APIResourceCollection; import org.wso2.carbon.identity.api.resource.collection.mgt.model.APIResourceCollectionSearchResult; @@ -27,6 +28,7 @@ import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceCollectionListItem; import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceCollectionListResponse; import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceCollectionResponse; +import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceCollectionResponseApiResources; import org.wso2.carbon.identity.api.server.api.resource.v1.ScopeGetModel; import org.wso2.carbon.identity.api.server.api.resource.v1.constants.APIResourceMgtEndpointConstants; import org.wso2.carbon.identity.api.server.api.resource.v1.util.APIResourceMgtEndpointUtil; @@ -102,12 +104,16 @@ public APIResourceCollectionResponse getAPIResourceCollectionByCollectionId(Stri apiResourceCollectionResponse.setDisplayName(apiResourceCollection.getDisplayName()); apiResourceCollectionResponse.setType(apiResourceCollection.getType()); - List apiResourceCollectionItems = - (apiResourceCollection.getApiResources() != null) - ? apiResourceCollection.getApiResources().stream() - .map(this::buildAPIResourceCollectionItem).collect(Collectors.toList()) - : Collections.emptyList(); - apiResourceCollectionResponse.setApiResources(apiResourceCollectionItems); + List readAPIResourceCollectionItems = getAPIResourceCollectionItems( + apiResourceCollection, APIResourceCollectionManagementConstants.READ); + List writeAPIResourceCollectionItems = getAPIResourceCollectionItems( + apiResourceCollection, APIResourceCollectionManagementConstants.WRITE); + + APIResourceCollectionResponseApiResources apiResourceCollectionResponseApiResources = + new APIResourceCollectionResponseApiResources(); + apiResourceCollectionResponseApiResources.setRead(readAPIResourceCollectionItems); + apiResourceCollectionResponseApiResources.setWrite(writeAPIResourceCollectionItems); + apiResourceCollectionResponse.setApiResources(apiResourceCollectionResponseApiResources); } catch (APIResourceCollectionMgtException e) { throw APIResourceMgtEndpointUtil.handleAPIResourceCollectionMgtException(e); } @@ -147,6 +153,24 @@ private ScopeGetModel buildScopeGetResponse(Scope scope) { .description(scope.getDescription()); } + /** + * Get API Resource Collection Items. + * + * @param apiResourceCollection API Resource Collection. + * @param resourceType Resource type. + * @return API Resource Collection Items. + */ + private List getAPIResourceCollectionItems(APIResourceCollection apiResourceCollection, + String resourceType) { + + if (apiResourceCollection.getApiResources() == null || apiResourceCollection.getApiResources() + .get(resourceType) == null) { + return Collections.emptyList(); + } + return apiResourceCollection.getApiResources().get(resourceType).stream() + .map(this::buildAPIResourceCollectionItem).collect(Collectors.toList()); + } + /** * Build API Resource List Item from API Resource. * 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 d488458401..f74cad86b6 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 @@ -795,7 +795,6 @@ components: - id - name - displayName - - self properties: id: type: string @@ -810,9 +809,16 @@ components: type: string example: SYSTEM apiResources: - type: array - items: - $ref: '#/components/schemas/APIResourceCollectionItem' + type: object + properties: + read: + type: array + items: + $ref: '#/components/schemas/APIResourceCollectionItem' + write: + type: array + items: + $ref: '#/components/schemas/APIResourceCollectionItem' ScopeGetModel: type: object From a39e68d4017902a76c5d6eacdd9f3fea9d0b59e6 Mon Sep 17 00:00:00 2001 From: Pasindu Yeshan Date: Tue, 14 Nov 2023 13:32:56 +0530 Subject: [PATCH 06/15] Add attributes logic --- .../v1/ApiResourceCollectionsApi.java | 4 +- .../v1/ApiResourceCollectionsApiService.java | 2 +- .../APIResourceMgtEndpointConstants.java | 6 +++ ...PIResourceCollectionManagementService.java | 44 +++++++++++++++++-- .../ApiResourceCollectionsApiServiceImpl.java | 5 ++- .../src/main/resources/APIResources.yaml | 21 ++++++++- 6 files changed, 72 insertions(+), 10 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/ApiResourceCollectionsApi.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/ApiResourceCollectionsApi.java index 6d9c564bb6..764e08e6e4 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/ApiResourceCollectionsApi.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/ApiResourceCollectionsApi.java @@ -83,9 +83,9 @@ public Response getAPIResourceCollectionByCollectionId(@ApiParam(value = "ID of @ApiResponse(code = 403, message = "Forbidden", response = Void.class), @ApiResponse(code = 500, message = "Server Error", response = Error.class) }) - public Response getAPIResourceCollections( @Valid@ApiParam(value = "Condition to filter the retrieval of records. Supports 'sw', 'co', 'ew' and 'eq' operations. ") @QueryParam("filter") String filter) { + public Response getAPIResourceCollections( @Valid@ApiParam(value = "Condition to filter the retrieval of records. Supports 'sw', 'co', 'ew' and 'eq' operations. ") @QueryParam("filter") String filter, @Valid@ApiParam(value = "Specifies the required attributes in the response. Only 'apiResources' attribute is currently supported.") @QueryParam("attributes") String attributes) { - return delegate.getAPIResourceCollections(filter ); + return delegate.getAPIResourceCollections(filter, 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/ApiResourceCollectionsApiService.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/ApiResourceCollectionsApiService.java index 2dd823a503..6e8bd7b5df 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/ApiResourceCollectionsApiService.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/ApiResourceCollectionsApiService.java @@ -34,5 +34,5 @@ public interface ApiResourceCollectionsApiService { public Response getAPIResourceCollectionByCollectionId(String collectionId); - public Response getAPIResourceCollections(String filter); + public Response getAPIResourceCollections(String filter, String 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 73c023d3a7..70b83a89e9 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 @@ -43,10 +43,15 @@ private APIResourceMgtEndpointConstants() { public static final List SUPPORTED_REQUIRED_ATTRIBUTES = Collections .unmodifiableList(supportedRequiredAttributeList); + private static final List supportedRequiredAttributeListCollectionsAPI = new ArrayList<>(); + public static final List SUPPORTED_REQUIRED_ATTRIBUTES_COLLECTIONS_API = Collections + .unmodifiableList(supportedRequiredAttributeListCollectionsAPI); + 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"; public static final String DESC_SORT_ORDER = "DESC"; + public static final String ATTRIBUTES_DELIMITER = ","; static { allowedAttributeList.add("description"); @@ -55,6 +60,7 @@ private APIResourceMgtEndpointConstants() { allowedAttributeList.add("scopes"); supportedRequiredAttributeList.add("properties"); + supportedRequiredAttributeListCollectionsAPI.add("apiResources"); } /** 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/ServerAPIResourceCollectionManagementService.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/ServerAPIResourceCollectionManagementService.java index 6630ddcb35..c89fde51f8 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/ServerAPIResourceCollectionManagementService.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/ServerAPIResourceCollectionManagementService.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.api.resource.v1.core; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.StringUtils; import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.identity.api.resource.collection.mgt.constant.APIResourceCollectionManagementConstants; import org.wso2.carbon.identity.api.resource.collection.mgt.exception.APIResourceCollectionMgtException; @@ -32,10 +34,12 @@ import org.wso2.carbon.identity.api.server.api.resource.v1.ScopeGetModel; import org.wso2.carbon.identity.api.server.api.resource.v1.constants.APIResourceMgtEndpointConstants; import org.wso2.carbon.identity.api.server.api.resource.v1.util.APIResourceMgtEndpointUtil; +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.Scope; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -53,15 +57,31 @@ public class ServerAPIResourceCollectionManagementService { * Get API Resource Collections List. * * @param filter filter string. + * @param requiredAttributes Required attributes. * @return API Resource Collections List. */ - public APIResourceCollectionListResponse getAPIResourceCollections(String filter) { + public APIResourceCollectionListResponse getAPIResourceCollections(String filter, String requiredAttributes) { APIResourceCollectionListResponse apiResourceCollectionListResponse = new APIResourceCollectionListResponse(); - try { - APIResourceCollectionSearchResult apiResourceCollectionSearchResult = APIResourceManagementServiceHolder - .getApiResourceCollectionManager().getAPIResourceCollections(filter); + List requestedAttributeList = new ArrayList<>(); + if (StringUtils.isNotEmpty(requiredAttributes)) { + requestedAttributeList = new ArrayList<>( + Arrays.asList(requiredAttributes.split(APIResourceMgtEndpointConstants.ATTRIBUTES_DELIMITER))); + validateRequiredAttributes(requestedAttributeList); + } + + APIResourceCollectionSearchResult apiResourceCollectionSearchResult; + if (CollectionUtils.isNotEmpty(requestedAttributeList)) { + apiResourceCollectionSearchResult = APIResourceManagementServiceHolder + .getApiResourceCollectionManager() + .getAPIResourceCollectionsWithRequiredAttributes(filter, requestedAttributeList, + CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); + } else { + apiResourceCollectionSearchResult = APIResourceManagementServiceHolder + .getApiResourceCollectionManager() + .getAPIResourceCollections(filter); + } List apiResourceCollections = apiResourceCollectionSearchResult .getAPIResourceCollections(); @@ -192,4 +212,20 @@ private APIResourceCollectionItem buildAPIResourceCollectionItem(APIResource api .self(V1_API_PATH_COMPONENT + APIResourceMgtEndpointConstants.API_RESOURCE_PATH_COMPONENT + "/" + apiResource.getId()); } + + /** + * 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_COLLECTIONS_API.contains(attribute))) { + throw APIResourceMgtEndpointUtil.handleException(Response.Status.BAD_REQUEST, + APIResourceMgtEndpointConstants.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/ApiResourceCollectionsApiServiceImpl.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/ApiResourceCollectionsApiServiceImpl.java index 351825c78e..8a920f0635 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/ApiResourceCollectionsApiServiceImpl.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/ApiResourceCollectionsApiServiceImpl.java @@ -40,8 +40,9 @@ public Response getAPIResourceCollectionByCollectionId(String collectionId) { } @Override - public Response getAPIResourceCollections(String filter) { + public Response getAPIResourceCollections(String filter, String attributes) { - return Response.ok().entity(serverAPIResourceManagementService.getAPIResourceCollections(filter)).build(); + return Response.ok().entity(serverAPIResourceManagementService.getAPIResourceCollections(filter, 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 f74cad86b6..d090650b1f 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 @@ -410,7 +410,8 @@ paths: * internal_api_resource_view operationId: getAPIResourceCollections parameters: - - $ref: '#/components/parameters/filter' + - $ref: '#/components/parameters/collectionFilter' + - $ref: '#/components/parameters/collectionAttributes' responses: 200: description: OK @@ -544,6 +545,16 @@ components: type: string example: identifier+eq+greetings + collectionFilter: + name: filter + in: query + required: false + description: | + Condition to filter the retrieval of records. Supports 'sw', 'co', 'ew' and 'eq' operations. + schema: + type: string + example: type+eq+tenant + limit: name: limit in: query @@ -562,6 +573,14 @@ components: schema: type: string + collectionAttributes: + name: attributes + in: query + required: false + description: Specifies the required attributes in the response. Only 'apiResources' attribute is currently supported. + schema: + type: string + schemas: Error: type: object From f99254bf914d92f790c7e0bde434c15d58554904 Mon Sep 17 00:00:00 2001 From: Pasindu Yeshan Date: Tue, 14 Nov 2023 15:08:14 +0530 Subject: [PATCH 07/15] Add required attribute support for listing --- .../v1/APIResourceCollectionListItem.java | 23 ++- ...esourceCollectionListItemApiResources.java | 140 ++++++++++++++++++ .../v1/APIResourceCollectionResponse.java | 8 +- .../api/resource/v1/APIResourceMap.java | 140 ++++++++++++++++++ ...PIResourceCollectionManagementService.java | 57 ++++--- .../src/main/resources/APIResources.yaml | 31 ++-- 6 files changed, 361 insertions(+), 38 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/APIResourceCollectionListItemApiResources.java 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/APIResourceMap.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/APIResourceCollectionListItem.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/APIResourceCollectionListItem.java index f038bc910e..0ca53459b6 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/APIResourceCollectionListItem.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/APIResourceCollectionListItem.java @@ -36,6 +36,7 @@ public class APIResourceCollectionListItem { private String name; private String displayName; private String type; + private APIResourceMap apiResources; private String self; /** @@ -116,6 +117,24 @@ public void setType(String type) { this.type = type; } + /** + **/ + public APIResourceCollectionListItem apiResources(APIResourceMap apiResources) { + + this.apiResources = apiResources; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("apiResources") + @Valid + public APIResourceMap getApiResources() { + return apiResources; + } + public void setApiResources(APIResourceMap apiResources) { + this.apiResources = apiResources; + } + /** **/ public APIResourceCollectionListItem self(String self) { @@ -152,12 +171,13 @@ public boolean equals(java.lang.Object o) { Objects.equals(this.name, apIResourceCollectionListItem.name) && Objects.equals(this.displayName, apIResourceCollectionListItem.displayName) && Objects.equals(this.type, apIResourceCollectionListItem.type) && + Objects.equals(this.apiResources, apIResourceCollectionListItem.apiResources) && Objects.equals(this.self, apIResourceCollectionListItem.self); } @Override public int hashCode() { - return Objects.hash(id, name, displayName, type, self); + return Objects.hash(id, name, displayName, type, apiResources, self); } @Override @@ -170,6 +190,7 @@ public String toString() { sb.append(" name: ").append(toIndentedString(name)).append("\n"); sb.append(" displayName: ").append(toIndentedString(displayName)).append("\n"); sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" apiResources: ").append(toIndentedString(apiResources)).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/APIResourceCollectionListItemApiResources.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/APIResourceCollectionListItemApiResources.java new file mode 100644 index 0000000000..2fa7e00cda --- /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/APIResourceCollectionListItemApiResources.java @@ -0,0 +1,140 @@ +/* + * 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 java.util.ArrayList; +import java.util.List; +import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceCollectionItem; +import javax.validation.constraints.*; + + +import io.swagger.annotations.*; +import java.util.Objects; +import javax.validation.Valid; +import javax.xml.bind.annotation.*; + +public class APIResourceCollectionListItemApiResources { + + private List read = null; + + private List write = null; + + + /** + **/ + public APIResourceCollectionListItemApiResources read(List read) { + + this.read = read; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("read") + @Valid + public List getRead() { + return read; + } + public void setRead(List read) { + this.read = read; + } + + public APIResourceCollectionListItemApiResources addReadItem(APIResourceCollectionItem readItem) { + if (this.read == null) { + this.read = new ArrayList(); + } + this.read.add(readItem); + return this; + } + + /** + **/ + public APIResourceCollectionListItemApiResources write(List write) { + + this.write = write; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("write") + @Valid + public List getWrite() { + return write; + } + public void setWrite(List write) { + this.write = write; + } + + public APIResourceCollectionListItemApiResources addWriteItem(APIResourceCollectionItem writeItem) { + if (this.write == null) { + this.write = new ArrayList(); + } + this.write.add(writeItem); + return this; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + APIResourceCollectionListItemApiResources apIResourceCollectionListItemApiResources = (APIResourceCollectionListItemApiResources) o; + return Objects.equals(this.read, apIResourceCollectionListItemApiResources.read) && + Objects.equals(this.write, apIResourceCollectionListItemApiResources.write); + } + + @Override + public int hashCode() { + return Objects.hash(read, write); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class APIResourceCollectionListItemApiResources {\n"); + + sb.append(" read: ").append(toIndentedString(read)).append("\n"); + sb.append(" write: ").append(toIndentedString(write)).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/APIResourceCollectionResponse.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/APIResourceCollectionResponse.java index a21f1fa309..b24206decb 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/APIResourceCollectionResponse.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/APIResourceCollectionResponse.java @@ -37,7 +37,7 @@ public class APIResourceCollectionResponse { private String name; private String displayName; private String type; - private APIResourceCollectionResponseApiResources apiResources; + private APIResourceMap apiResources; /** **/ @@ -119,7 +119,7 @@ public void setType(String type) { /** **/ - public APIResourceCollectionResponse apiResources(APIResourceCollectionResponseApiResources apiResources) { + public APIResourceCollectionResponse apiResources(APIResourceMap apiResources) { this.apiResources = apiResources; return this; @@ -128,10 +128,10 @@ public APIResourceCollectionResponse apiResources(APIResourceCollectionResponseA @ApiModelProperty(value = "") @JsonProperty("apiResources") @Valid - public APIResourceCollectionResponseApiResources getApiResources() { + public APIResourceMap getApiResources() { return apiResources; } - public void setApiResources(APIResourceCollectionResponseApiResources apiResources) { + public void setApiResources(APIResourceMap apiResources) { this.apiResources = apiResources; } 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/APIResourceMap.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/APIResourceMap.java new file mode 100644 index 0000000000..3562b7d33a --- /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/APIResourceMap.java @@ -0,0 +1,140 @@ +/* + * 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 java.util.ArrayList; +import java.util.List; +import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceCollectionItem; +import javax.validation.constraints.*; + + +import io.swagger.annotations.*; +import java.util.Objects; +import javax.validation.Valid; +import javax.xml.bind.annotation.*; + +public class APIResourceMap { + + private List read = null; + + private List write = null; + + + /** + **/ + public APIResourceMap read(List read) { + + this.read = read; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("read") + @Valid + public List getRead() { + return read; + } + public void setRead(List read) { + this.read = read; + } + + public APIResourceMap addReadItem(APIResourceCollectionItem readItem) { + if (this.read == null) { + this.read = new ArrayList(); + } + this.read.add(readItem); + return this; + } + + /** + **/ + public APIResourceMap write(List write) { + + this.write = write; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("write") + @Valid + public List getWrite() { + return write; + } + public void setWrite(List write) { + this.write = write; + } + + public APIResourceMap addWriteItem(APIResourceCollectionItem writeItem) { + if (this.write == null) { + this.write = new ArrayList(); + } + this.write.add(writeItem); + return this; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + APIResourceMap apIResourceMap = (APIResourceMap) o; + return Objects.equals(this.read, apIResourceMap.read) && + Objects.equals(this.write, apIResourceMap.write); + } + + @Override + public int hashCode() { + return Objects.hash(read, write); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class APIResourceMap {\n"); + + sb.append(" read: ").append(toIndentedString(read)).append("\n"); + sb.append(" write: ").append(toIndentedString(write)).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/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/core/ServerAPIResourceCollectionManagementService.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/ServerAPIResourceCollectionManagementService.java index c89fde51f8..cdd9552914 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/ServerAPIResourceCollectionManagementService.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/ServerAPIResourceCollectionManagementService.java @@ -30,7 +30,7 @@ import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceCollectionListItem; import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceCollectionListResponse; import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceCollectionResponse; -import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceCollectionResponseApiResources; +import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceMap; import org.wso2.carbon.identity.api.server.api.resource.v1.ScopeGetModel; import org.wso2.carbon.identity.api.server.api.resource.v1.constants.APIResourceMgtEndpointConstants; import org.wso2.carbon.identity.api.server.api.resource.v1.util.APIResourceMgtEndpointUtil; @@ -71,15 +71,14 @@ public APIResourceCollectionListResponse getAPIResourceCollections(String filter validateRequiredAttributes(requestedAttributeList); } + boolean hasRequiredAttributes = CollectionUtils.isNotEmpty(requestedAttributeList); APIResourceCollectionSearchResult apiResourceCollectionSearchResult; - if (CollectionUtils.isNotEmpty(requestedAttributeList)) { - apiResourceCollectionSearchResult = APIResourceManagementServiceHolder - .getApiResourceCollectionManager() + if (hasRequiredAttributes) { + apiResourceCollectionSearchResult = APIResourceManagementServiceHolder.getApiResourceCollectionManager() .getAPIResourceCollectionsWithRequiredAttributes(filter, requestedAttributeList, CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); } else { - apiResourceCollectionSearchResult = APIResourceManagementServiceHolder - .getApiResourceCollectionManager() + apiResourceCollectionSearchResult = APIResourceManagementServiceHolder.getApiResourceCollectionManager() .getAPIResourceCollections(filter); } @@ -92,7 +91,9 @@ public APIResourceCollectionListResponse getAPIResourceCollections(String filter } apiResourceCollectionListResponse.setTotalResults(apiResourceCollectionSearchResult.getTotalCount()); apiResourceCollectionListResponse.setApiResourceCollections( - apiResourceCollections.stream().map(this::buildAPIResourceCollectionListItem) + apiResourceCollections.stream() + .map(apiResourceCollection -> buildAPIResourceCollectionListItem(apiResourceCollection, + hasRequiredAttributes)) .collect(Collectors.toList())); } catch (APIResourceCollectionMgtException e) { throw APIResourceMgtEndpointUtil.handleAPIResourceCollectionMgtException(e); @@ -123,17 +124,7 @@ public APIResourceCollectionResponse getAPIResourceCollectionByCollectionId(Stri apiResourceCollectionResponse.setName(apiResourceCollection.getName()); apiResourceCollectionResponse.setDisplayName(apiResourceCollection.getDisplayName()); apiResourceCollectionResponse.setType(apiResourceCollection.getType()); - - List readAPIResourceCollectionItems = getAPIResourceCollectionItems( - apiResourceCollection, APIResourceCollectionManagementConstants.READ); - List writeAPIResourceCollectionItems = getAPIResourceCollectionItems( - apiResourceCollection, APIResourceCollectionManagementConstants.WRITE); - - APIResourceCollectionResponseApiResources apiResourceCollectionResponseApiResources = - new APIResourceCollectionResponseApiResources(); - apiResourceCollectionResponseApiResources.setRead(readAPIResourceCollectionItems); - apiResourceCollectionResponseApiResources.setWrite(writeAPIResourceCollectionItems); - apiResourceCollectionResponse.setApiResources(apiResourceCollectionResponseApiResources); + apiResourceCollectionResponse.setApiResources(buildAPIResourceMap(apiResourceCollection)); } catch (APIResourceCollectionMgtException e) { throw APIResourceMgtEndpointUtil.handleAPIResourceCollectionMgtException(e); } @@ -147,15 +138,20 @@ public APIResourceCollectionResponse getAPIResourceCollectionByCollectionId(Stri * @return API Resource Collection List Item. */ private APIResourceCollectionListItem buildAPIResourceCollectionListItem( - APIResourceCollection apiResourceCollection) { + APIResourceCollection apiResourceCollection, boolean includeAPIResources) { - return new APIResourceCollectionListItem() + APIResourceCollectionListItem item = new APIResourceCollectionListItem() .id(apiResourceCollection.getId()) .name(apiResourceCollection.getName()) .displayName(apiResourceCollection.getDisplayName()) .type(apiResourceCollection.getType()) .self(V1_API_PATH_COMPONENT + APIResourceMgtEndpointConstants.API_RESOURCE_COLLECTION_PATH_COMPONENT + "/" + apiResourceCollection.getId()); + + if (includeAPIResources) { + item.setApiResources(buildAPIResourceMap(apiResourceCollection)); + } + return item; } /** @@ -228,4 +224,25 @@ private void validateRequiredAttributes(List requiredAttributeList) thro } } } + + /** + * Build API Resource read write map. + * + * @param apiResourceCollection API Resource Collection. + * @return API Resource read write map. + */ + private APIResourceMap buildAPIResourceMap( + APIResourceCollection apiResourceCollection) { + + List readAPIResourceCollectionItems = getAPIResourceCollectionItems( + apiResourceCollection, APIResourceCollectionManagementConstants.READ); + List writeAPIResourceCollectionItems = getAPIResourceCollectionItems( + apiResourceCollection, APIResourceCollectionManagementConstants.WRITE); + + APIResourceMap apiResourceCollectionResponseApiResources = + new APIResourceMap(); + apiResourceCollectionResponseApiResources.setRead(readAPIResourceCollectionItems); + apiResourceCollectionResponseApiResources.setWrite(writeAPIResourceCollectionItems); + return apiResourceCollectionResponseApiResources; + } } 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 d090650b1f..eac3f34130 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 @@ -481,7 +481,7 @@ components: schema: type: string example: er34-gf23-bv54-vb90 - + collectionId: name: collectionId in: path @@ -740,6 +740,18 @@ components: items: $ref: '#/components/schemas/APIResourceListItem' + APIResourceMap: + type: object + properties: + read: + type: array + items: + $ref: '#/components/schemas/APIResourceCollectionItem' + write: + type: array + items: + $ref: '#/components/schemas/APIResourceCollectionItem' + APIResourceCollectionListItem: type: object required: @@ -760,10 +772,12 @@ components: type: type: string example: SYSTEM + apiResources: + $ref: '#/components/schemas/APIResourceMap' self: type: string example: /t/carbon.super/api/server/v1/api-resource-collections/eDUwOUNlcnRpZmljYXRlQXV0aGVudGljYXRvcg - + APIResourceCollectionListResponse: type: object required: @@ -776,7 +790,7 @@ components: type: array items: $ref: '#/components/schemas/APIResourceCollectionListItem' - + APIResourceCollectionItem: type: object required: @@ -828,16 +842,7 @@ components: type: string example: SYSTEM apiResources: - type: object - properties: - read: - type: array - items: - $ref: '#/components/schemas/APIResourceCollectionItem' - write: - type: array - items: - $ref: '#/components/schemas/APIResourceCollectionItem' + $ref: '#/components/schemas/APIResourceMap' ScopeGetModel: type: object From 0f516fbf3287b99dd32d666b18533e9083d75aca Mon Sep 17 00:00:00 2001 From: Pasindu Yeshan Date: Wed, 15 Nov 2023 10:30:05 +0530 Subject: [PATCH 08/15] Refactor code --- ...PIResourceCollectionManagementService.java | 35 +++++++------------ 1 file changed, 13 insertions(+), 22 deletions(-) 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/ServerAPIResourceCollectionManagementService.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/ServerAPIResourceCollectionManagementService.java index cdd9552914..460df7f8ee 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/ServerAPIResourceCollectionManagementService.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/ServerAPIResourceCollectionManagementService.java @@ -64,37 +64,28 @@ public APIResourceCollectionListResponse getAPIResourceCollections(String filter APIResourceCollectionListResponse apiResourceCollectionListResponse = new APIResourceCollectionListResponse(); try { - List requestedAttributeList = new ArrayList<>(); - if (StringUtils.isNotEmpty(requiredAttributes)) { - requestedAttributeList = new ArrayList<>( - Arrays.asList(requiredAttributes.split(APIResourceMgtEndpointConstants.ATTRIBUTES_DELIMITER))); + List requestedAttributeList = StringUtils.isNotEmpty(requiredAttributes) ? + Arrays.asList(requiredAttributes.split(APIResourceMgtEndpointConstants.ATTRIBUTES_DELIMITER)) : + Collections.emptyList(); + if (!requestedAttributeList.isEmpty()) { validateRequiredAttributes(requestedAttributeList); } - boolean hasRequiredAttributes = CollectionUtils.isNotEmpty(requestedAttributeList); - APIResourceCollectionSearchResult apiResourceCollectionSearchResult; - if (hasRequiredAttributes) { - apiResourceCollectionSearchResult = APIResourceManagementServiceHolder.getApiResourceCollectionManager() - .getAPIResourceCollectionsWithRequiredAttributes(filter, requestedAttributeList, - CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); - } else { - apiResourceCollectionSearchResult = APIResourceManagementServiceHolder.getApiResourceCollectionManager() - .getAPIResourceCollections(filter); - } - - List apiResourceCollections = apiResourceCollectionSearchResult - .getAPIResourceCollections(); + APIResourceCollectionSearchResult apiResourceCollectionSearchResult = + APIResourceManagementServiceHolder.getApiResourceCollectionManager() + .getAPIResourceCollections(filter, requestedAttributeList, + CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); + List apiResourceCollections = + apiResourceCollectionSearchResult.getAPIResourceCollections(); if (apiResourceCollections == null || apiResourceCollections.isEmpty()) { apiResourceCollectionListResponse.setTotalResults(0); apiResourceCollectionListResponse.setApiResourceCollections(new ArrayList<>()); return apiResourceCollectionListResponse; } apiResourceCollectionListResponse.setTotalResults(apiResourceCollectionSearchResult.getTotalCount()); - apiResourceCollectionListResponse.setApiResourceCollections( - apiResourceCollections.stream() - .map(apiResourceCollection -> buildAPIResourceCollectionListItem(apiResourceCollection, - hasRequiredAttributes)) - .collect(Collectors.toList())); + apiResourceCollectionListResponse.setApiResourceCollections(apiResourceCollections.stream() + .map(apiResourceCollection -> buildAPIResourceCollectionListItem(apiResourceCollection, + CollectionUtils.isNotEmpty(requestedAttributeList))).collect(Collectors.toList())); } catch (APIResourceCollectionMgtException e) { throw APIResourceMgtEndpointUtil.handleAPIResourceCollectionMgtException(e); } From d2716ec13ce95c456e4f76c7ef7151e14d6f0529 Mon Sep 17 00:00:00 2001 From: Pasindu Yeshan Date: Sat, 18 Nov 2023 18:16:48 +0530 Subject: [PATCH 09/15] Change api path to meta --- ...sourceCollectionsApi.java => MetaApi.java} | 36 +++++++++---------- ...onsApiService.java => MetaApiService.java} | 13 +------ ...actory.java => MetaApiServiceFactory.java} | 10 +++--- ...rviceImpl.java => MetaApiServiceImpl.java} | 6 ++-- .../src/main/resources/APIResources.yaml | 10 +++--- .../cxf/api-resource-server-v1-cxf.xml | 2 +- 6 files changed, 32 insertions(+), 45 deletions(-) rename 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/{ApiResourceCollectionsApi.java => MetaApi.java} (81%) rename 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/{ApiResourceCollectionsApiService.java => MetaApiService.java} (61%) rename 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/factories/{ApiResourceCollectionsApiServiceFactory.java => MetaApiServiceFactory.java} (68%) rename 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/{ApiResourceCollectionsApiServiceImpl.java => MetaApiServiceImpl.java} (86%) 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/ApiResourceCollectionsApi.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/MetaApi.java similarity index 81% rename from 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/ApiResourceCollectionsApi.java rename to 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/MetaApi.java index 764e08e6e4..f1239cc27a 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/ApiResourceCollectionsApi.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/MetaApi.java @@ -18,35 +18,33 @@ package org.wso2.carbon.identity.api.server.api.resource.v1; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import io.swagger.annotations.Authorization; 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.APIResourceCollectionListResponse; -import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceCollectionResponse; -import org.wso2.carbon.identity.api.server.api.resource.v1.Error; -import org.wso2.carbon.identity.api.server.api.resource.v1.ApiResourceCollectionsApiService; import javax.validation.Valid; -import javax.ws.rs.*; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; -import io.swagger.annotations.*; - -import javax.validation.constraints.*; -@Path("/api-resource-collections") -@Api(description = "The api-resource-collections API") +@Path("/meta") +@Api(description = "The meta API") -public class ApiResourceCollectionsApi { +public class MetaApi { @Autowired - private ApiResourceCollectionsApiService delegate; + private MetaApiService delegate; @Valid @GET - @Path("/{collectionId}") + @Path("/api-resource-collections/{collectionId}") @Produces({ "application/json" }) @ApiOperation(value = "Get API resource collection specified by the id", notes = "Get API resource collection specified by the id Permission required:
* /permission/admin/manage/identity/apiresourcemgt/view
Scope required:
* internal_api_resource_view ", response = APIResourceCollectionResponse.class, authorizations = { @@ -68,7 +66,7 @@ public Response getAPIResourceCollectionByCollectionId(@ApiParam(value = "ID of @Valid @GET - + @Path("/api-resource-collections") @Produces({ "application/json" }) @ApiOperation(value = "List all API resource collections in the server", notes = "List all API resource collections in the server Permission required:
* /permission/admin/manage/identity/apiresourcemgt/view
Scope required:
* internal_api_resource_view ", response = APIResourceCollectionListResponse.class, authorizations = { 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/ApiResourceCollectionsApiService.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/MetaApiService.java similarity index 61% rename from 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/ApiResourceCollectionsApiService.java rename to 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/MetaApiService.java index 6e8bd7b5df..30d39658bb 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/ApiResourceCollectionsApiService.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/MetaApiService.java @@ -17,20 +17,9 @@ */ 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.APIResourceCollectionListResponse; -import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceCollectionResponse; -import org.wso2.carbon.identity.api.server.api.resource.v1.Error; import javax.ws.rs.core.Response; - -public interface ApiResourceCollectionsApiService { +public interface MetaApiService { public Response getAPIResourceCollectionByCollectionId(String collectionId); 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/factories/ApiResourceCollectionsApiServiceFactory.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/factories/MetaApiServiceFactory.java similarity index 68% rename from 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/factories/ApiResourceCollectionsApiServiceFactory.java rename to 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/factories/MetaApiServiceFactory.java index 1998e08afe..178a1a72e1 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/factories/ApiResourceCollectionsApiServiceFactory.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/factories/MetaApiServiceFactory.java @@ -18,14 +18,14 @@ package org.wso2.carbon.identity.api.server.api.resource.v1.factories; -import org.wso2.carbon.identity.api.server.api.resource.v1.ApiResourceCollectionsApiService; -import org.wso2.carbon.identity.api.server.api.resource.v1.impl.ApiResourceCollectionsApiServiceImpl; +import org.wso2.carbon.identity.api.server.api.resource.v1.MetaApiService; +import org.wso2.carbon.identity.api.server.api.resource.v1.impl.MetaApiServiceImpl; -public class ApiResourceCollectionsApiServiceFactory { +public class MetaApiServiceFactory { - private final static ApiResourceCollectionsApiService service = new ApiResourceCollectionsApiServiceImpl(); + private final static MetaApiService service = new MetaApiServiceImpl(); - public static ApiResourceCollectionsApiService getApiResourceCollectionsApi() + public static MetaApiService getMetaApi() { return service; } 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/ApiResourceCollectionsApiServiceImpl.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/MetaApiServiceImpl.java similarity index 86% rename from 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/ApiResourceCollectionsApiServiceImpl.java rename to 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/MetaApiServiceImpl.java index 8a920f0635..feb5bcf864 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/ApiResourceCollectionsApiServiceImpl.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/MetaApiServiceImpl.java @@ -19,15 +19,15 @@ package org.wso2.carbon.identity.api.server.api.resource.v1.impl; import org.springframework.beans.factory.annotation.Autowired; -import org.wso2.carbon.identity.api.server.api.resource.v1.ApiResourceCollectionsApiService; +import org.wso2.carbon.identity.api.server.api.resource.v1.MetaApiService; import org.wso2.carbon.identity.api.server.api.resource.v1.core.ServerAPIResourceCollectionManagementService; import javax.ws.rs.core.Response; /** - * Implementation of the API resource collections REST API. + * Implementation of the API resource collections meta REST API. */ -public class ApiResourceCollectionsApiServiceImpl implements ApiResourceCollectionsApiService { +public class MetaApiServiceImpl implements MetaApiService { @Autowired ServerAPIResourceCollectionManagementService serverAPIResourceManagementService; 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 eac3f34130..70ac462c09 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 @@ -397,7 +397,7 @@ paths: schema: $ref: '#/components/schemas/Error' - /api-resource-collections: + /meta/api-resource-collections: get: tags: - API Resource Collections @@ -430,7 +430,7 @@ paths: schema: $ref: '#/components/schemas/Error' - /api-resource-collections/{collectionId}: + /meta/api-resource-collections/{collectionId}: get: tags: - API Resource Collections @@ -481,7 +481,7 @@ components: schema: type: string example: er34-gf23-bv54-vb90 - + collectionId: name: collectionId in: path @@ -777,7 +777,7 @@ components: self: type: string example: /t/carbon.super/api/server/v1/api-resource-collections/eDUwOUNlcnRpZmljYXRlQXV0aGVudGljYXRvcg - + APIResourceCollectionListResponse: type: object required: @@ -790,7 +790,7 @@ components: type: array items: $ref: '#/components/schemas/APIResourceCollectionListItem' - + APIResourceCollectionItem: type: object required: diff --git a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/resources/META-INF/cxf/api-resource-server-v1-cxf.xml b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/resources/META-INF/cxf/api-resource-server-v1-cxf.xml index d764bb9534..d977454b72 100644 --- a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/resources/META-INF/cxf/api-resource-server-v1-cxf.xml +++ b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/resources/META-INF/cxf/api-resource-server-v1-cxf.xml @@ -23,7 +23,7 @@ - + Date: Sat, 18 Nov 2023 21:28:34 +0530 Subject: [PATCH 10/15] Add api resource collection mgt service --- pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pom.xml b/pom.xml index ea9fd8645c..c3543262c9 100644 --- a/pom.xml +++ b/pom.xml @@ -197,6 +197,12 @@ ${carbon.identity.framework.version} provided
+ + org.wso2.carbon.identity.framework + org.wso2.carbon.identity.api.resource.collection.mgt + ${carbon.identity.framework.version} + provided + org.wso2.carbon.identity.framework org.wso2.carbon.identity.application.mgt From 8328cd3a853b6edd44ec533e5340ac5757d6ab53 Mon Sep 17 00:00:00 2001 From: Pasindu Yeshan Date: Sun, 19 Nov 2023 01:42:34 +0530 Subject: [PATCH 11/15] Add comment --- .../api/resource/v1/factories/MetaApiServiceFactory.java | 3 +++ 1 file changed, 3 insertions(+) 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/factories/MetaApiServiceFactory.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/factories/MetaApiServiceFactory.java index 178a1a72e1..c2b23f5274 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/factories/MetaApiServiceFactory.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/factories/MetaApiServiceFactory.java @@ -21,6 +21,9 @@ import org.wso2.carbon.identity.api.server.api.resource.v1.MetaApiService; import org.wso2.carbon.identity.api.server.api.resource.v1.impl.MetaApiServiceImpl; +/** + * Factory class for MetaApiService. + */ public class MetaApiServiceFactory { private final static MetaApiService service = new MetaApiServiceImpl(); From e6d1ede70a95e2ed92ea679c6b0ca1366efaec0f Mon Sep 17 00:00:00 2001 From: Pasindu Yeshan Date: Sun, 19 Nov 2023 01:44:17 +0530 Subject: [PATCH 12/15] Change example --- .../src/main/resources/APIResources.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 70ac462c09..51d72cca8b 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 @@ -721,7 +721,7 @@ components: example: before href: type: string - example: /t/carbon.super/api/server/v1/api-resources?after=NDoy + example: /api/server/v1/api-resources?after=NDoy APIResourceListResponse: type: object From 49fcf4f54d80cb713554dfafe47aac39259613a0 Mon Sep 17 00:00:00 2001 From: Pasindu Yeshan Date: Sun, 19 Nov 2023 14:25:53 +0530 Subject: [PATCH 13/15] Bump framework version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c3543262c9..cf6b3d9d8d 100644 --- a/pom.xml +++ b/pom.xml @@ -766,7 +766,7 @@ 1.4 1.2.4 1.8.62 - 5.25.506 + 5.25.528 3.0.5 5.2.0 **/gen/**/* From 96411389941cd2ddfe425f86a0811a80a46594ce Mon Sep 17 00:00:00 2001 From: Pasindu Yeshan Date: Sun, 19 Nov 2023 14:46:31 +0530 Subject: [PATCH 14/15] Refactor code --- .../v1/core/ServerAPIResourceCollectionManagementService.java | 3 +-- .../api/resource/v1/util/APIResourceMgtEndpointUtil.java | 2 +- 2 files changed, 2 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/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/core/ServerAPIResourceCollectionManagementService.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/ServerAPIResourceCollectionManagementService.java index 460df7f8ee..fdca8d8c41 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/ServerAPIResourceCollectionManagementService.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/ServerAPIResourceCollectionManagementService.java @@ -222,8 +222,7 @@ private void validateRequiredAttributes(List requiredAttributeList) thro * @param apiResourceCollection API Resource Collection. * @return API Resource read write map. */ - private APIResourceMap buildAPIResourceMap( - APIResourceCollection apiResourceCollection) { + private APIResourceMap buildAPIResourceMap(APIResourceCollection apiResourceCollection) { List readAPIResourceCollectionItems = getAPIResourceCollectionItems( apiResourceCollection, APIResourceCollectionManagementConstants.READ); 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/util/APIResourceMgtEndpointUtil.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/util/APIResourceMgtEndpointUtil.java index 2075f05c4a..c5814d3eee 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/util/APIResourceMgtEndpointUtil.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/util/APIResourceMgtEndpointUtil.java @@ -177,7 +177,7 @@ public static APIError handleAPIResourceCollectionMgtException(APIResourceCollec } else { LOG.error(e.getMessage(), e); } - String errorCode = e.getErrorCode(); //TODO: Update this + String errorCode = e.getErrorCode(); errorCode = errorCode.contains(ERROR_CODE_DELIMITER) ? errorCode : APIResourceMgtEndpointConstants.API_RESOURCE_MANAGEMENT_PREFIX + errorCode; return handleException(status, errorCode, e.getMessage(), e.getDescription()); From 18c998530a55a91434f2e56c6b3766be1f1a0de4 Mon Sep 17 00:00:00 2001 From: Pasindu Yeshan Date: Sun, 19 Nov 2023 16:09:46 +0530 Subject: [PATCH 15/15] Refactor code --- .../v1/core/ServerAPIResourceCollectionManagementService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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/ServerAPIResourceCollectionManagementService.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/ServerAPIResourceCollectionManagementService.java index fdca8d8c41..4fd5753615 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/ServerAPIResourceCollectionManagementService.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/ServerAPIResourceCollectionManagementService.java @@ -77,7 +77,7 @@ public APIResourceCollectionListResponse getAPIResourceCollections(String filter CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); List apiResourceCollections = apiResourceCollectionSearchResult.getAPIResourceCollections(); - if (apiResourceCollections == null || apiResourceCollections.isEmpty()) { + if (CollectionUtils.isEmpty(apiResourceCollections)) { apiResourceCollectionListResponse.setTotalResults(0); apiResourceCollectionListResponse.setApiResourceCollections(new ArrayList<>()); return apiResourceCollectionListResponse;