From bdf2a5daa680f160120d9d0692d85f209b59e8d2 Mon Sep 17 00:00:00 2001 From: Thamindu Aluthwala Date: Wed, 23 Aug 2023 11:18:16 +0530 Subject: [PATCH 1/6] Add api resource mgt API --- .../pom.xml | 73 ++ .../APIResourceManagementServiceHolder.java | 71 ++ .../APIResourceMgtOSGiServiceFactory.java | 50 ++ .../factory/OAuthAdminOSGiServiceFactory.java | 53 ++ .../pom.xml | 192 +++++ .../resource/v1/APIResourceCreationModel.java | 198 +++++ .../api/resource/v1/APIResourceListItem.java | 211 +++++ .../resource/v1/APIResourceListResponse.java | 161 ++++ .../resource/v1/APIResourcePatchModel.java | 183 ++++ .../api/resource/v1/APIResourceResponse.java | 296 +++++++ .../api/resource/v1/ApiResourcesApi.java | 224 +++++ .../resource/v1/ApiResourcesApiService.java | 43 + .../api/server/api/resource/v1/Error.java | 161 ++++ .../api/resource/v1/PaginationLink.java | 119 +++ .../api/resource/v1/ScopeCreationModel.java | 142 ++++ .../server/api/resource/v1/ScopeGetModel.java | 167 ++++ .../api/server/api/resource/v1/ScopesApi.java | 69 ++ .../api/resource/v1/ScopesApiService.java | 35 + .../v1/SubscribedApplicationGetModel.java | 119 +++ .../ApiResourcesApiServiceFactory.java | 32 + .../v1/factories/ScopesApiServiceFactory.java | 32 + .../APIResourceMgtEndpointConstants.java | 122 +++ .../ServerAPIResourceManagementService.java | 468 +++++++++++ .../APIResourceMgtEndpointException.java | 38 + .../v1/impl/ApiResourcesApiServiceImpl.java | 103 +++ .../v1/impl/ScopesApiServiceImpl.java | 39 + .../v1/util/APIResourceMgtEndpointUtil.java | 183 ++++ .../src/main/resources/APIResources.yaml | 780 ++++++++++++++++++ .../cxf/api-resource-server-v1-cxf.xml | 38 + .../pom.xml | 38 + pom.xml | 13 + 31 files changed, 4453 insertions(+) create mode 100644 components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.common/pom.xml create mode 100644 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 create mode 100644 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/factory/APIResourceMgtOSGiServiceFactory.java create mode 100644 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/factory/OAuthAdminOSGiServiceFactory.java create mode 100644 components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/pom.xml 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/APIResourceCreationModel.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/APIResourceListItem.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/APIResourceListResponse.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/APIResourcePatchModel.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/APIResourceResponse.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/ApiResourcesApi.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/ApiResourcesApiService.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/Error.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/PaginationLink.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/ScopeCreationModel.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/ScopeGetModel.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/ScopesApi.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/ScopesApiService.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/SubscribedApplicationGetModel.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/ApiResourcesApiServiceFactory.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/ScopesApiServiceFactory.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/constants/APIResourceMgtEndpointConstants.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/ServerAPIResourceManagementService.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/exception/APIResourceMgtEndpointException.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/ApiResourcesApiServiceImpl.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/ScopesApiServiceImpl.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/util/APIResourceMgtEndpointUtil.java create mode 100644 components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/resources/APIResources.yaml create mode 100644 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 create mode 100644 components/org.wso2.carbon.identity.api.server.api.resource/pom.xml 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 new file mode 100644 index 0000000000..a150b8a81b --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.common/pom.xml @@ -0,0 +1,73 @@ + + + + 4.0.0 + + + org.wso2.carbon.identity.server.api + org.wso2.carbon.identity.api.server.api.resource + 1.2.79-SNAPSHOT + ../pom.xml + + + org.wso2.carbon.identity.api.server.api.resource.common + 1.2.79-SNAPSHOT + jar + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + + + org.springframework + spring-web + provided + + + javax.ws.rs + javax.ws.rs-api + provided + + + org.wso2.carbon.identity.framework + org.wso2.carbon.identity.application.mgt + provided + + + org.wso2.carbon.identity.framework + org.wso2.carbon.identity.api.resource.mgt + provided + + + org.wso2.carbon.identity.inbound.auth.oauth2 + org.wso2.carbon.identity.oauth + 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 new file mode 100644 index 0000000000..01042f8d08 --- /dev/null +++ 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 @@ -0,0 +1,71 @@ +/* + * 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.common; + +import org.wso2.carbon.identity.api.resource.mgt.APIResourceManager; +import org.wso2.carbon.identity.oauth.OAuthAdminServiceImpl; + +/** + * Service holder class for api resource management. + */ +public class APIResourceManagementServiceHolder { + + private static APIResourceManager apiResourceManager; + private static OAuthAdminServiceImpl oAuthAdminServiceImpl; + + /** + * Get APIResourceManager osgi service. + * + * @return APIResourceManager. + */ + public static APIResourceManager getApiResourceManager() { + + return apiResourceManager; + } + + /** + * Set APIResourceManager osgi service. + * + * @param apiResourceManager APIResourceManager. + */ + public static void setApiResourceManager(APIResourceManager apiResourceManager) { + + APIResourceManagementServiceHolder.apiResourceManager = apiResourceManager; + } + + /** + * Get OAuthAdminServiceImpl instance. + * + * @return OAuthAdminServiceImpl instance. + */ + public static OAuthAdminServiceImpl getOAuthAdminServiceImpl() { + + return oAuthAdminServiceImpl; + } + + /** + * Set OAuthAdminServiceImpl instance. + * + * @param oAuthAdminServiceImpl OAuthAdminServiceImpl instance. + */ + public static void setOAuthAdminServiceImpl(OAuthAdminServiceImpl oAuthAdminServiceImpl) { + + APIResourceManagementServiceHolder.oAuthAdminServiceImpl = oAuthAdminServiceImpl; + } +} 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/factory/APIResourceMgtOSGiServiceFactory.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/factory/APIResourceMgtOSGiServiceFactory.java new file mode 100644 index 0000000000..953bd1cfd5 --- /dev/null +++ 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/factory/APIResourceMgtOSGiServiceFactory.java @@ -0,0 +1,50 @@ +/* + * 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.common.factory; + +import org.springframework.beans.factory.config.AbstractFactoryBean; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.identity.api.resource.mgt.APIResourceManager; + +/** + * Factory class for APIResourceManagementOSGiService. + */ +public class APIResourceMgtOSGiServiceFactory extends AbstractFactoryBean { + + private APIResourceManager apiResourceManager; + + @Override + public Class getObjectType() { + + return Object.class; + } + + @Override + protected APIResourceManager createInstance() throws Exception { + + if (this.apiResourceManager == null) { + apiResourceManager = (APIResourceManager) PrivilegedCarbonContext. + getThreadLocalCarbonContext().getOSGiService(APIResourceManager.class, null); + if (apiResourceManager == null) { + throw new Exception("Unable to retrieve APIResourceManager service."); + } + } + return this.apiResourceManager; + } +} 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/factory/OAuthAdminOSGiServiceFactory.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/factory/OAuthAdminOSGiServiceFactory.java new file mode 100644 index 0000000000..e160b1eb4b --- /dev/null +++ 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/factory/OAuthAdminOSGiServiceFactory.java @@ -0,0 +1,53 @@ +/* + * 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.common.factory; + +import org.springframework.beans.factory.config.AbstractFactoryBean; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.identity.oauth.OAuthAdminServiceImpl; + +/** + * Factory Beans serves as a factory for creating other beans within the IOC container. This factory bean is used to + * instantiate the OAuthAdminServiceImpl type of object inside the container. + */ +public class OAuthAdminOSGiServiceFactory extends AbstractFactoryBean { + + private OAuthAdminServiceImpl oauthAdminService; + + @Override + public Class getObjectType() { + + return Object.class; + } + + @Override + protected OAuthAdminServiceImpl createInstance() throws Exception { + + if (this.oauthAdminService == null) { + oauthAdminService = (OAuthAdminServiceImpl) PrivilegedCarbonContext + .getThreadLocalCarbonContext().getOSGiService(OAuthAdminServiceImpl.class, null); + + if (oauthAdminService == null) { + throw new Exception("Unable to retrieve OAuthAdminServiceImpl service."); + } + } + return this.oauthAdminService; + } +} + 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 new file mode 100644 index 0000000000..68d3c26206 --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/pom.xml @@ -0,0 +1,192 @@ + + + + 4.0.0 + + + org.wso2.carbon.identity.server.api + org.wso2.carbon.identity.api.server.api.resource + 1.2.79-SNAPSHOT + ../pom.xml + + + WSO2 Identity Server - Applications Rest API + WSO2 Identity Server - API Resource Rest API + org.wso2.carbon.identity.api.server.api.resource.v1 + 1.2.79-SNAPSHOT + jar + + + + org.wso2.carbon.identity.organization.management.core + org.wso2.carbon.identity.organization.management.service + provided + + + org.apache.cxf + cxf-rt-frontend-jaxrs + provided + + + org.apache.cxf + cxf-rt-rs-service-description + provided + + + javax.ws.rs + javax.ws.rs-api + provided + + + io.swagger + swagger-jaxrs + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.core + jackson-annotations + + + com.fasterxml.jackson.core + jackson-core + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + + + javax.ws.rs + jsr311-api + + + com.google.guava + guava + + + + + org.springframework + spring-web + provided + + + com.fasterxml.jackson.jaxrs + jackson-jaxrs-json-provider + provided + + + org.wso2.carbon.identity.framework + org.wso2.carbon.identity.api.resource.mgt + provided + + + org.wso2.carbon.identity.server.api + org.wso2.carbon.identity.api.server.common + + + org.apache.cxf + cxf-rt-rs-extension-search + provided + + + org.wso2.carbon.identity.server.api + org.wso2.carbon.identity.api.server.api.resource.common + + + org.wso2.carbon.identity.framework + org.wso2.carbon.identity.application.common + + + org.wso2.carbon.identity.inbound.auth.oauth2 + org.wso2.carbon.identity.oauth + provided + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven.compiler.plugin.version} + + 1.8 + 1.8 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.8 + + + add-source + generate-sources + + add-source + + + + src/gen/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/APIResourceCreationModel.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/APIResourceCreationModel.java new file mode 100644 index 0000000000..3e60430092 --- /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/APIResourceCreationModel.java @@ -0,0 +1,198 @@ +/* + * 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.ScopeCreationModel; +import javax.validation.constraints.*; + + +import io.swagger.annotations.*; +import java.util.Objects; +import javax.validation.Valid; +import javax.xml.bind.annotation.*; + +public class APIResourceCreationModel { + + private String name; + private String identifier; + private String description; + private Boolean requiresAuthorization; + private List scopes = null; + + + /** + **/ + public APIResourceCreationModel 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 APIResourceCreationModel identifier(String identifier) { + + this.identifier = identifier; + return this; + } + + @ApiModelProperty(example = "greetings_api", required = true, value = "") + @JsonProperty("identifier") + @Valid + @NotNull(message = "Property identifier cannot be null.") + + public String getIdentifier() { + return identifier; + } + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + /** + **/ + public APIResourceCreationModel description(String description) { + + this.description = description; + return this; + } + + @ApiModelProperty(example = "Greetings API representation", value = "") + @JsonProperty("description") + @Valid + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + + /** + **/ + public APIResourceCreationModel requiresAuthorization(Boolean requiresAuthorization) { + + this.requiresAuthorization = requiresAuthorization; + return this; + } + + @ApiModelProperty(example = "true", value = "") + @JsonProperty("requiresAuthorization") + @Valid + public Boolean getRequiresAuthorization() { + return requiresAuthorization; + } + public void setRequiresAuthorization(Boolean requiresAuthorization) { + this.requiresAuthorization = requiresAuthorization; + } + + /** + **/ + public APIResourceCreationModel 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 APIResourceCreationModel addScopesItem(ScopeCreationModel 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; + } + APIResourceCreationModel apIResourceCreationModel = (APIResourceCreationModel) o; + return Objects.equals(this.name, apIResourceCreationModel.name) && + Objects.equals(this.identifier, apIResourceCreationModel.identifier) && + Objects.equals(this.description, apIResourceCreationModel.description) && + Objects.equals(this.requiresAuthorization, apIResourceCreationModel.requiresAuthorization) && + Objects.equals(this.scopes, apIResourceCreationModel.scopes); + } + + @Override + public int hashCode() { + return Objects.hash(name, identifier, description, requiresAuthorization, scopes); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class APIResourceCreationModel {\n"); + + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" identifier: ").append(toIndentedString(identifier)).append("\n"); + sb.append(" description: ").append(toIndentedString(description)).append("\n"); + sb.append(" requiresAuthorization: ").append(toIndentedString(requiresAuthorization)).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/APIResourceListItem.java b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/APIResourceListItem.java new file mode 100644 index 0000000000..ef343a122c --- /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/APIResourceListItem.java @@ -0,0 +1,211 @@ +/* + * 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 APIResourceListItem { + + private String id; + private String name; + private String identifier; + private String type; + private Boolean requiresAuthorization; + private String self; + + /** + **/ + public APIResourceListItem 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 APIResourceListItem 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 APIResourceListItem identifier(String identifier) { + + this.identifier = identifier; + return this; + } + + @ApiModelProperty(example = "greetings_api", required = true, value = "") + @JsonProperty("identifier") + @Valid + @NotNull(message = "Property identifier cannot be null.") + + public String getIdentifier() { + return identifier; + } + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + /** + **/ + public APIResourceListItem 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 APIResourceListItem requiresAuthorization(Boolean requiresAuthorization) { + + this.requiresAuthorization = requiresAuthorization; + return this; + } + + @ApiModelProperty(example = "true", value = "") + @JsonProperty("requiresAuthorization") + @Valid + public Boolean getRequiresAuthorization() { + return requiresAuthorization; + } + public void setRequiresAuthorization(Boolean requiresAuthorization) { + this.requiresAuthorization = requiresAuthorization; + } + + /** + **/ + public APIResourceListItem 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; + } + APIResourceListItem apIResourceListItem = (APIResourceListItem) o; + return Objects.equals(this.id, apIResourceListItem.id) && + Objects.equals(this.name, apIResourceListItem.name) && + Objects.equals(this.identifier, apIResourceListItem.identifier) && + Objects.equals(this.type, apIResourceListItem.type) && + Objects.equals(this.requiresAuthorization, apIResourceListItem.requiresAuthorization) && + Objects.equals(this.self, apIResourceListItem.self); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, identifier, type, requiresAuthorization, self); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class APIResourceListItem {\n"); + + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" identifier: ").append(toIndentedString(identifier)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" requiresAuthorization: ").append(toIndentedString(requiresAuthorization)).append("\n"); + sb.append(" 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/APIResourceListResponse.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/APIResourceListResponse.java new file mode 100644 index 0000000000..3fcf0ec56e --- /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/APIResourceListResponse.java @@ -0,0 +1,161 @@ +/* + * 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.APIResourceListItem; +import org.wso2.carbon.identity.api.server.api.resource.v1.PaginationLink; +import javax.validation.constraints.*; + + +import io.swagger.annotations.*; +import java.util.Objects; +import javax.validation.Valid; +import javax.xml.bind.annotation.*; + +public class APIResourceListResponse { + + private Integer totalResults; + private List links = new ArrayList(); + + private List apiResources = null; + + + /** + **/ + public APIResourceListResponse 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 APIResourceListResponse links(List links) { + + this.links = links; + return this; + } + + @ApiModelProperty(required = true, value = "") + @JsonProperty("links") + @Valid + @NotNull(message = "Property links cannot be null.") + + public List getLinks() { + return links; + } + public void setLinks(List links) { + this.links = links; + } + + public APIResourceListResponse addLinksItem(PaginationLink linksItem) { + this.links.add(linksItem); + return this; + } + + /** + **/ + public APIResourceListResponse apiResources(List apiResources) { + + this.apiResources = apiResources; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("apiResources") + @Valid + public List getApiResources() { + return apiResources; + } + public void setApiResources(List apiResources) { + this.apiResources = apiResources; + } + + public APIResourceListResponse addApiResourcesItem(APIResourceListItem apiResourcesItem) { + if (this.apiResources == null) { + this.apiResources = new ArrayList(); + } + this.apiResources.add(apiResourcesItem); + return this; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + APIResourceListResponse apIResourceListResponse = (APIResourceListResponse) o; + return Objects.equals(this.totalResults, apIResourceListResponse.totalResults) && + Objects.equals(this.links, apIResourceListResponse.links) && + Objects.equals(this.apiResources, apIResourceListResponse.apiResources); + } + + @Override + public int hashCode() { + return Objects.hash(totalResults, links, apiResources); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class APIResourceListResponse {\n"); + + sb.append(" totalResults: ").append(toIndentedString(totalResults)).append("\n"); + sb.append(" links: ").append(toIndentedString(links)).append("\n"); + sb.append(" apiResources: ").append(toIndentedString(apiResources)).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/APIResourcePatchModel.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/APIResourcePatchModel.java new file mode 100644 index 0000000000..ba00307b2e --- /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/APIResourcePatchModel.java @@ -0,0 +1,183 @@ +/* + * 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.ScopeCreationModel; +import javax.validation.constraints.*; + + +import io.swagger.annotations.*; +import java.util.Objects; +import javax.validation.Valid; +import javax.xml.bind.annotation.*; + +public class APIResourcePatchModel { + + private String name; + private String description; + private List addedScopes = null; + + private List removedScopes = null; + + + /** + **/ + public APIResourcePatchModel name(String name) { + + this.name = name; + return this; + } + + @ApiModelProperty(example = "Greetings API", value = "") + @JsonProperty("name") + @Valid + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + /** + **/ + public APIResourcePatchModel description(String description) { + + this.description = description; + return this; + } + + @ApiModelProperty(example = "Greetings API representation", value = "") + @JsonProperty("description") + @Valid + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + + /** + **/ + public APIResourcePatchModel addedScopes(List addedScopes) { + + this.addedScopes = addedScopes; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("addedScopes") + @Valid + public List getAddedScopes() { + return addedScopes; + } + public void setAddedScopes(List addedScopes) { + this.addedScopes = addedScopes; + } + + public APIResourcePatchModel addAddedScopesItem(ScopeCreationModel addedScopesItem) { + if (this.addedScopes == null) { + this.addedScopes = new ArrayList(); + } + this.addedScopes.add(addedScopesItem); + return this; + } + + /** + * This field is not supported yet. + **/ + public APIResourcePatchModel removedScopes(List removedScopes) { + + this.removedScopes = removedScopes; + return this; + } + + @ApiModelProperty(value = "This field is not supported yet.") + @JsonProperty("removedScopes") + @Valid + public List getRemovedScopes() { + return removedScopes; + } + public void setRemovedScopes(List removedScopes) { + this.removedScopes = removedScopes; + } + + public APIResourcePatchModel addRemovedScopesItem(String removedScopesItem) { + if (this.removedScopes == null) { + this.removedScopes = new ArrayList(); + } + this.removedScopes.add(removedScopesItem); + return this; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + APIResourcePatchModel apIResourcePatchModel = (APIResourcePatchModel) o; + return Objects.equals(this.name, apIResourcePatchModel.name) && + Objects.equals(this.description, apIResourcePatchModel.description) && + Objects.equals(this.addedScopes, apIResourcePatchModel.addedScopes) && + Objects.equals(this.removedScopes, apIResourcePatchModel.removedScopes); + } + + @Override + public int hashCode() { + return Objects.hash(name, description, addedScopes, removedScopes); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class APIResourcePatchModel {\n"); + + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" description: ").append(toIndentedString(description)).append("\n"); + sb.append(" addedScopes: ").append(toIndentedString(addedScopes)).append("\n"); + sb.append(" removedScopes: ").append(toIndentedString(removedScopes)).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/APIResourceResponse.java b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/APIResourceResponse.java new file mode 100644 index 0000000000..22b3d7b93e --- /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/APIResourceResponse.java @@ -0,0 +1,296 @@ +/* + * 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 org.wso2.carbon.identity.api.server.api.resource.v1.SubscribedApplicationGetModel; +import javax.validation.constraints.*; + + +import io.swagger.annotations.*; +import java.util.Objects; +import javax.validation.Valid; +import javax.xml.bind.annotation.*; + +public class APIResourceResponse { + + private String id; + private String name; + private String description; + private String identifier; + private String type; + private Boolean requiresAuthorization; + private List scopes = null; + + private List subscribedApplications = null; + + private String self; + + /** + **/ + public APIResourceResponse 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 APIResourceResponse 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 APIResourceResponse 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 APIResourceResponse identifier(String identifier) { + + this.identifier = identifier; + return this; + } + + @ApiModelProperty(example = "greetings_api", required = true, value = "") + @JsonProperty("identifier") + @Valid + @NotNull(message = "Property identifier cannot be null.") + + public String getIdentifier() { + return identifier; + } + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + /** + **/ + public APIResourceResponse 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 APIResourceResponse requiresAuthorization(Boolean requiresAuthorization) { + + this.requiresAuthorization = requiresAuthorization; + return this; + } + + @ApiModelProperty(example = "true", value = "") + @JsonProperty("requiresAuthorization") + @Valid + public Boolean getRequiresAuthorization() { + return requiresAuthorization; + } + public void setRequiresAuthorization(Boolean requiresAuthorization) { + this.requiresAuthorization = requiresAuthorization; + } + + /** + **/ + public APIResourceResponse 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 APIResourceResponse addScopesItem(ScopeGetModel scopesItem) { + if (this.scopes == null) { + this.scopes = new ArrayList(); + } + this.scopes.add(scopesItem); + return this; + } + + /** + **/ + public APIResourceResponse subscribedApplications(List subscribedApplications) { + + this.subscribedApplications = subscribedApplications; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("subscribedApplications") + @Valid + public List getSubscribedApplications() { + return subscribedApplications; + } + public void setSubscribedApplications(List subscribedApplications) { + this.subscribedApplications = subscribedApplications; + } + + public APIResourceResponse addSubscribedApplicationsItem(SubscribedApplicationGetModel subscribedApplicationsItem) { + if (this.subscribedApplications == null) { + this.subscribedApplications = new ArrayList(); + } + this.subscribedApplications.add(subscribedApplicationsItem); + return this; + } + + /** + **/ + public APIResourceResponse 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; + } + APIResourceResponse apIResourceResponse = (APIResourceResponse) o; + return Objects.equals(this.id, apIResourceResponse.id) && + Objects.equals(this.name, apIResourceResponse.name) && + Objects.equals(this.description, apIResourceResponse.description) && + Objects.equals(this.identifier, apIResourceResponse.identifier) && + Objects.equals(this.type, apIResourceResponse.type) && + Objects.equals(this.requiresAuthorization, apIResourceResponse.requiresAuthorization) && + Objects.equals(this.scopes, apIResourceResponse.scopes) && + Objects.equals(this.subscribedApplications, apIResourceResponse.subscribedApplications) && + Objects.equals(this.self, apIResourceResponse.self); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, description, identifier, type, requiresAuthorization, scopes, subscribedApplications, self); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class APIResourceResponse {\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(" requiresAuthorization: ").append(toIndentedString(requiresAuthorization)).append("\n"); + sb.append(" scopes: ").append(toIndentedString(scopes)).append("\n"); + sb.append(" subscribedApplications: ").append(toIndentedString(subscribedApplications)).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/ApiResourcesApi.java b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/ApiResourcesApi.java new file mode 100644 index 0000000000..0bc88af4c9 --- /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/ApiResourcesApi.java @@ -0,0 +1,224 @@ +/* + * 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 java.util.List; + +import javax.validation.Valid; +import javax.ws.rs.*; +import javax.ws.rs.core.Response; +import io.swagger.annotations.*; + +@Path("/api-resources") +@Api(description = "The api-resources API") + +public class ApiResourcesApi { + + @Autowired + private ApiResourcesApiService delegate; + + @Valid + @POST + + @Consumes({ "application/json" }) + @Produces({ "application/json", "application/xml", }) + @ApiOperation(value = "Add a new API resource", notes = "Add a new API resource", response = APIResourceResponse.class, authorizations = { + @Authorization(value = "BasicAuth"), + @Authorization(value = "OAuth2", scopes = { + + }) + }, tags={ "API Resources", }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "OK", response = APIResourceResponse.class), + @ApiResponse(code = 400, message = "Bad Request", response = Error.class), + @ApiResponse(code = 401, message = "Unauthorized", response = Void.class), + @ApiResponse(code = 403, message = "Forbidden", response = Void.class), + @ApiResponse(code = 404, message = "Not Found", response = Error.class), + @ApiResponse(code = 409, message = "Conflict", response = Error.class), + @ApiResponse(code = 500, message = "Server Error", response = Error.class) + }) + public Response addAPIResource(@ApiParam(value = "This represents the API resource to be created." ,required=true) @Valid APIResourceCreationModel apIResourceCreationModel) { + + return delegate.addAPIResource(apIResourceCreationModel ); + } + + @Valid + @DELETE + @Path("/{apiResourceId}") + + @Produces({ "application/json" }) + @ApiOperation(value = "Delete API resource specified by the id", notes = "Delete API resource specified by the id", response = Void.class, authorizations = { + @Authorization(value = "BasicAuth"), + @Authorization(value = "OAuth2", scopes = { + + }) + }, tags={ "API Resources", }) + @ApiResponses(value = { + @ApiResponse(code = 204, message = "No Content", response = Void.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 apiResourcesApiResourceIdDelete(@ApiParam(value = "ID of the API Resource.",required=true) @PathParam("apiResourceId") String apiResourceId) { + + return delegate.apiResourcesApiResourceIdDelete(apiResourceId ); + } + + @Valid + @GET + @Path("/{apiResourceId}") + + @Produces({ "application/json" }) + @ApiOperation(value = "Get API resource specified by the id", notes = "Get API resource specified by the id", response = APIResourceResponse.class, authorizations = { + @Authorization(value = "BasicAuth"), + @Authorization(value = "OAuth2", scopes = { + + }) + }, tags={ "API Resources", }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "OK", response = APIResourceResponse.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 apiResourcesApiResourceIdGet(@ApiParam(value = "ID of the API Resource.",required=true) @PathParam("apiResourceId") String apiResourceId) { + + return delegate.apiResourcesApiResourceIdGet(apiResourceId ); + } + + @Valid + @PATCH + @Path("/{apiResourceId}") + @Consumes({ "application/json" }) + @Produces({ "application/json", "application/xml", }) + @ApiOperation(value = "Patch API resource specified by the id", notes = "Patch API resource specified by the id. Patch operation only supports \"name\", \"description\" updating and \"addedScopes\" fields at the moment.", response = APIResourceResponse.class, authorizations = { + @Authorization(value = "BasicAuth"), + @Authorization(value = "OAuth2", scopes = { + + }) + }, tags={ "API Resources", }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "OK", response = APIResourceResponse.class), + @ApiResponse(code = 400, message = "Bad Request", response = Error.class), + @ApiResponse(code = 401, message = "Unauthorized", response = Void.class), + @ApiResponse(code = 403, message = "Forbidden", response = Void.class), + @ApiResponse(code = 404, message = "Not Found", response = Error.class), + @ApiResponse(code = 409, message = "Conflict", response = Error.class), + @ApiResponse(code = 500, message = "Server Error", response = Error.class), + @ApiResponse(code = 501, message = "Not Implemented", response = Error.class) + }) + public Response apiResourcesApiResourceIdPatch(@ApiParam(value = "ID of the API Resource.",required=true) @PathParam("apiResourceId") String apiResourceId, @ApiParam(value = "This represents the API resource to be patched." ,required=true) @Valid APIResourcePatchModel apIResourcePatchModel) { + + return delegate.apiResourcesApiResourceIdPatch(apiResourceId, apIResourcePatchModel ); + } + + @Valid + @GET + @Path("/{apiResourceId}/scopes") + + @Produces({ "application/json" }) + @ApiOperation(value = "Get API resource scopes", notes = "Get API resource scopes specified by the id", response = ScopeGetModel.class, responseContainer = "List", authorizations = { + @Authorization(value = "BasicAuth"), + @Authorization(value = "OAuth2", scopes = { + + }) + }, tags={ "API Resource Scopes", }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "OK", response = ScopeGetModel.class, responseContainer = "List"), + @ApiResponse(code = 401, message = "Unauthorized", response = Void.class), + @ApiResponse(code = 403, message = "Forbidden", response = Void.class), + @ApiResponse(code = 404, message = "Not Found", response = Error.class), + @ApiResponse(code = 500, message = "Server Error", response = Error.class) + }) + public Response apiResourcesApiResourceIdScopesGet(@ApiParam(value = "ID of the API Resource.",required=true) @PathParam("apiResourceId") String apiResourceId) { + + return delegate.apiResourcesApiResourceIdScopesGet(apiResourceId ); + } + + @Valid + @PUT + @Path("/{apiResourceId}/scopes") + @Consumes({ "application/json" }) + @Produces({ "application/json", "application/xml", }) + @ApiOperation(value = "Add scopes to API resource", notes = "Put scopes API resource specified by the id", response = Void.class, authorizations = { + @Authorization(value = "BasicAuth"), + @Authorization(value = "OAuth2", scopes = { + + }) + }, tags={ "API Resource Scopes", }) + @ApiResponses(value = { + @ApiResponse(code = 204, message = "No Content", response = Void.class), + @ApiResponse(code = 400, message = "Bad Request", response = Error.class), + @ApiResponse(code = 401, message = "Unauthorized", response = Void.class), + @ApiResponse(code = 403, message = "Forbidden", response = Void.class), + @ApiResponse(code = 404, message = "Not Found", response = Error.class), + @ApiResponse(code = 409, message = "Conflict", response = Error.class), + @ApiResponse(code = 500, message = "Server Error", response = Error.class) + }) + public Response apiResourcesApiResourceIdScopesPut(@ApiParam(value = "ID of the API Resource.",required=true) @PathParam("apiResourceId") String apiResourceId, @ApiParam(value = "This represents the API resource to be patched." ,required=true) @Valid List scopeCreationModel) { + + return delegate.apiResourcesApiResourceIdScopesPut(apiResourceId, scopeCreationModel ); + } + + @Valid + @DELETE + @Path("/{apiResourceId}/scopes/{scopeId}") + + @Produces({ "application/json" }) + @ApiOperation(value = "Delete API resource specified by the id", notes = "Delete API resource specified by the id", response = Void.class, authorizations = { + @Authorization(value = "BasicAuth"), + @Authorization(value = "OAuth2", scopes = { + + }) + }, tags={ "API Resource Scopes", }) + @ApiResponses(value = { + @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 apiResourcesApiResourceIdScopesScopeIdDelete(@ApiParam(value = "ID of the API Resource.",required=true) @PathParam("apiResourceId") String apiResourceId, @ApiParam(value = "ID of the Scope.",required=true) @PathParam("scopeId") String scopeId) { + + return delegate.apiResourcesApiResourceIdScopesScopeNameDelete(apiResourceId, scopeId ); + } + + @Valid + @GET + + + @Produces({ "application/json" }) + @ApiOperation(value = "List all API resources in the server", notes = "List all API resources in the server", response = APIResourceListResponse.class, authorizations = { + @Authorization(value = "BasicAuth"), + @Authorization(value = "OAuth2", scopes = { + + }) + }, tags={ "API Resources", }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "OK", response = APIResourceListResponse.class), + @ApiResponse(code = 401, message = "Unauthorized", response = Void.class), + @ApiResponse(code = 403, message = "Forbidden", response = Void.class), + @ApiResponse(code = 500, message = "Server Error", response = Error.class) + }) + public Response getAPIResources( @Valid@ApiParam(value = "Base64 encoded cursor value for backward pagination. ") @QueryParam("before") String before, @Valid@ApiParam(value = "Base64 encoded cursor value for forward pagination. ") @QueryParam("after") String after, @Valid@ApiParam(value = "Condition to filter the retrieval of records. Supports 'sw', 'co', 'ew' and 'eq' operations. ") @QueryParam("filter") String filter, @Valid@ApiParam(value = "Maximum number of records to return. ") @QueryParam("limit") Integer limit, @Valid@ApiParam(value = "Specifies the required parameters in the response. This parameter is not supported yet") @QueryParam("requiredAttributes") String requiredAttributes) { + + return delegate.getAPIResources(before, after, filter, limit, requiredAttributes ); + } + +} diff --git a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/ApiResourcesApiService.java b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/ApiResourcesApiService.java new file mode 100644 index 0000000000..d7d087d2d5 --- /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/ApiResourcesApiService.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; + +import java.util.List; + +import javax.ws.rs.core.Response; + + +public interface ApiResourcesApiService { + + public Response addAPIResource(APIResourceCreationModel apIResourceCreationModel); + + public Response apiResourcesApiResourceIdDelete(String apiResourceId); + + public Response apiResourcesApiResourceIdGet(String apiResourceId); + + public Response apiResourcesApiResourceIdPatch(String apiResourceId, APIResourcePatchModel apIResourcePatchModel); + + public Response apiResourcesApiResourceIdScopesGet(String apiResourceId); + + public Response apiResourcesApiResourceIdScopesPut(String apiResourceId, List scopeCreationModel); + + public Response apiResourcesApiResourceIdScopesScopeNameDelete(String apiResourceId, String scopeName); + + public Response getAPIResources(String before, String after, String filter, Integer limit, String requiredAttributes); +} 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/Error.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/Error.java new file mode 100644 index 0000000000..5fe989b98e --- /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/Error.java @@ -0,0 +1,161 @@ +/* + * 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 Error { + + private String code; + private String message; + private String description; + private String traceId; + + /** + **/ + public Error code(String code) { + + this.code = code; + return this; + } + + @ApiModelProperty(example = "AAA-00000", value = "") + @JsonProperty("code") + @Valid + public String getCode() { + return code; + } + public void setCode(String code) { + this.code = code; + } + + /** + **/ + public Error message(String message) { + + this.message = message; + return this; + } + + @ApiModelProperty(example = "Some Error Message", value = "") + @JsonProperty("message") + @Valid + public String getMessage() { + return message; + } + public void setMessage(String message) { + this.message = message; + } + + /** + **/ + public Error description(String description) { + + this.description = description; + return this; + } + + @ApiModelProperty(example = "Some Error Description", value = "") + @JsonProperty("description") + @Valid + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + + /** + **/ + public Error traceId(String traceId) { + + this.traceId = traceId; + return this; + } + + @ApiModelProperty(example = "e0fbcfeb-3617-43c4-8dd0-7b7d38e13047", value = "") + @JsonProperty("traceId") + @Valid + public String getTraceId() { + return traceId; + } + public void setTraceId(String traceId) { + this.traceId = traceId; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Error error = (Error) o; + return Objects.equals(this.code, error.code) && + Objects.equals(this.message, error.message) && + Objects.equals(this.description, error.description) && + Objects.equals(this.traceId, error.traceId); + } + + @Override + public int hashCode() { + return Objects.hash(code, message, description, traceId); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class Error {\n"); + + sb.append(" code: ").append(toIndentedString(code)).append("\n"); + sb.append(" message: ").append(toIndentedString(message)).append("\n"); + sb.append(" description: ").append(toIndentedString(description)).append("\n"); + sb.append(" traceId: ").append(toIndentedString(traceId)).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/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 new file mode 100644 index 0000000000..3403c2f707 --- /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/PaginationLink.java @@ -0,0 +1,119 @@ +/* + * 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 PaginationLink { + + private String rel; + private String href; + + /** + **/ + public PaginationLink rel(String rel) { + + this.rel = rel; + return this; + } + + @ApiModelProperty(example = "before", value = "") + @JsonProperty("rel") + @Valid + public String getRel() { + return rel; + } + public void setRel(String rel) { + this.rel = rel; + } + + /** + **/ + public PaginationLink href(String href) { + + this.href = href; + return this; + } + + @ApiModelProperty(example = "/o/orgName/api-resources?after=NDoy", value = "") + @JsonProperty("href") + @Valid + public String getHref() { + return href; + } + public void setHref(String href) { + this.href = href; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + PaginationLink paginationLink = (PaginationLink) o; + return Objects.equals(this.rel, paginationLink.rel) && + Objects.equals(this.href, paginationLink.href); + } + + @Override + public int hashCode() { + return Objects.hash(rel, href); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class PaginationLink {\n"); + + sb.append(" rel: ").append(toIndentedString(rel)).append("\n"); + sb.append(" href: ").append(toIndentedString(href)).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/ScopeCreationModel.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/ScopeCreationModel.java new file mode 100644 index 0000000000..d269682d48 --- /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/ScopeCreationModel.java @@ -0,0 +1,142 @@ +/* + * 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 ScopeCreationModel { + + private String name; + private String displayName; + private String description; + + /** + **/ + public ScopeCreationModel name(String name) { + + this.name = name; + return this; + } + + @ApiModelProperty(example = "greetings:write", 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 ScopeCreationModel displayName(String displayName) { + + this.displayName = displayName; + return this; + } + + @ApiModelProperty(example = "Write Greetings", value = "") + @JsonProperty("displayName") + @Valid + public String getDisplayName() { + return displayName; + } + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + /** + **/ + public ScopeCreationModel description(String description) { + + this.description = description; + return this; + } + + @ApiModelProperty(example = "Allows writing greetings", value = "") + @JsonProperty("description") + @Valid + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ScopeCreationModel scopeCreationModel = (ScopeCreationModel) o; + return Objects.equals(this.name, scopeCreationModel.name) && + Objects.equals(this.displayName, scopeCreationModel.displayName) && + Objects.equals(this.description, scopeCreationModel.description); + } + + @Override + public int hashCode() { + return Objects.hash(name, displayName, description); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class ScopeCreationModel {\n"); + + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" displayName: ").append(toIndentedString(displayName)).append("\n"); + sb.append(" description: ").append(toIndentedString(description)).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/ScopeGetModel.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/ScopeGetModel.java new file mode 100644 index 0000000000..b357201c91 --- /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/ScopeGetModel.java @@ -0,0 +1,167 @@ +/* + * 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 ScopeGetModel { + + private String id; + private String displayName; + private String name; + private String description; + + /** + **/ + public ScopeGetModel id(String id) { + + this.id = id; + return this; + } + + @ApiModelProperty(example = "sf23-fg34-fy53-hj23", 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 ScopeGetModel displayName(String displayName) { + + this.displayName = displayName; + return this; + } + + @ApiModelProperty(example = "Write", 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 ScopeGetModel name(String name) { + + this.name = name; + return this; + } + + @ApiModelProperty(example = "greetings:write", 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 ScopeGetModel description(String description) { + + this.description = description; + return this; + } + + @ApiModelProperty(example = "Allow writing greetings", value = "") + @JsonProperty("description") + @Valid + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ScopeGetModel scopeGetModel = (ScopeGetModel) o; + return Objects.equals(this.id, scopeGetModel.id) && + Objects.equals(this.displayName, scopeGetModel.displayName) && + Objects.equals(this.name, scopeGetModel.name) && + Objects.equals(this.description, scopeGetModel.description); + } + + @Override + public int hashCode() { + return Objects.hash(id, displayName, name, description); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class ScopeGetModel {\n"); + + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" displayName: ").append(toIndentedString(displayName)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" description: ").append(toIndentedString(description)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n"); + } +} + diff --git a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/ScopesApi.java b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/gen/java/org/wso2/carbon/identity/api/server/api/resource/v1/ScopesApi.java new file mode 100644 index 0000000000..e44caef832 --- /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/ScopesApi.java @@ -0,0 +1,69 @@ +/* + * 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.Error; +import org.wso2.carbon.identity.api.server.api.resource.v1.ScopeGetModel; +import org.wso2.carbon.identity.api.server.api.resource.v1.ScopesApiService; + +import javax.validation.Valid; +import javax.ws.rs.*; +import javax.ws.rs.core.Response; +import io.swagger.annotations.*; + +import javax.validation.constraints.*; + +@Path("/scopes") +@Api(description = "The scopes API") + +public class ScopesApi { + + @Autowired + private ScopesApiService delegate; + + @Valid + @GET + + + @Produces({ "application/json" }) + @ApiOperation(value = "Get all scopes in the tenant", notes = "Get all scopes in the tenant", response = ScopeGetModel.class, responseContainer = "List", authorizations = { + @Authorization(value = "BasicAuth"), + @Authorization(value = "OAuth2", scopes = { + + }) + }, tags={ "API Resource Scopes" }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "OK", response = ScopeGetModel.class, responseContainer = "List"), + @ApiResponse(code = 401, message = "Unauthorized", response = Void.class), + @ApiResponse(code = 403, message = "Forbidden", response = Void.class), + @ApiResponse(code = 404, message = "Not Found", response = Error.class), + @ApiResponse(code = 500, message = "Server Error", response = Error.class) + }) + public Response scopesGet( @Valid@ApiParam(value = "Condition to filter the retrieval of records. Supports 'sw', 'co', 'ew' and 'eq' operations. ") @QueryParam("filter") String filter) { + + return delegate.scopesGet(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/ScopesApiService.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/ScopesApiService.java new file mode 100644 index 0000000000..3880555282 --- /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/ScopesApiService.java @@ -0,0 +1,35 @@ +/* + * 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.Error; +import org.wso2.carbon.identity.api.server.api.resource.v1.ScopeGetModel; +import javax.ws.rs.core.Response; + + +public interface ScopesApiService { + + public Response scopesGet(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/SubscribedApplicationGetModel.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/SubscribedApplicationGetModel.java new file mode 100644 index 0000000000..7705c673ad --- /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/SubscribedApplicationGetModel.java @@ -0,0 +1,119 @@ +/* + * 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 SubscribedApplicationGetModel { + + private String name; + private String id; + + /** + **/ + public SubscribedApplicationGetModel name(String name) { + + this.name = name; + return this; + } + + @ApiModelProperty(example = "Application1", value = "") + @JsonProperty("name") + @Valid + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + /** + **/ + public SubscribedApplicationGetModel id(String id) { + + this.id = id; + return this; + } + + @ApiModelProperty(example = "23fd-23gd-54vv-sdhf", value = "") + @JsonProperty("id") + @Valid + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + SubscribedApplicationGetModel subscribedApplicationGetModel = (SubscribedApplicationGetModel) o; + return Objects.equals(this.name, subscribedApplicationGetModel.name) && + Objects.equals(this.id, subscribedApplicationGetModel.id); + } + + @Override + public int hashCode() { + return Objects.hash(name, id); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class SubscribedApplicationGetModel {\n"); + + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" id: ").append(toIndentedString(id)).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/factories/ApiResourcesApiServiceFactory.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/ApiResourcesApiServiceFactory.java new file mode 100644 index 0000000000..1d89750b24 --- /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/ApiResourcesApiServiceFactory.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.ApiResourcesApiService; +import org.wso2.carbon.identity.api.server.api.resource.v1.impl.ApiResourcesApiServiceImpl; + +public class ApiResourcesApiServiceFactory { + + private final static ApiResourcesApiService service = new ApiResourcesApiServiceImpl(); + + public static ApiResourcesApiService getApiResourcesApi() + { + return service; + } +} 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/ScopesApiServiceFactory.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/ScopesApiServiceFactory.java new file mode 100644 index 0000000000..cb91296d06 --- /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/ScopesApiServiceFactory.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.ScopesApiService; +import org.wso2.carbon.identity.api.server.api.resource.v1.impl.ScopesApiServiceImpl; + +public class ScopesApiServiceFactory { + + private final static ScopesApiService service = new ScopesApiServiceImpl(); + + public static ScopesApiService getScopesApi() + { + 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/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 new file mode 100644 index 0000000000..6e212893ae --- /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/constants/APIResourceMgtEndpointConstants.java @@ -0,0 +1,122 @@ +/* + * 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.constants; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * Constants related to API resource management. + */ +public class APIResourceMgtEndpointConstants { + + private APIResourceMgtEndpointConstants() { + } + + public static final String API_RESOURCE_TYPE = "BUSINESS"; + public static final String API_RESOURCE_MANAGEMENT_PREFIX = "API-RESOURCE-"; + public static final String API_RESOURCE_PATH_COMPONENT = "/api-resources"; + private static final List allowedAttributeList = new ArrayList<>(); + public static final List ALLOWED_SEARCH_ATTRIBUTES = Collections.unmodifiableList(allowedAttributeList); + 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"; + + static { + allowedAttributeList.add("description"); + allowedAttributeList.add("type"); + allowedAttributeList.add("requires_authorization"); + allowedAttributeList.add("scopes"); + } + + /** + * Enum for error messages. + */ + public enum ErrorMessage { + + // Client errors. + ERROR_CODE_API_RESOURCE_LIMIT_REACHED("60001", + "Unable to create an API resource.", + "Maximum number of allowed API resources have been reached."), + ERROR_CODE_API_RESOURCE_NOT_FOUND("60002", + "Unable to find the API resource.", + "Unable to find the API resource with the id: %s in the tenant domain."), + ERROR_CODE_INVALID_API_RESOURCE_NAME("60003", + "Invalid API resource name provided.", "API resource name is required."), + ERROR_CODE_INVALID_API_RESOURCE_IDENTIFIER("60004", + "Invalid API resource identifier provided.", "API resource identifier is required."), + ERROR_CODE_INVALID_SCOPE_NAME("60005", + "Invalid scope name provided.", "Scope name is required."), + ERROR_CODE_REMOVED_SCOPES_PATCH_NOT_SUPPORTED("60006", + "Removed scopes patching is not supported yet.", + "Removed scopes patching is not supported yet for API resources."), + ERROR_CODE_INVALID_SEARCH_ATTRIBUTE("60007", + "Invalid search attribute.", + "Invalid search attribute: %s."), + ERROR_CODE_RESTRICTED_SCOPE_NAME("60008", + "Restricted scope name provided.", "Scope name is restricted."), + ERROR_CODE_RESTRICTED_OIDC_SCOPES("60009", "Existing OIDC scope name provided.", + "Provided scopes name is already exists in the system as an OIDC scope."), + ERROR_CODE_INVALID_LIMIT("60010", "Invalid limit provided.", + "Limit should be a positive integer."), + ERROR_CODE_BOTH_BEFORE_AFTER_PROVIDED("60011", "Invalid before/after provided.", + "Both before and after parameters cannot be provided at the same time."), + + // Server errors. + ERROR_CODE_ADD_API_RESOURCE("65001", "Error while adding api resource.", "Server encountered an error while " + + "adding the api resource."), + + ERROR_CODE_VALIDATE_SCOPES("65002", "Error while validating scopes.", "Server encountered an error while " + + "validating the scopes."), + ; + private final String code; + private final String message; + private final String description; + + ErrorMessage(String code, String message, String description) { + + this.code = code; + this.message = message; + this.description = description; + } + + public String getCode() { + + return API_RESOURCE_MANAGEMENT_PREFIX + code; + } + + public String getMessage() { + + return message; + } + + public String getDescription() { + + return description; + } + + @Override + public String toString() { + + return code + " | " + message; + } + } +} diff --git a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/core/ServerAPIResourceManagementService.java b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/core/ServerAPIResourceManagementService.java new file mode 100644 index 0000000000..c31252fd4d --- /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/ServerAPIResourceManagementService.java @@ -0,0 +1,468 @@ +/* + * 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.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.CarbonContext; +import org.wso2.carbon.identity.api.resource.mgt.APIResourceMgtException; +import org.wso2.carbon.identity.api.resource.mgt.model.APIResourceSearchResult; +import org.wso2.carbon.identity.api.server.api.resource.common.APIResourceManagementServiceHolder; +import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceCreationModel; +import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceListItem; +import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceListResponse; +import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourcePatchModel; +import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceResponse; +import org.wso2.carbon.identity.api.server.api.resource.v1.PaginationLink; +import org.wso2.carbon.identity.api.server.api.resource.v1.ScopeCreationModel; +import org.wso2.carbon.identity.api.server.api.resource.v1.ScopeGetModel; +import org.wso2.carbon.identity.api.server.api.resource.v1.constants.APIResourceMgtEndpointConstants; +import org.wso2.carbon.identity.api.server.api.resource.v1.constants.APIResourceMgtEndpointConstants.ErrorMessage; +import org.wso2.carbon.identity.api.server.api.resource.v1.exception.APIResourceMgtEndpointException; +import org.wso2.carbon.identity.api.server.api.resource.v1.util.APIResourceMgtEndpointUtil; +import org.wso2.carbon.identity.api.server.common.ContextLoader; +import org.wso2.carbon.identity.application.common.model.APIResource; +import org.wso2.carbon.identity.application.common.model.Scope; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Base64; +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.api.resource.v1.constants.APIResourceMgtEndpointConstants.ASC_SORT_ORDER; +import static org.wso2.carbon.identity.api.server.api.resource.v1.constants.APIResourceMgtEndpointConstants.DEFAULT_LIMIT; +import static org.wso2.carbon.identity.api.server.api.resource.v1.constants.APIResourceMgtEndpointConstants.DESC_SORT_ORDER; +import static org.wso2.carbon.identity.api.server.common.Constants.V1_API_PATH_COMPONENT; + +/** + * Server API Resource Management Service. + */ +public class ServerAPIResourceManagementService { + + private static final ServerAPIResourceManagementService instance = new ServerAPIResourceManagementService(); + + private static final Log LOG = LogFactory.getLog(ServerAPIResourceManagementService.class); + + private ServerAPIResourceManagementService() { + + } + + public static ServerAPIResourceManagementService getInstance() { + + return instance; + } + + /** + * Add API resource. + * + * @param apIResourceCreationModel API resource creation model. + * @return Response. + */ + public APIResourceResponse addAPIResourceWithResourceId(APIResourceCreationModel apIResourceCreationModel) { + + if (LOG.isDebugEnabled()) { + LOG.debug("Adding API resource with resource id: " + apIResourceCreationModel.getIdentifier()); + } + try { + APIResource apiResource = createAPIResource(apIResourceCreationModel); + APIResource createdAPIResource = APIResourceManagementServiceHolder.getApiResourceManager() + .addAPIResource(apiResource, CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); + if (createdAPIResource == null) { + LOG.error(ErrorMessage.ERROR_CODE_ADD_API_RESOURCE.getDescription()); + throw APIResourceMgtEndpointUtil.handleException(Response.Status.INTERNAL_SERVER_ERROR, + ErrorMessage.ERROR_CODE_ADD_API_RESOURCE); + } + return buildAPIResourceResponse(createdAPIResource); + } catch (APIResourceMgtException e) { + throw APIResourceMgtEndpointUtil.handleAPIResourceMgtException(e); + } + } + + /** + * Get API Resources. + * + * @param before - before parameter for cursor based pagination. + * @param after - after parameter for cursor based pagination. + * @param filter - filter parameter. + * @return Response with API Resources list. + */ + public APIResourceListResponse getAPIResources(String before, String after, String filter, Integer limit) { + + APIResourceListResponse apiResourceListResponse = new APIResourceListResponse(); + + try { + // Set default values if the parameters are not set. + limit = validatedLimit(limit); + + // Validate before and after parameters. + if (StringUtils.isNotBlank(before) && StringUtils.isNotBlank(after)) { + throw APIResourceMgtEndpointUtil.handleException(Response.Status.BAD_REQUEST, + APIResourceMgtEndpointConstants.ErrorMessage.ERROR_CODE_BOTH_BEFORE_AFTER_PROVIDED); + } + + // Set the pagination sort order. + String paginationSortOrder = StringUtils.isNotBlank(before) ? DESC_SORT_ORDER : ASC_SORT_ORDER; + + APIResourceSearchResult apiResourceSearchResult = APIResourceManagementServiceHolder.getApiResourceManager() + .getAPIResources(before, after, limit + 1, filter, paginationSortOrder, + CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); + List apiResources = apiResourceSearchResult.getAPIResources(); + + if (limit != 0 && CollectionUtils.isNotEmpty(apiResources)) { + boolean hasMoreItems = apiResources.size() > limit; + boolean needsReverse = StringUtils.isNotBlank(before); + boolean isFirstPage = (StringUtils.isBlank(before) && StringUtils.isBlank(after)) || + (StringUtils.isNotBlank(before) && !hasMoreItems); + boolean isLastPage = !hasMoreItems && (StringUtils.isNotBlank(after) || StringUtils.isBlank(before)); + + String url = "?limit=" + limit; + + if (StringUtils.isNotBlank(filter)) { + try { + url += "&filter=" + URLEncoder.encode(filter, StandardCharsets.UTF_8.name()); + } catch (UnsupportedEncodingException e) { + LOG.error("Server encountered an error while building pagination URL for the response.", e); + } + } + + if (hasMoreItems) { + apiResources.remove(apiResources.size() - 1); + } + if (needsReverse) { + Collections.reverse(apiResources); + } + if (!isFirstPage) { + String encodedString = Base64.getEncoder().encodeToString(apiResources.get(0).getCursorKey() + .toString().getBytes(StandardCharsets.UTF_8)); + apiResourceListResponse.addLinksItem(buildPaginationLink(url + "&before=" + encodedString, + "previous")); + } + if (!isLastPage) { + String encodedString = Base64.getEncoder().encodeToString(apiResources.get(apiResources.size() - 1) + .getCursorKey().toString().getBytes(StandardCharsets.UTF_8)); + apiResourceListResponse.addLinksItem(buildPaginationLink(url + "&after=" + encodedString, "next")); + } + } + if (apiResources == null || apiResources.isEmpty()) { + apiResourceListResponse.setTotalResults(0); + apiResourceListResponse.setApiResources(new ArrayList<>()); + return apiResourceListResponse; + } + apiResourceListResponse.setTotalResults(apiResourceSearchResult.getTotalCount()); + apiResourceListResponse.setApiResources(apiResourceSearchResult.getAPIResources().stream() + .map(this::buildAPIResourceListItem).collect(Collectors.toList())); + } catch (APIResourceMgtException e) { + throw APIResourceMgtEndpointUtil.handleAPIResourceMgtException(e); + } + return apiResourceListResponse; + } + + /** + * Get API Resource by ID. + * + * @param apiResourceID API Resource ID. + * @return API Resource. + */ + public APIResource getAPIResourceById(String apiResourceID) { + + try { + APIResource apiResource = APIResourceManagementServiceHolder.getApiResourceManager() + .getAPIResourceById(apiResourceID, CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); + if (apiResource == null) { + throw APIResourceMgtEndpointUtil.handleException(Response.Status.NOT_FOUND, + APIResourceMgtEndpointConstants.ErrorMessage.ERROR_CODE_API_RESOURCE_NOT_FOUND, apiResourceID); + } + return apiResource; + } catch (APIResourceMgtException e) { + throw APIResourceMgtEndpointUtil.handleAPIResourceMgtException(e); + } + } + + /** + * Patch API Resource by ID. + * + * @param apiResourceID API Resource ID. + * @param apiResourcePatchModel API Resource Patch Model. + */ + public void patchAPIResourceById(String apiResourceID, APIResourcePatchModel apiResourcePatchModel) { + + try { + APIResource currentAPIResource = getAPIResourceById(apiResourceID); + + if (apiResourcePatchModel.getRemovedScopes() != null) { + LOG.debug("Removed scopes field is not supported in patch operation."); + throw APIResourceMgtEndpointUtil.handleException(Response.Status.NOT_IMPLEMENTED, + APIResourceMgtEndpointConstants.ErrorMessage.ERROR_CODE_REMOVED_SCOPES_PATCH_NOT_SUPPORTED); + } + + String displayName = apiResourcePatchModel.getName() == null ? currentAPIResource.getName() : + apiResourcePatchModel.getName(); + String description = apiResourcePatchModel.getDescription() == null ? currentAPIResource.getDescription() : + apiResourcePatchModel.getDescription(); + List addedScopes = createScopes(apiResourcePatchModel.getAddedScopes()); + // Creating an empty list of removed scope names since operation is not supported. + List removedScopeNames = new ArrayList<>(); + + APIResource.APIResourceBuilder apiResourceBuilder = new APIResource.APIResourceBuilder() + .name(displayName) + .id(apiResourceID) + .description(description); + APIResource apiResource = apiResourceBuilder.build(); + APIResourceManagementServiceHolder.getApiResourceManager().updateAPIResource(apiResource, addedScopes, + removedScopeNames, CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); + } catch (APIResourceMgtException e) { + throw APIResourceMgtEndpointUtil.handleAPIResourceMgtException(e); + } + } + + /** + * Delete API Resource by ID. + * + * @param apiResourceID API Resource ID. + */ + public void deleteAPIResource(String apiResourceID) { + + try { + if (LOG.isDebugEnabled()) { + LOG.debug("Deleting API Resource with ID: " + apiResourceID); + } + APIResourceManagementServiceHolder.getApiResourceManager().deleteAPIResourceById(apiResourceID, + CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); + } catch (APIResourceMgtException e) { + throw APIResourceMgtEndpointUtil.handleAPIResourceMgtException(e); + } + } + + /** + * Get scopes by API ID. + * + * @param apiResourceId API resource id. + * @return List of scopes. + */ + public List getScopesByAPIId(String apiResourceId) { + + try { + APIResource apiResource = APIResourceManagementServiceHolder.getApiResourceManager() + .getAPIResourceById(apiResourceId, CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); + if (apiResource == null) { + throw APIResourceMgtEndpointUtil.handleException(Response.Status.NOT_FOUND, + APIResourceMgtEndpointConstants.ErrorMessage.ERROR_CODE_API_RESOURCE_NOT_FOUND, apiResourceId); + } + return apiResource.getScopes(); + } catch (APIResourceMgtException e) { + throw APIResourceMgtEndpointUtil.handleAPIResourceMgtException(e); + } + } + + /** + * Put scopes by API ID. This replaces existing scopes. + * + * @param apiResourceId API resource id. + * @param scopeCreationModels Scope creation models. + */ + public void putScopesByAPIId(String apiResourceId, List scopeCreationModels) { + + try { + APIResource apiResource = APIResourceManagementServiceHolder.getApiResourceManager() + .getAPIResourceById(apiResourceId, CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); + if (apiResource == null) { + throw APIResourceMgtEndpointUtil.handleException(Response.Status.NOT_FOUND, + APIResourceMgtEndpointConstants.ErrorMessage.ERROR_CODE_API_RESOURCE_NOT_FOUND, apiResourceId); + } + List scopes = createScopes(scopeCreationModels); + APIResourceManagementServiceHolder.getApiResourceManager().putScopes(apiResourceId, apiResource.getScopes(), + scopes, CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); + } catch (APIResourceMgtException e) { + throw APIResourceMgtEndpointUtil.handleAPIResourceMgtException(e); + } + } + + /** + * Delete scopes by the scope ID. + * + * @param apiResourceId API Resource ID. + * @param scopeName Scope Name. + */ + public void deleteScopeByScopeName(String apiResourceId, String scopeName) { + + try { + if (LOG.isDebugEnabled()) { + LOG.debug("Deleting scope with ID: " + scopeName + " of API Resource ID: " + apiResourceId); + } + APIResourceManagementServiceHolder.getApiResourceManager() + .deleteAPIScopeByScopeName(apiResourceId, scopeName, + CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); + } catch (APIResourceMgtException e) { + throw APIResourceMgtEndpointUtil.handleAPIResourceMgtException(e); + } + } + + /** + * Search Scopes registered in the tenant. + * + * @param filter Filter query. + * @return List of scopes. + */ + public List getScopesByTenant(String filter) { + + try { + return APIResourceManagementServiceHolder.getApiResourceManager() + .getScopesByTenantDomain(CarbonContext.getThreadLocalCarbonContext().getTenantDomain(), filter); + } catch (APIResourceMgtException e) { + throw APIResourceMgtEndpointUtil.handleAPIResourceMgtException(e); + } + } + + /** + * Build APIResourceResponse from APIResource. + * + * @param apiResource APIResource object. + * @return APIResourceResponse object. + */ + private APIResourceResponse buildAPIResourceResponse(APIResource apiResource) { + + return new APIResourceResponse() + .id(apiResource.getId()) + .name(apiResource.getName()) + .identifier(apiResource.getIdentifier()) + .description(apiResource.getDescription()) + .scopes(apiResource.getScopes().stream().map(this::buildScopeGetResponse) + .collect(Collectors.toList())) + .requiresAuthorization(apiResource.isRequiresAuthorization()); + } + + /** + * 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()); + } + + /** + * Create API resource from the API resource creation model. + * + * @param apIResourceCreationModel API resource creation model. + * @return API resource. + */ + private APIResource createAPIResource(APIResourceCreationModel apIResourceCreationModel) + throws APIResourceMgtException { + + APIResourceMgtEndpointUtil.validateAPIResource(apIResourceCreationModel); + APIResource.APIResourceBuilder apiResourceBuilder = new APIResource.APIResourceBuilder() + .name(apIResourceCreationModel.getName()) + .identifier(apIResourceCreationModel.getIdentifier()) + .description(apIResourceCreationModel.getDescription()) + .scopes(createScopes(apIResourceCreationModel.getScopes())) + .requiresAuthorization(apIResourceCreationModel.getRequiresAuthorization() != null ? + apIResourceCreationModel.getRequiresAuthorization() : true) + .type(APIResourceMgtEndpointConstants.API_RESOURCE_TYPE); + return apiResourceBuilder.build(); + } + + /** + * Create scopes from the scope creation models. + * + * @param scopeCreationModels Scope creation models. + * @return List of scopes. + */ + private List createScopes(List scopeCreationModels) + throws APIResourceMgtException { + + APIResourceMgtEndpointUtil.validateScopes(scopeCreationModels); + List scopes = new ArrayList<>(); + if (scopeCreationModels == null) { + return scopes; + } + for (ScopeCreationModel scopeCreationModel : scopeCreationModels) { + Scope.ScopeBuilder scopeBuilder = new Scope.ScopeBuilder() + .name(scopeCreationModel.getName()) + .displayName(scopeCreationModel.getDisplayName() != null ? scopeCreationModel.getDisplayName() : + scopeCreationModel.getName()) + .description(scopeCreationModel.getDescription()); + scopes.add(scopeBuilder.build()); + } + return scopes; + } + + /** + * Build API Resource List Item from API Resource. + * + * @param apiResource API Resource. + * @return API Resource List Item. + */ + private APIResourceListItem buildAPIResourceListItem(APIResource apiResource) { + + return new APIResourceListItem() + .id(apiResource.getId()) + .name(apiResource.getName()) + .identifier(apiResource.getIdentifier()) + .type(apiResource.getType()) + .requiresAuthorization(apiResource.isRequiresAuthorization()) + .self(V1_API_PATH_COMPONENT + APIResourceMgtEndpointConstants.API_RESOURCE_PATH_COMPONENT + "/" + + apiResource.getId()); + } + + /** + * Build Pagination Link. + * + * @param url URL + * @param rel Rel + * @return Pagination Link + */ + private PaginationLink buildPaginationLink(String url, String rel) { + + return new PaginationLink() + .href(ContextLoader.buildURIForHeader(V1_API_PATH_COMPONENT + + APIResourceMgtEndpointConstants.API_RESOURCE_PATH_COMPONENT + url).toString()) + .rel(rel); + } + + /** + * Validate limit parameter. + * + * @param limit Limit parameter. + * @return Validated limit. + * @throws APIResourceMgtEndpointException if the limit is invalid. + */ + private static Integer validatedLimit(Integer limit) throws APIResourceMgtEndpointException { + + limit = limit == null ? DEFAULT_LIMIT : limit; + if (limit == 0 || limit < 0) { + throw APIResourceMgtEndpointUtil.handleException(Response.Status.BAD_REQUEST, + ErrorMessage.ERROR_CODE_INVALID_LIMIT); + } + return limit; + } +} 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/exception/APIResourceMgtEndpointException.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/exception/APIResourceMgtEndpointException.java new file mode 100644 index 0000000000..9976a6f910 --- /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/exception/APIResourceMgtEndpointException.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.exception; + +import org.wso2.carbon.identity.api.server.api.resource.v1.Error; + +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +/** + * Exception class for API resource management endpoint. + */ +public class APIResourceMgtEndpointException extends WebApplicationException { + + public APIResourceMgtEndpointException(Response.Status status, Error error) { + + super(Response.status(status).entity(error).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .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/impl/ApiResourcesApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/impl/ApiResourcesApiServiceImpl.java new file mode 100644 index 0000000000..8a32305721 --- /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/ApiResourcesApiServiceImpl.java @@ -0,0 +1,103 @@ +/* + * 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.springframework.beans.factory.annotation.Autowired; +import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceCreationModel; +import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourcePatchModel; +import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceResponse; +import org.wso2.carbon.identity.api.server.api.resource.v1.ApiResourcesApiService; +import org.wso2.carbon.identity.api.server.api.resource.v1.ScopeCreationModel; +import org.wso2.carbon.identity.api.server.api.resource.v1.constants.APIResourceMgtEndpointConstants; +import org.wso2.carbon.identity.api.server.api.resource.v1.core.ServerAPIResourceManagementService; +import org.wso2.carbon.identity.api.server.common.ContextLoader; + +import java.net.URI; +import java.util.List; + +import javax.ws.rs.core.Response; + +import static org.wso2.carbon.identity.api.server.common.Constants.V1_API_PATH_COMPONENT; + +/** + * Implementation of the Api resources REST Api. + */ +public class ApiResourcesApiServiceImpl implements ApiResourcesApiService { + + @Autowired + ServerAPIResourceManagementService serverAPIResourceManagementService; + + @Override + public Response addAPIResource(APIResourceCreationModel apIResourceCreationModel) { + + APIResourceResponse apiResourceResponse = + serverAPIResourceManagementService.addAPIResourceWithResourceId(apIResourceCreationModel); + URI location = ContextLoader.buildURIForHeader(V1_API_PATH_COMPONENT + + APIResourceMgtEndpointConstants.API_RESOURCE_PATH_COMPONENT + "/" + apiResourceResponse.getId()); + return Response.created(location).entity(apiResourceResponse).build(); + } + + @Override + public Response apiResourcesApiResourceIdDelete(String apiResourceId) { + + serverAPIResourceManagementService.deleteAPIResource(apiResourceId); + return Response.noContent().build(); + } + + @Override + public Response apiResourcesApiResourceIdGet(String apiResourceId) { + + return Response.ok().entity(serverAPIResourceManagementService.getAPIResourceById(apiResourceId)).build(); + } + + @Override + public Response apiResourcesApiResourceIdPatch(String apiResourceId, APIResourcePatchModel apIResourcePatchModel) { + + serverAPIResourceManagementService.patchAPIResourceById(apiResourceId, apIResourcePatchModel); + return Response.noContent().build(); + } + + @Override + public Response apiResourcesApiResourceIdScopesGet(String apiResourceId) { + + return Response.ok().entity(serverAPIResourceManagementService.getScopesByAPIId(apiResourceId)).build(); + } + + @Override + public Response apiResourcesApiResourceIdScopesPut(String apiResourceId, + List scopeCreationModel) { + + serverAPIResourceManagementService.putScopesByAPIId(apiResourceId, scopeCreationModel); + return Response.noContent().build(); + } + + @Override + public Response apiResourcesApiResourceIdScopesScopeNameDelete(String apiResourceId, String scopeName) { + + serverAPIResourceManagementService.deleteScopeByScopeName(apiResourceId, scopeName); + return Response.noContent().build(); + } + + @Override + public Response getAPIResources(String before, String after, String filter, Integer limit, String sortOrder) { + + return Response.ok().entity(serverAPIResourceManagementService.getAPIResources(before, after, filter, limit)) + .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/impl/ScopesApiServiceImpl.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/ScopesApiServiceImpl.java new file mode 100644 index 0000000000..b66d889841 --- /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/ScopesApiServiceImpl.java @@ -0,0 +1,39 @@ +/* + * 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.ScopesApiService; +import org.wso2.carbon.identity.api.server.api.resource.v1.core.ServerAPIResourceManagementService; + +import javax.ws.rs.core.Response; + +/** + * Implementation of scopes API. + */ +public class ScopesApiServiceImpl implements ScopesApiService { + + ServerAPIResourceManagementService serverAPIResourceManagementService = + ServerAPIResourceManagementService.getInstance(); + + @Override + public Response scopesGet(String filter) { + + return Response.ok().entity(serverAPIResourceManagementService.getScopesByTenant(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 new file mode 100644 index 0000000000..dff0b7e878 --- /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/util/APIResourceMgtEndpointUtil.java @@ -0,0 +1,183 @@ +/* + * 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.util; + +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.mgt.APIResourceMgtClientException; +import org.wso2.carbon.identity.api.resource.mgt.APIResourceMgtException; +import org.wso2.carbon.identity.api.server.api.resource.common.APIResourceManagementServiceHolder; +import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceCreationModel; +import org.wso2.carbon.identity.api.server.api.resource.v1.Error; +import org.wso2.carbon.identity.api.server.api.resource.v1.ScopeCreationModel; +import org.wso2.carbon.identity.api.server.api.resource.v1.constants.APIResourceMgtEndpointConstants; +import org.wso2.carbon.identity.api.server.api.resource.v1.exception.APIResourceMgtEndpointException; +import org.wso2.carbon.identity.api.server.common.ContextLoader; +import org.wso2.carbon.identity.core.util.IdentityUtil; +import org.wso2.carbon.identity.oauth.IdentityOAuthAdminException; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +import javax.ws.rs.core.Response; + +import static org.wso2.carbon.identity.api.resource.mgt.constant.APIResourceManagementConstants.ErrorMessages.ERROR_CODE_API_RESOURCE_ALREADY_EXISTS; +import static org.wso2.carbon.identity.api.resource.mgt.constant.APIResourceManagementConstants.ErrorMessages.ERROR_CODE_SCOPE_ALREADY_EXISTS; +import static org.wso2.carbon.identity.api.server.api.resource.v1.constants.APIResourceMgtEndpointConstants.ErrorMessage.ERROR_CODE_INVALID_API_RESOURCE_IDENTIFIER; +import static org.wso2.carbon.identity.api.server.api.resource.v1.constants.APIResourceMgtEndpointConstants.ErrorMessage.ERROR_CODE_INVALID_API_RESOURCE_NAME; +import static org.wso2.carbon.identity.api.server.api.resource.v1.constants.APIResourceMgtEndpointConstants.ErrorMessage.ERROR_CODE_INVALID_SCOPE_NAME; +import static org.wso2.carbon.identity.api.server.api.resource.v1.constants.APIResourceMgtEndpointConstants.ErrorMessage.ERROR_CODE_INVALID_SEARCH_ATTRIBUTE; +import static org.wso2.carbon.identity.api.server.api.resource.v1.constants.APIResourceMgtEndpointConstants.ErrorMessage.ERROR_CODE_RESTRICTED_OIDC_SCOPES; +import static org.wso2.carbon.identity.api.server.api.resource.v1.constants.APIResourceMgtEndpointConstants.ErrorMessage.ERROR_CODE_RESTRICTED_SCOPE_NAME; +import static org.wso2.carbon.identity.api.server.api.resource.v1.constants.APIResourceMgtEndpointConstants.ErrorMessage.ERROR_CODE_VALIDATE_SCOPES; +import static org.wso2.carbon.identity.api.server.common.Constants.ERROR_CODE_DELIMITER; + +/** + * Utility class for API resource management endpoint. + */ +public class APIResourceMgtEndpointUtil { + + private static final Log log = LogFactory.getLog(APIResourceMgtEndpointUtil.class); + + public static void validateAPIResource(APIResourceCreationModel apiResource) { + + if (StringUtils.isBlank(apiResource.getName())) { + throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_INVALID_API_RESOURCE_NAME); + } + if (StringUtils.isBlank(apiResource.getIdentifier())) { + throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_INVALID_API_RESOURCE_IDENTIFIER); + } + } + + public static void validateScopes(List scopes) { + + if (scopes == null || scopes.isEmpty()) { + return; + } + for (ScopeCreationModel scope : scopes) { + // Validate scope name. + if (StringUtils.isBlank(scope.getName())) { + throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_INVALID_SCOPE_NAME); + } + // Validate restricted scope names. + List restrictedScopes = + IdentityUtil.getPropertyAsList(APIResourceMgtEndpointConstants.RESTRICTED_OAUTH2_SCOPES); + for (String restrictedScope : restrictedScopes) { + if (scope.getName().startsWith(restrictedScope)) { + throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_RESTRICTED_SCOPE_NAME); + } + } + + // Validate OIDC scopes. + try { + List registeredOIDCScopes = APIResourceManagementServiceHolder.getOAuthAdminServiceImpl() + .getRegisteredOIDCScope(ContextLoader.getTenantDomainFromContext()); + if (registeredOIDCScopes.contains(scope.getName())) { + throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_RESTRICTED_OIDC_SCOPES); + } + } catch (IdentityOAuthAdminException e) { + throw handleException(Response.Status.INTERNAL_SERVER_ERROR, ERROR_CODE_VALIDATE_SCOPES); + } + } + } + + /** + * Validate the attributes provided for search. + * + * @param attributes List of attributes to be validated. + * @return List of validated attributes. + */ + public static List validateAndConvertToLowerCase(List attributes) { + + List validatedAttributes = new ArrayList<>(); + + if (attributes == null || attributes.isEmpty()) { + return validatedAttributes; + } + + for (String attribute : attributes) { + String lowerCaseAttribute = attribute.toLowerCase(Locale.ENGLISH); + if (!APIResourceMgtEndpointConstants.ALLOWED_SEARCH_ATTRIBUTES.contains(lowerCaseAttribute)) { + throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_INVALID_SEARCH_ATTRIBUTE); + } + validatedAttributes.add(lowerCaseAttribute); + } + return validatedAttributes; + } + + public static APIResourceMgtEndpointException handleException(Response.Status status, + APIResourceMgtEndpointConstants.ErrorMessage error) { + + return new APIResourceMgtEndpointException(status, getError(error.getCode(), error.getMessage(), + error.getDescription())); + } + + public static APIResourceMgtEndpointException handleException(Response.Status status, + APIResourceMgtEndpointConstants.ErrorMessage error, + String data) { + + return new APIResourceMgtEndpointException(status, getError(error.getCode(), error.getMessage(), + String.format(error.getDescription(), data))); + } + + public static APIResourceMgtEndpointException handleException(Response.Status status, String errorCode, + String message, String description) { + + return new APIResourceMgtEndpointException(status, getError(errorCode, message, description)); + } + + public static APIResourceMgtEndpointException handleAPIResourceMgtException(APIResourceMgtException e) { + + Response.Status status = Response.Status.INTERNAL_SERVER_ERROR; + if (e instanceof APIResourceMgtClientException) { + log.debug(e.getMessage(), e); + if (ERROR_CODE_API_RESOURCE_ALREADY_EXISTS.getCode().equals(e.getErrorCode()) || + ERROR_CODE_SCOPE_ALREADY_EXISTS.getCode().equals(e.getErrorCode())) { + status = Response.Status.CONFLICT; + } else { + status = Response.Status.BAD_REQUEST; + } + } else { + log.error(e.getMessage(), e); + } + 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()); + } + + /** + * Returns a generic error object. + * + * @param errorCode Error code. + * @param errorMessage Error message. + * @param errorDescription Error description. + * @return A generic error with the specified details. + */ + public static Error getError(String errorCode, String errorMessage, String errorDescription) { + + Error error = new Error(); + error.setCode(errorCode); + error.setMessage(errorMessage); + error.setDescription(errorDescription); + return error; + } +} 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 new file mode 100644 index 0000000000..3e3459b97b --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/resources/APIResources.yaml @@ -0,0 +1,780 @@ +openapi: 3.0.0 +info: + description: > + This document specifies an **API Resource Management RESTful API** for **WSO2 + Identity Server**. + version: "v1" + title: WSO2 Identity Server - API Resource Management Rest API + termsOfService: 'http://swagger.io/terms/' + contact: + name: WSO2 + url: 'http://wso2.com/products/identity-server/' + email: architecture@wso2.org + license: + name: Apache 2.0 + url: 'http://www.apache.org/licenses/LICENSE-2.0.html' + +security: + - OAuth2: [] + - BasicAuth: [] + +servers: + - url: 'https://{server-url}/t/{tenant-domain}/api/server/v1' + variables: + tenant-domain: + default: "carbon.super" + server-url: + default: "localhost:9443" + +paths: + /api-resources: + post: + tags: + - API Resources + operationId: addAPIResource + summary: Add a new API resource + description: > + Add a new API resource + Permission required:
+ * /permission/admin/manage/identity/apiresourcemgt/create
+ Scope required:
+ * internal_api_resource_create + responses: + 200: + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/APIResourceResponse' + 400: + description: Bad Request + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + 401: + description: Unauthorized + 403: + description: Forbidden + 404: + description: Not Found + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + 409: + description: Conflict + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + application/xml: + schema: + $ref: '#/components/schemas/Error' + 500: + description: Server Error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/APIResourceCreationModel' + description: This represents the API resource to be created. + required: true + get: + tags: + - API Resources + summary: List all API resources in the server + description: > + List all API resources in the server + Permission required:
+ * /permission/admin/manage/identity/apiresourcemgt/view
+ Scope required:
+ * internal_api_resource_view + operationId: getAPIResources + parameters: + - $ref: '#/components/parameters/before' + - $ref: '#/components/parameters/after' + - $ref: '#/components/parameters/filter' + - $ref: '#/components/parameters/limit' + - $ref: '#/components/parameters/requiredAttributes' + responses: + 200: + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/APIResourceListResponse' + 401: + description: Unauthorized + 403: + description: Forbidden + 500: + description: Server Error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + + /api-resources/{apiResourceId}: + get: + tags: + - API Resources + summary: Get API resource specified by the id + description: > + Get API resource specified by the id + Permission required:
+ * /permission/admin/manage/identity/apiresourcemgt/view
+ Scope required:
+ * internal_api_resource_view + parameters: + - $ref: '#/components/parameters/apiResourceId' + responses: + 200: + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/APIResourceResponse' + 401: + description: Unauthorized + 403: + description: Forbidden + 500: + description: Server Error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + + patch: + tags: + - API Resources + summary: Patch API resource specified by the id + 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
+ Scope required:
+ * internal_api_resource_update + parameters: + - $ref: '#/components/parameters/apiResourceId' + responses: + 200: + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/APIResourceResponse' + 400: + description: Bad Request + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + 401: + description: Unauthorized + 403: + description: Forbidden + 404: + description: Not Found + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + 409: + description: Conflict + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + application/xml: + schema: + $ref: '#/components/schemas/Error' + 500: + description: Server Error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + 501: + description: Not Implemented + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/APIResourcePatchModel' + description: This represents the API resource to be patched. + required: true + delete: + tags: + - API Resources + summary: Delete API resource specified by the id + description: > + Delete API resource specified by the id + Permission required:
+ * /permission/admin/manage/identity/apiresourcemgt/delete
+ Scope required:
+ * internal_api_resource_delete + parameters: + - $ref: '#/components/parameters/apiResourceId' + responses: + 204: + description: No Content + 401: + description: Unauthorized + 403: + description: Forbidden + 500: + description: Server Error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + + /api-resources/{apiResourceId}/scopes: + get: + tags: + - API Resource Scopes + summary: Get API resource scopes + description: > + Get API resource scopes specified by the id + Permission required:
+ * /permission/admin/manage/identity/apiresourcemgt/view
+ Scope required:
+ * internal_api_resource_view + parameters: + - $ref: '#/components/parameters/apiResourceId' + responses: + 200: + description: OK + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/ScopeGetModel' + 401: + description: Unauthorized + 403: + description: Forbidden + 404: + description: Not Found + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + 500: + description: Server Error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + + put: + tags: + - API Resource Scopes + summary: Add scopes to API resource + description: > + Put scopes API resource specified by the id + Permission required:
+ * /permission/admin/manage/identity/apiresourcemgt/update
+ Scope required:
+ * internal_api_resource_update + parameters: + - $ref: '#/components/parameters/apiResourceId' + responses: + 204: + description: No Content + 400: + description: Bad Request + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + 401: + description: Unauthorized + 403: + description: Forbidden + 404: + description: Not Found + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + 409: + description: Conflict + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + application/xml: + schema: + $ref: '#/components/schemas/Error' + 500: + description: Server Error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + + requestBody: + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/ScopeCreationModel' + description: This represents the API resource to be patched. + required: true + + /api-resources/{apiResourceId}/scopes/{scopeName}: + delete: + tags: + - API Resource Scopes + summary: Delete API scope specified by the name + description: > + Delete API scope specified by the name + Permission required:
+ * /permission/admin/manage/identity/apiresourcemgt/delete
+ Scope required:
+ * internal_api_resource_delete + parameters: + - $ref: '#/components/parameters/apiResourceId' + - $ref: '#/components/parameters/scopeName' + responses: + 401: + description: Unauthorized + 403: + description: Forbidden + 500: + description: Server Error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + + /scopes: + get: + tags: + - API Resource Scopes + summary: Get all scopes in the tenant + description: > + Get all scopes in the tenant + Permission required:
+ * /permission/admin/manage/identity/apiresourcemgt/view
+ Scope required:
+ * internal_api_resource_view + parameters: + - $ref: '#/components/parameters/filter' + responses: + 200: + description: OK + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/ScopeGetModel' + 401: + description: Unauthorized + 403: + description: Forbidden + 404: + description: Not Found + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + 500: + description: Server Error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + +components: + parameters: + organizationId: + in: path + name: organizationId + description: uuid of the org. + required: true + schema: + type: string + example: "1234-4567-4567" + + apiResourceId: + name: apiResourceId + in: path + description: ID of the API Resource. + required: true + schema: + type: string + example: er34-gf23-bv54-vb90 + + scopeName: + name: scopeName + in: path + description: Name of the Scope. + required: true + schema: + type: string + + applicationId: + name: applicationId + in: path + description: ID of the Application. + required: true + schema: + type: string + + authorizationId: + name: authorizationId + in: path + description: ID of the authorization. + required: true + schema: + type: string + + before: + name: before + in: query + required: false + description: | + Base64 encoded cursor value for backward pagination. + schema: + type: string + example: Ng== + + after: + name: after + in: query + required: false + description: | + Base64 encoded cursor value for forward pagination. + schema: + type: string + example: Ng== + + filter: + 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: identifier+eq+greetings + + limit: + name: limit + in: query + required: false + description: | + Maximum number of records to return. + schema: + type: integer + example: 10 + + requiredAttributes: + name: requiredAttributes + in: query + required: false + description: Specifies the required parameters in the response. This parameter is not supported yet + schema: + type: string + + schemas: + Error: + type: object + properties: + code: + type: string + example: AAA-00000 + message: + type: string + example: Some Error Message + description: + type: string + example: Some Error Description + traceId: + type: string + example: e0fbcfeb-3617-43c4-8dd0-7b7d38e13047 + + APIResourceListItem: + type: object + required: + - id + - name + - identifier + - self + properties: + id: + type: string + example: gh43-jk34-vb34-df67 + name: + type: string + example: Greetings API + identifier: + type: string + example: greetings_api + type: + type: string + example: SYSTEM + requiresAuthorization: + type: boolean + example: true + self: + type: string + example: /t/carbon.super/api/server/v1/api-resources/eDUwOUNlcnRpZmljYXRlQXV0aGVudGljYXRvcg + + APIResourceResponse: + type: object + required: + - id + - name + - identifier + - 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 + requiresAuthorization: + type: boolean + example: true + scopes: + type: array + items: + $ref: '#/components/schemas/ScopeGetModel' + subscribedApplications: + type: array + items: + $ref: '#/components/schemas/SubscribedApplicationGetModel' + self: + type: string + example: /t/carbon.super/api/server/v1/api-resources/eDUwOUNlcnRpZmljYXRlQXV0aGVudGljYXRvcg + + APIResourceCreationModel: + type: object + required: + - identifier + - name + properties: + name: + type: string + example: Greetings API + identifier: + type: string + example: greetings_api + description: + type: string + example: Greetings API representation + requiresAuthorization: + type: boolean + example: true + scopes: + type: array + items: + $ref: '#/components/schemas/ScopeCreationModel' + + APIResourcePatchModel: + type: object + properties: + name: + type: string + example: Greetings API + description: + type: string + example: Greetings API representation + addedScopes: + type: array + items: + $ref: '#/components/schemas/ScopeCreationModel' + removedScopes: + type: array + items: + type: string + description: This field is not supported yet. + + PaginationLink: + type: object + properties: + rel: + type: string + example: before + href: + type: string + example: /o/orgName/api-resources?after=NDoy + + APIResourceListResponse: + type: object + required: + - links + properties: + totalResults: + type: integer + example: 1 + links: + type: array + items: + $ref: '#/components/schemas/PaginationLink' + APIResources: + type: array + items: + $ref: '#/components/schemas/APIResourceListItem' + + ScopeGetModel: + type: object + required: + - id + - displayName + - name + properties: + id: + type: string + example: sf23-fg34-fy53-hj23 + displayName: + type: string + example: Write + name: + type: string + example: greetings:write + description: + type: string + example: Allow writing greetings + + ScopeCreationModel: + type: object + required: + - name + properties: + name: + type: string + example: 'greetings:write' + displayName: + type: string + example: "Write Greetings" + description: + type: string + example: "Allows writing greetings" + + SubscribedApplicationGetModel: + type: object + properties: + name: + type: string + example: Application1 + id: + type: string + example: 23fd-23gd-54vv-sdhf + + responses: + BadRequest: + description: Bad Request. Invalid request or validation error. + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + example: + code: 400 + message: Bad Request + description: Invalid request or validation error + + Conflict: + description: Conflict. Specified resource already exists. + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + example: + code: 409 + message: Conflict + description: Specified resource already exists + moreInfo: '' + error: [] + Forbidden: + description: >- + Forbidden. The request must be conditional but no condition has been + specified. + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + example: + code: 403 + message: Forbidden + description: >- + The request must be conditional but no condition has been + specified + InternalServerError: + description: Internal Server Error. + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + example: + code: 500 + message: Internal Server Error + description: >- + The server encountered an internal error. Please contact + administrator. + moreInfo: '' + error: [] + NotFound: + description: Not Found. The specified resource does not exist. + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + example: + code: 404 + message: Not Found + description: The specified resource does not exist + moreInfo: '' + error: [] + + Unauthorized: + description: Unauthorized. The user is not authorized. + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + example: + code: 401 + message: Unauthorized + description: The user is not authorized + moreInfo: '' + error: [] + + securitySchemes: + BasicAuth: + type: http + scheme: basic + OAuth2: + type: oauth2 + flows: + authorizationCode: + authorizationUrl: 'https://localhost:9443/oauth2/authorize' + tokenUrl: 'http://localhost:9443/oauth2/token' + scopes: {} \ No newline at end of file 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 new file mode 100644 index 0000000000..d0e3e969ba --- /dev/null +++ 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 @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + diff --git a/components/org.wso2.carbon.identity.api.server.api.resource/pom.xml b/components/org.wso2.carbon.identity.api.server.api.resource/pom.xml new file mode 100644 index 0000000000..47eec109b3 --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.api.resource/pom.xml @@ -0,0 +1,38 @@ + + + + 4.0.0 + + + identity-api-server + org.wso2.carbon.identity.server.api + 1.2.79-SNAPSHOT + ../../pom.xml + + + org.wso2.carbon.identity.api.server.api.resource + 1.2.79-SNAPSHOT + pom + + + org.wso2.carbon.identity.api.server.api.resource.common + org.wso2.carbon.identity.api.server.api.resource.v1 + + + diff --git a/pom.xml b/pom.xml index 155af72a21..cfd1f0685f 100644 --- a/pom.xml +++ b/pom.xml @@ -191,6 +191,12 @@ ${carbon.identity.framework.version} provided + + org.wso2.carbon.identity.framework + org.wso2.carbon.identity.api.resource.mgt + ${carbon.identity.framework.version} + provided + org.wso2.carbon.identity.framework org.wso2.carbon.identity.application.mgt @@ -394,6 +400,12 @@ ${project.version} provided + + org.wso2.carbon.identity.server.api + org.wso2.carbon.identity.api.server.api.resource.common + ${project.version} + provided + org.wso2.carbon org.wso2.carbon.user.api @@ -775,6 +787,7 @@ components/org.wso2.carbon.identity.api.idle.account.identification components/org.wso2.carbon.identity.api.expired.password.identification components/org.wso2.carbon.identity.api.server.organization.user.invitation.management + components/org.wso2.carbon.identity.api.server.api.resource From 309ef1da7a07b1cbab113bdae9aa5e30bfbe1bad Mon Sep 17 00:00:00 2001 From: Thamindu Aluthwala Date: Wed, 13 Sep 2023 09:54:13 +0530 Subject: [PATCH 2/6] address review comments --- .../pom.xml | 3 +- .../pom.xml | 6 +-- .../ServerAPIResourceManagementService.java | 14 +++--- .../APIResourceMgtEndpointException.java | 38 --------------- .../v1/util/APIResourceMgtEndpointUtil.java | 46 ++++++++++--------- .../src/main/resources/APIResources.yaml | 10 ++-- .../pom.xml | 3 +- 7 files changed, 39 insertions(+), 81 deletions(-) delete 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/exception/APIResourceMgtEndpointException.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 a150b8a81b..d8d8d5026e 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 @@ -22,12 +22,11 @@ org.wso2.carbon.identity.server.api org.wso2.carbon.identity.api.server.api.resource - 1.2.79-SNAPSHOT + 1.2.81-SNAPSHOT ../pom.xml org.wso2.carbon.identity.api.server.api.resource.common - 1.2.79-SNAPSHOT jar 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 68d3c26206..3a4f6d82d0 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 @@ -22,14 +22,13 @@ org.wso2.carbon.identity.server.api org.wso2.carbon.identity.api.server.api.resource - 1.2.79-SNAPSHOT + 1.2.81-SNAPSHOT ../pom.xml - WSO2 Identity Server - Applications Rest API + WSO2 Identity Server - API Resource Rest API WSO2 Identity Server - API Resource Rest API org.wso2.carbon.identity.api.server.api.resource.v1 - 1.2.79-SNAPSHOT jar @@ -114,6 +113,7 @@ org.wso2.carbon.identity.framework org.wso2.carbon.identity.application.common + provided org.wso2.carbon.identity.inbound.auth.oauth2 diff --git a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/core/ServerAPIResourceManagementService.java b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/core/ServerAPIResourceManagementService.java index c31252fd4d..ce54f1ba35 100644 --- a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/core/ServerAPIResourceManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/core/ServerAPIResourceManagementService.java @@ -36,9 +36,9 @@ 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.constants.APIResourceMgtEndpointConstants.ErrorMessage; -import org.wso2.carbon.identity.api.server.api.resource.v1.exception.APIResourceMgtEndpointException; import org.wso2.carbon.identity.api.server.api.resource.v1.util.APIResourceMgtEndpointUtil; import org.wso2.carbon.identity.api.server.common.ContextLoader; +import org.wso2.carbon.identity.api.server.common.error.APIError; import org.wso2.carbon.identity.application.common.model.APIResource; import org.wso2.carbon.identity.application.common.model.Scope; @@ -105,9 +105,9 @@ public APIResourceResponse addAPIResourceWithResourceId(APIResourceCreationModel /** * Get API Resources. * - * @param before - before parameter for cursor based pagination. - * @param after - after parameter for cursor based pagination. - * @param filter - filter parameter. + * @param before before parameter for cursor based pagination. + * @param after after parameter for cursor based pagination. + * @param filter filter parameter. * @return Response with API Resources list. */ public APIResourceListResponse getAPIResources(String before, String after, String filter, Integer limit) { @@ -132,7 +132,7 @@ public APIResourceListResponse getAPIResources(String before, String after, Stri CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); List apiResources = apiResourceSearchResult.getAPIResources(); - if (limit != 0 && CollectionUtils.isNotEmpty(apiResources)) { + if (CollectionUtils.isNotEmpty(apiResources)) { boolean hasMoreItems = apiResources.size() > limit; boolean needsReverse = StringUtils.isNotBlank(before); boolean isFirstPage = (StringUtils.isBlank(before) && StringUtils.isBlank(after)) || @@ -454,9 +454,9 @@ private PaginationLink buildPaginationLink(String url, String rel) { * * @param limit Limit parameter. * @return Validated limit. - * @throws APIResourceMgtEndpointException if the limit is invalid. + * @throws APIError if the limit is invalid. */ - private static Integer validatedLimit(Integer limit) throws APIResourceMgtEndpointException { + private static Integer validatedLimit(Integer limit) throws APIError { limit = limit == null ? DEFAULT_LIMIT : limit; if (limit == 0 || limit < 0) { 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/exception/APIResourceMgtEndpointException.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/exception/APIResourceMgtEndpointException.java deleted file mode 100644 index 9976a6f910..0000000000 --- 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/exception/APIResourceMgtEndpointException.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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.exception; - -import org.wso2.carbon.identity.api.server.api.resource.v1.Error; - -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -/** - * Exception class for API resource management endpoint. - */ -public class APIResourceMgtEndpointException extends WebApplicationException { - - public APIResourceMgtEndpointException(Response.Status status, Error error) { - - super(Response.status(status).entity(error).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) - .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 dff0b7e878..e039b5b17c 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 @@ -25,11 +25,11 @@ import org.wso2.carbon.identity.api.resource.mgt.APIResourceMgtException; import org.wso2.carbon.identity.api.server.api.resource.common.APIResourceManagementServiceHolder; import org.wso2.carbon.identity.api.server.api.resource.v1.APIResourceCreationModel; -import org.wso2.carbon.identity.api.server.api.resource.v1.Error; import org.wso2.carbon.identity.api.server.api.resource.v1.ScopeCreationModel; import org.wso2.carbon.identity.api.server.api.resource.v1.constants.APIResourceMgtEndpointConstants; -import org.wso2.carbon.identity.api.server.api.resource.v1.exception.APIResourceMgtEndpointException; import org.wso2.carbon.identity.api.server.common.ContextLoader; +import org.wso2.carbon.identity.api.server.common.error.APIError; +import org.wso2.carbon.identity.api.server.common.error.ErrorDTO; import org.wso2.carbon.identity.core.util.IdentityUtil; import org.wso2.carbon.identity.oauth.IdentityOAuthAdminException; @@ -55,7 +55,7 @@ */ public class APIResourceMgtEndpointUtil { - private static final Log log = LogFactory.getLog(APIResourceMgtEndpointUtil.class); + private static final Log LOG = LogFactory.getLog(APIResourceMgtEndpointUtil.class); public static void validateAPIResource(APIResourceCreationModel apiResource) { @@ -69,7 +69,7 @@ public static void validateAPIResource(APIResourceCreationModel apiResource) { public static void validateScopes(List scopes) { - if (scopes == null || scopes.isEmpty()) { + if (scopes == null) { return; } for (ScopeCreationModel scope : scopes) { @@ -90,8 +90,10 @@ public static void validateScopes(List scopes) { try { List registeredOIDCScopes = APIResourceManagementServiceHolder.getOAuthAdminServiceImpl() .getRegisteredOIDCScope(ContextLoader.getTenantDomainFromContext()); - if (registeredOIDCScopes.contains(scope.getName())) { - throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_RESTRICTED_OIDC_SCOPES); + if (registeredOIDCScopes != null) { + if (registeredOIDCScopes.contains(scope.getName())) { + throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_RESTRICTED_OIDC_SCOPES); + } } } catch (IdentityOAuthAdminException e) { throw handleException(Response.Status.INTERNAL_SERVER_ERROR, ERROR_CODE_VALIDATE_SCOPES); @@ -109,7 +111,7 @@ public static List validateAndConvertToLowerCase(List attributes List validatedAttributes = new ArrayList<>(); - if (attributes == null || attributes.isEmpty()) { + if (attributes == null) { return validatedAttributes; } @@ -123,32 +125,32 @@ public static List validateAndConvertToLowerCase(List attributes return validatedAttributes; } - public static APIResourceMgtEndpointException handleException(Response.Status status, - APIResourceMgtEndpointConstants.ErrorMessage error) { + public static APIError handleException(Response.Status status, + APIResourceMgtEndpointConstants.ErrorMessage error) { - return new APIResourceMgtEndpointException(status, getError(error.getCode(), error.getMessage(), + return new APIError(status, getError(error.getCode(), error.getMessage(), error.getDescription())); } - public static APIResourceMgtEndpointException handleException(Response.Status status, - APIResourceMgtEndpointConstants.ErrorMessage error, - String data) { + public static APIError handleException(Response.Status status, + APIResourceMgtEndpointConstants.ErrorMessage error, + String data) { - return new APIResourceMgtEndpointException(status, getError(error.getCode(), error.getMessage(), + return new APIError(status, getError(error.getCode(), error.getMessage(), String.format(error.getDescription(), data))); } - public static APIResourceMgtEndpointException handleException(Response.Status status, String errorCode, - String message, String description) { + public static APIError handleException(Response.Status status, String errorCode, + String message, String description) { - return new APIResourceMgtEndpointException(status, getError(errorCode, message, description)); + return new APIError(status, getError(errorCode, message, description)); } - public static APIResourceMgtEndpointException handleAPIResourceMgtException(APIResourceMgtException e) { + public static APIError handleAPIResourceMgtException(APIResourceMgtException e) { Response.Status status = Response.Status.INTERNAL_SERVER_ERROR; if (e instanceof APIResourceMgtClientException) { - log.debug(e.getMessage(), e); + LOG.debug(e.getMessage(), e); if (ERROR_CODE_API_RESOURCE_ALREADY_EXISTS.getCode().equals(e.getErrorCode()) || ERROR_CODE_SCOPE_ALREADY_EXISTS.getCode().equals(e.getErrorCode())) { status = Response.Status.CONFLICT; @@ -156,7 +158,7 @@ public static APIResourceMgtEndpointException handleAPIResourceMgtException(APIR status = Response.Status.BAD_REQUEST; } } else { - log.error(e.getMessage(), e); + LOG.error(e.getMessage(), e); } String errorCode = e.getErrorCode(); errorCode = errorCode.contains(ERROR_CODE_DELIMITER) ? errorCode : @@ -172,9 +174,9 @@ public static APIResourceMgtEndpointException handleAPIResourceMgtException(APIR * @param errorDescription Error description. * @return A generic error with the specified details. */ - public static Error getError(String errorCode, String errorMessage, String errorDescription) { + public static ErrorDTO getError(String errorCode, String errorMessage, String errorDescription) { - Error error = new Error(); + ErrorDTO error = new ErrorDTO(); error.setCode(errorCode); error.setMessage(errorMessage); error.setDescription(errorDescription); 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 3e3459b97b..aae71fe967 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 @@ -163,12 +163,8 @@ paths: parameters: - $ref: '#/components/parameters/apiResourceId' responses: - 200: - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/APIResourceResponse' + 204: + description: Not Content 400: description: Bad Request content: @@ -777,4 +773,4 @@ components: authorizationCode: authorizationUrl: 'https://localhost:9443/oauth2/authorize' tokenUrl: 'http://localhost:9443/oauth2/token' - scopes: {} \ No newline at end of file + scopes: {} diff --git a/components/org.wso2.carbon.identity.api.server.api.resource/pom.xml b/components/org.wso2.carbon.identity.api.server.api.resource/pom.xml index 47eec109b3..7627fb68d9 100644 --- a/components/org.wso2.carbon.identity.api.server.api.resource/pom.xml +++ b/components/org.wso2.carbon.identity.api.server.api.resource/pom.xml @@ -22,12 +22,11 @@ identity-api-server org.wso2.carbon.identity.server.api - 1.2.79-SNAPSHOT + 1.2.81-SNAPSHOT ../../pom.xml org.wso2.carbon.identity.api.server.api.resource - 1.2.79-SNAPSHOT pom From 65bac930b44c5542bb25a5eba3887117d981dcf0 Mon Sep 17 00:00:00 2001 From: Thamindu Aluthwala Date: Mon, 18 Sep 2023 14:13:39 +0530 Subject: [PATCH 3/6] Update pom --- .../pom.xml | 2 +- .../org.wso2.carbon.identity.api.server.api.resource.v1/pom.xml | 2 +- .../org.wso2.carbon.identity.api.server.api.resource/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.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 d8d8d5026e..6f8cca4ef4 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 @@ -22,7 +22,7 @@ org.wso2.carbon.identity.server.api org.wso2.carbon.identity.api.server.api.resource - 1.2.81-SNAPSHOT + 1.2.82-SNAPSHOT ../pom.xml 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 3a4f6d82d0..c38788cbcc 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 @@ -22,7 +22,7 @@ org.wso2.carbon.identity.server.api org.wso2.carbon.identity.api.server.api.resource - 1.2.81-SNAPSHOT + 1.2.82-SNAPSHOT ../pom.xml diff --git a/components/org.wso2.carbon.identity.api.server.api.resource/pom.xml b/components/org.wso2.carbon.identity.api.server.api.resource/pom.xml index 7627fb68d9..0a35d49f1f 100644 --- a/components/org.wso2.carbon.identity.api.server.api.resource/pom.xml +++ b/components/org.wso2.carbon.identity.api.server.api.resource/pom.xml @@ -22,7 +22,7 @@ identity-api-server org.wso2.carbon.identity.server.api - 1.2.81-SNAPSHOT + 1.2.82-SNAPSHOT ../../pom.xml From 9b7a5c35cf160bb97b3bf2233355215a698c2428 Mon Sep 17 00:00:00 2001 From: Thamindu Aluthwala Date: Mon, 18 Sep 2023 16:56:17 +0530 Subject: [PATCH 4/6] use autowire --- .../v1/core/ServerAPIResourceManagementService.java | 11 ----------- .../api/resource/v1/impl/ScopesApiServiceImpl.java | 5 +++-- 2 files changed, 3 insertions(+), 13 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/ServerAPIResourceManagementService.java b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/core/ServerAPIResourceManagementService.java index ce54f1ba35..06fdf3544f 100644 --- a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/core/ServerAPIResourceManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/core/ServerAPIResourceManagementService.java @@ -63,19 +63,8 @@ */ public class ServerAPIResourceManagementService { - private static final ServerAPIResourceManagementService instance = new ServerAPIResourceManagementService(); - private static final Log LOG = LogFactory.getLog(ServerAPIResourceManagementService.class); - private ServerAPIResourceManagementService() { - - } - - public static ServerAPIResourceManagementService getInstance() { - - return instance; - } - /** * Add 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/java/org/wso2/carbon/identity/api/server/api/resource/v1/impl/ScopesApiServiceImpl.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/ScopesApiServiceImpl.java index b66d889841..808d70d219 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/ScopesApiServiceImpl.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/ScopesApiServiceImpl.java @@ -18,6 +18,7 @@ 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.ScopesApiService; import org.wso2.carbon.identity.api.server.api.resource.v1.core.ServerAPIResourceManagementService; @@ -28,8 +29,8 @@ */ public class ScopesApiServiceImpl implements ScopesApiService { - ServerAPIResourceManagementService serverAPIResourceManagementService = - ServerAPIResourceManagementService.getInstance(); + @Autowired + ServerAPIResourceManagementService serverAPIResourceManagementService; @Override public Response scopesGet(String filter) { From 89381aeddfd4c39617b5f995f7aaa450b7425aac Mon Sep 17 00:00:00 2001 From: Thamindu Aluthwala Date: Mon, 18 Sep 2023 21:04:36 +0530 Subject: [PATCH 5/6] simplify if condition --- .../resource/v1/core/ServerAPIResourceManagementService.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/ServerAPIResourceManagementService.java b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/core/ServerAPIResourceManagementService.java index 06fdf3544f..68652684dc 100644 --- a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/core/ServerAPIResourceManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.v1/src/main/java/org/wso2/carbon/identity/api/server/api/resource/v1/core/ServerAPIResourceManagementService.java @@ -448,7 +448,7 @@ private PaginationLink buildPaginationLink(String url, String rel) { private static Integer validatedLimit(Integer limit) throws APIError { limit = limit == null ? DEFAULT_LIMIT : limit; - if (limit == 0 || limit < 0) { + if (limit <= 0) { throw APIResourceMgtEndpointUtil.handleException(Response.Status.BAD_REQUEST, ErrorMessage.ERROR_CODE_INVALID_LIMIT); } From db434f949f8a20f9882300c3b67591bd8ad8b891 Mon Sep 17 00:00:00 2001 From: Thamindu Aluthwala Date: Mon, 18 Sep 2023 21:37:33 +0530 Subject: [PATCH 6/6] update pom --- .../pom.xml | 2 +- .../org.wso2.carbon.identity.api.server.api.resource.v1/pom.xml | 2 +- .../org.wso2.carbon.identity.api.server.api.resource/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.server.api.resource/org.wso2.carbon.identity.api.server.api.resource.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 6f8cca4ef4..4b89afbd3d 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 @@ -22,7 +22,7 @@ org.wso2.carbon.identity.server.api org.wso2.carbon.identity.api.server.api.resource - 1.2.82-SNAPSHOT + 1.2.83-SNAPSHOT ../pom.xml 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 c38788cbcc..c2d54dc8c4 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 @@ -22,7 +22,7 @@ org.wso2.carbon.identity.server.api org.wso2.carbon.identity.api.server.api.resource - 1.2.82-SNAPSHOT + 1.2.83-SNAPSHOT ../pom.xml diff --git a/components/org.wso2.carbon.identity.api.server.api.resource/pom.xml b/components/org.wso2.carbon.identity.api.server.api.resource/pom.xml index 0a35d49f1f..c11ff9fcc6 100644 --- a/components/org.wso2.carbon.identity.api.server.api.resource/pom.xml +++ b/components/org.wso2.carbon.identity.api.server.api.resource/pom.xml @@ -22,7 +22,7 @@ identity-api-server org.wso2.carbon.identity.server.api - 1.2.82-SNAPSHOT + 1.2.83-SNAPSHOT ../../pom.xml