From 3e77678ebff16bf12d966f84e7d3c0cc896b4719 Mon Sep 17 00:00:00 2001 From: dewniMW Date: Thu, 21 Sep 2023 10:01:15 +0530 Subject: [PATCH] Add organization configuration management API --- .../pom.xml | 57 +++++ .../OrganizationConfigsServiceHolder.java | 49 +++++ ...zationConfigManagerOSGIServiceFactory.java | 53 +++++ .../pom.xml | 170 +++++++++++++++ .../configs/v1/OrganizationConfigsApi.java | 115 ++++++++++ .../v1/OrganizationConfigsApiService.java | 39 ++++ .../OrganizationConfigsApiServiceFactory.java | 32 +++ .../organization/configs/v1/model/Config.java | 110 ++++++++++ .../organization/configs/v1/model/Error.java | 169 +++++++++++++++ .../configs/v1/model/Properties.java | 123 +++++++++++ .../v1/core/OrganizationConfigsService.java | 136 ++++++++++++ .../OrganizationConfigsApiServiceImpl.java | 55 +++++ .../organization-configs-server-v1-cxf.xml | 31 +++ .../main/resources/organization-configs.yaml | 202 ++++++++++++++++++ .../pom.xml | 37 ++++ pom.xml | 15 +- 16 files changed, 1392 insertions(+), 1 deletion(-) create mode 100644 components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.common/pom.xml create mode 100644 components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.common/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/common/OrganizationConfigsServiceHolder.java create mode 100644 components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.common/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/common/factory/OrganizationConfigManagerOSGIServiceFactory.java create mode 100644 components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/pom.xml create mode 100644 components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/configs/v1/OrganizationConfigsApi.java create mode 100644 components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/configs/v1/OrganizationConfigsApiService.java create mode 100644 components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/configs/v1/factories/OrganizationConfigsApiServiceFactory.java create mode 100644 components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/configs/v1/model/Config.java create mode 100644 components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/configs/v1/model/Error.java create mode 100644 components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/configs/v1/model/Properties.java create mode 100644 components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/v1/core/OrganizationConfigsService.java create mode 100644 components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/v1/impl/OrganizationConfigsApiServiceImpl.java create mode 100644 components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/main/resources/META-INF/cxf/organization-configs-server-v1-cxf.xml create mode 100644 components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/main/resources/organization-configs.yaml create mode 100644 components/org.wso2.carbon.identity.api.server.organization.configs/pom.xml diff --git a/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.common/pom.xml b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.common/pom.xml new file mode 100644 index 0000000000..475cec37ab --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.common/pom.xml @@ -0,0 +1,57 @@ + + + + 4.0.0 + + + org.wso2.carbon.identity.server.api + org.wso2.carbon.identity.api.server.organization.configs + 1.2.84-SNAPSHOT + + + org.wso2.carbon.identity.api.server.organization.configs.common + jar + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + + + org.wso2.carbon.identity.organization.management + org.wso2.carbon.identity.organization.config.service + provided + + + org.springframework + spring-web + provided + + + + diff --git a/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.common/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/common/OrganizationConfigsServiceHolder.java b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.common/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/common/OrganizationConfigsServiceHolder.java new file mode 100644 index 0000000000..8747877c0c --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.common/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/common/OrganizationConfigsServiceHolder.java @@ -0,0 +1,49 @@ +/* + * 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.organization.configs.common; + +import org.wso2.carbon.identity.organization.config.service.OrganizationConfigManager; + +/** + * Service holder class for organization configuration management. + */ +public class OrganizationConfigsServiceHolder { + + private static OrganizationConfigManager organizationConfigManager; + + /** + * Get ConfigManager OSGi service. + * + * @return ConfigManager. + */ + public static OrganizationConfigManager getOrganizationConfigManager() { + + return organizationConfigManager; + } + + /** + * Set ConfigManager OSGi service. + * + * @param organizationConfigManager ConfigManager. + */ + public static void setOrganizationConfigManager(OrganizationConfigManager organizationConfigManager) { + + OrganizationConfigsServiceHolder.organizationConfigManager = organizationConfigManager; + } +} diff --git a/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.common/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/common/factory/OrganizationConfigManagerOSGIServiceFactory.java b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.common/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/common/factory/OrganizationConfigManagerOSGIServiceFactory.java new file mode 100644 index 0000000000..145baeb38d --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.common/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/common/factory/OrganizationConfigManagerOSGIServiceFactory.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.organization.configs.common.factory; + +import org.springframework.beans.factory.config.AbstractFactoryBean; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.identity.organization.config.service.OrganizationConfigManager; + +/** + * Factory Beans serves as a factory for creating other beans within the IOC container. This factory bean is used to + * instantiate the OrganizationConfigManager type of object inside the container. + */ +public class OrganizationConfigManagerOSGIServiceFactory extends AbstractFactoryBean { + + private OrganizationConfigManager organizationConfigManager; + + @Override + public Class getObjectType() { + + return Object.class; + } + + @Override + protected OrganizationConfigManager createInstance() throws Exception { + + if (this.organizationConfigManager == null) { + OrganizationConfigManager taskOperationService = (OrganizationConfigManager) PrivilegedCarbonContext. + getThreadLocalCarbonContext().getOSGiService(OrganizationConfigManager.class, null); + if (taskOperationService != null) { + this.organizationConfigManager = taskOperationService; + } else { + throw new Exception("Unable to retrieve OrganizationConfigManager service."); + } + } + return this.organizationConfigManager; + } +} diff --git a/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/pom.xml b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/pom.xml new file mode 100644 index 0000000000..ad22262f13 --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/pom.xml @@ -0,0 +1,170 @@ + + + + 4.0.0 + + + org.wso2.carbon.identity.server.api + org.wso2.carbon.identity.api.server.organization.configs + 1.2.84-SNAPSHOT + + + org.wso2.carbon.identity.api.server.organization.configs.v1 + jar + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.8 + + + add-source + generate-sources + + add-source + + + + src/gen/java + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven.compiler.plugin.version} + + 1.8 + 1.8 + + + + + + + + org.apache.cxf + cxf-rt-frontend-jaxrs + provided + + + org.apache.cxf + cxf-rt-rs-service-description + provided + + + org.springframework + spring-web + 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 + + + + + com.fasterxml.jackson.jaxrs + jackson-jaxrs-json-provider + provided + + + org.wso2.carbon.identity.server.api + org.wso2.carbon.identity.api.server.common + provided + + + org.wso2.carbon.identity.server.api + org.wso2.carbon.identity.api.server.organization.configs.common + provided + + + org.wso2.carbon.identity.organization.management + org.wso2.carbon.identity.organization.config.service + provided + + + + diff --git a/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/configs/v1/OrganizationConfigsApi.java b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/configs/v1/OrganizationConfigsApi.java new file mode 100644 index 0000000000..b2a0312306 --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/configs/v1/OrganizationConfigsApi.java @@ -0,0 +1,115 @@ +/* + * 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.organization.configs.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.organization.configs.v1.model.Config; +import org.wso2.carbon.identity.api.server.organization.configs.v1.model.Error; +import org.wso2.carbon.identity.api.server.organization.configs.v1.OrganizationConfigsApiService; + +import javax.validation.Valid; +import javax.ws.rs.*; +import javax.ws.rs.core.Response; +import io.swagger.annotations.*; + +import javax.validation.constraints.*; + +@Path("/organization-configs") +@Api(description = "The organization-configs API") + +public class OrganizationConfigsApi { + + @Autowired + private OrganizationConfigsApiService delegate; + + @Valid + @POST + @Path("/discovery") + @Consumes({ "application/json" }) + @Produces({ "application/json" }) + @ApiOperation(value = "Add organization discovery configuration.", notes = "This API provides the capability to add discovery configuration for the primary organization.
Permission required:
* /permission/admin/manage/identity/configmgt/add
Scope required:
* internal_config_mgt_add ", response = Config.class, authorizations = { + @Authorization(value = "BasicAuth"), + @Authorization(value = "OAuth2", scopes = { + + }) + }, tags={ "Discovery", }) + @ApiResponses(value = { + @ApiResponse(code = 201, message = "Successful Response", response = Config.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 = 409, message = "Conflict", response = Error.class), + @ApiResponse(code = 500, message = "Server Error", response = Error.class) + }) + public Response createDiscoveryConfig(@ApiParam(value = "" ) @Valid Config config) { + + return delegate.createDiscoveryConfig(config ); + } + + @Valid + @DELETE + @Path("/discovery") + + @Produces({ "application/json" }) + @ApiOperation(value = "Delete organization discovery configuration.", notes = "This API provides the capability to delete discovery configuration of the primary organization.
Permission required:
* /permission/admin/manage/identity/configmgt/delete
Scope required:
* internal_config_mgt_delete ", response = Void.class, authorizations = { + @Authorization(value = "BasicAuth"), + @Authorization(value = "OAuth2", scopes = { + + }) + }, tags={ "Discovery", }) + @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 = 404, message = "Not Found", response = Error.class), + @ApiResponse(code = 500, message = "Server Error", response = Error.class) + }) + public Response deleteDiscoveryConfig() { + + return delegate.deleteDiscoveryConfig(); + } + + @Valid + @GET + @Path("/discovery") + + @Produces({ "application/json" }) + @ApiOperation(value = "Get organization discovery configuration.", notes = "This API facilitates the retrieval of discovery configuration of the primary organization.
Permission required:
* /permission/admin/manage/identity/configmgt/view
Scope required:
* internal_config_mgt_view ", response = Config.class, authorizations = { + @Authorization(value = "BasicAuth"), + @Authorization(value = "OAuth2", scopes = { + + }) + }, tags={ "Discovery" }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Successful response.", response = Config.class), + @ApiResponse(code = 401, message = "Authentication information is missing or invalid.", response = Void.class), + @ApiResponse(code = 403, message = "Access forbidden.", response = Void.class), + @ApiResponse(code = 500, message = "Internal server error.", response = Error.class) + }) + public Response getDiscoveryConfig() { + + return delegate.getDiscoveryConfig(); + } + +} diff --git a/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/configs/v1/OrganizationConfigsApiService.java b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/configs/v1/OrganizationConfigsApiService.java new file mode 100644 index 0000000000..50ebed2842 --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/configs/v1/OrganizationConfigsApiService.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.organization.configs.v1; + +import org.wso2.carbon.identity.api.server.organization.configs.v1.*; +import org.wso2.carbon.identity.api.server.organization.configs.v1.model.*; +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.organization.configs.v1.model.Config; +import org.wso2.carbon.identity.api.server.organization.configs.v1.model.Error; +import javax.ws.rs.core.Response; + + +public interface OrganizationConfigsApiService { + + public Response createDiscoveryConfig(Config config); + + public Response deleteDiscoveryConfig(); + + public Response getDiscoveryConfig(); +} diff --git a/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/configs/v1/factories/OrganizationConfigsApiServiceFactory.java b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/configs/v1/factories/OrganizationConfigsApiServiceFactory.java new file mode 100644 index 0000000000..ca10ec7642 --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/configs/v1/factories/OrganizationConfigsApiServiceFactory.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.organization.configs.v1.factories; + +import org.wso2.carbon.identity.api.server.organization.configs.v1.OrganizationConfigsApiService; +import org.wso2.carbon.identity.api.server.organization.configs.v1.impl.OrganizationConfigsApiServiceImpl; + +public class OrganizationConfigsApiServiceFactory { + + private final static OrganizationConfigsApiService service = new OrganizationConfigsApiServiceImpl(); + + public static OrganizationConfigsApiService getOrganizationConfigsApi() + { + return service; + } +} diff --git a/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/configs/v1/model/Config.java b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/configs/v1/model/Config.java new file mode 100644 index 0000000000..c8aefe68fe --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/configs/v1/model/Config.java @@ -0,0 +1,110 @@ +/* + * 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.organization.configs.v1.model; + +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.organization.configs.v1.model.Properties; +import javax.validation.constraints.*; + + +import io.swagger.annotations.*; +import java.util.Objects; +import javax.validation.Valid; +import javax.xml.bind.annotation.*; + +public class Config { + + private List properties = null; + + + /** + **/ + public Config properties(List properties) { + + this.properties = properties; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("properties") + @Valid + public List getProperties() { + return properties; + } + public void setProperties(List properties) { + this.properties = properties; + } + + public Config addPropertiesItem(Properties propertiesItem) { + if (this.properties == null) { + this.properties = new ArrayList<>(); + } + this.properties.add(propertiesItem); + return this; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Config config = (Config) o; + return Objects.equals(this.properties, config.properties); + } + + @Override + public int hashCode() { + return Objects.hash(properties); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class Config {\n"); + + sb.append(" properties: ").append(toIndentedString(properties)).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.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/configs/v1/model/Error.java b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/configs/v1/model/Error.java new file mode 100644 index 0000000000..97b40a27ce --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/configs/v1/model/Error.java @@ -0,0 +1,169 @@ +/* + * 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.organization.configs.v1.model; + +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; + + /** + * An error code. + **/ + public Error code(String code) { + + this.code = code; + return this; + } + + @ApiModelProperty(example = "OCM-00000", required = true, value = "An error code.") + @JsonProperty("code") + @Valid + @NotNull(message = "Property code cannot be null.") + + public String getCode() { + return code; + } + public void setCode(String code) { + this.code = code; + } + + /** + * An error message. + **/ + public Error message(String message) { + + this.message = message; + return this; + } + + @ApiModelProperty(example = "Some Error Message", required = true, value = "An error message.") + @JsonProperty("message") + @Valid + @NotNull(message = "Property message cannot be null.") + + public String getMessage() { + return message; + } + public void setMessage(String message) { + this.message = message; + } + + /** + * An error description. + **/ + public Error description(String description) { + + this.description = description; + return this; + } + + @ApiModelProperty(example = "Some Error Description", value = "An error description.") + @JsonProperty("description") + @Valid + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + + /** + * An error trace identifier. + **/ + public Error traceId(String traceId) { + + this.traceId = traceId; + return this; + } + + @ApiModelProperty(example = "e0fbcfeb-3617-43c4-8dd0-7b7d38e13047", value = "An error trace identifier.") + @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.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/configs/v1/model/Properties.java b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/configs/v1/model/Properties.java new file mode 100644 index 0000000000..3e01c3f9b9 --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/configs/v1/model/Properties.java @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.identity.api.server.organization.configs.v1.model; + +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 Properties { + + private String key; + private String value; + + /** + **/ + public Properties key(String key) { + + this.key = key; + return this; + } + + @ApiModelProperty(example = "emailDomain.enable", required = true, value = "") + @JsonProperty("key") + @Valid + @NotNull(message = "Property key cannot be null.") + + public String getKey() { + return key; + } + public void setKey(String key) { + this.key = key; + } + + /** + **/ + public Properties value(String value) { + + this.value = value; + return this; + } + + @ApiModelProperty(example = "true", required = true, value = "") + @JsonProperty("value") + @Valid + @NotNull(message = "Property value cannot be null.") + + public String getValue() { + return value; + } + public void setValue(String value) { + this.value = value; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Properties properties = (Properties) o; + return Objects.equals(this.key, properties.key) && + Objects.equals(this.value, properties.value); + } + + @Override + public int hashCode() { + return Objects.hash(key, value); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class Properties {\n"); + + sb.append(" key: ").append(toIndentedString(key)).append("\n"); + sb.append(" value: ").append(toIndentedString(value)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n"); + } +} + diff --git a/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/v1/core/OrganizationConfigsService.java b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/v1/core/OrganizationConfigsService.java new file mode 100644 index 0000000000..a9d1d68f19 --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/v1/core/OrganizationConfigsService.java @@ -0,0 +1,136 @@ +/* + * 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.organization.configs.v1.core; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.identity.api.server.common.error.APIError; +import org.wso2.carbon.identity.api.server.common.error.ErrorResponse; +import org.wso2.carbon.identity.api.server.organization.configs.common.OrganizationConfigsServiceHolder; +import org.wso2.carbon.identity.api.server.organization.configs.v1.model.Config; +import org.wso2.carbon.identity.api.server.organization.configs.v1.model.Properties; +import org.wso2.carbon.identity.organization.config.service.exception.OrganizationConfigClientException; +import org.wso2.carbon.identity.organization.config.service.exception.OrganizationConfigException; +import org.wso2.carbon.identity.organization.config.service.model.ConfigProperty; +import org.wso2.carbon.identity.organization.config.service.model.DiscoveryConfig; + +import java.util.List; +import java.util.stream.Collectors; + +import javax.ws.rs.core.Response; + +import static org.wso2.carbon.identity.organization.config.service.constant.OrganizationConfigConstants.ErrorMessages.ERROR_CODE_DISCOVERY_CONFIG_CONFLICT; +import static org.wso2.carbon.identity.organization.config.service.constant.OrganizationConfigConstants.ErrorMessages.ERROR_CODE_DISCOVERY_CONFIG_NOT_EXIST; + +/** + * Perform organization configuration management related operations. + */ +public class OrganizationConfigsService { + + private static final Log LOG = LogFactory.getLog(OrganizationConfigsService.class); + + /** + * Add the organization discovery configuration in the primary organization. + * + * @param config The organization discovery configuration. + */ + public void addDiscoveryConfiguration(Config config) { + + List configProperties = config.getProperties().stream() + .map(property -> new ConfigProperty(property.getKey(), property.getValue())) + .collect(Collectors.toList()); + try { + OrganizationConfigsServiceHolder.getOrganizationConfigManager().addDiscoveryConfiguration + (new DiscoveryConfig(configProperties)); + } catch (OrganizationConfigException e) { + throw handleException(e); + } + } + + /** + * Fetch organization discovery configuration. + * + * @return The organization discovery configuration. + */ + public Config getDiscoveryConfiguration() { + + try { + DiscoveryConfig discoveryConfig = OrganizationConfigsServiceHolder.getOrganizationConfigManager() + .getDiscoveryConfiguration(); + + List properties = discoveryConfig.getConfigProperties().stream() + .map(configProperty -> { + Properties prop = new Properties(); + prop.setKey(configProperty.getKey()); + prop.setValue(configProperty.getValue()); + return prop; + }).collect(Collectors.toList()); + Config config = new Config(); + config.setProperties(properties); + return config; + } catch (OrganizationConfigException e) { + throw handleException(e); + } + } + + /** + * Delete the organization discovery configuration. + */ + public void deleteDiscoveryConfiguration() { + + try { + OrganizationConfigsServiceHolder.getOrganizationConfigManager().deleteDiscoveryConfiguration(); + } catch (OrganizationConfigException e) { + throw handleException(e); + } + } + + private APIError handleException(OrganizationConfigException e) { + + if (e instanceof OrganizationConfigClientException) { + throw buildClientError(e); + } + throw buildServerError(e); + } + + private APIError buildClientError(OrganizationConfigException e) { + + String errorCode = e.getErrorCode(); + ErrorResponse errorResponse = new ErrorResponse.Builder().withCode(e.getErrorCode()).withMessage(e.getMessage()) + .withDescription(e.getDescription()).build(LOG, e.getMessage()); + + Response.Status status = Response.Status.BAD_REQUEST; + if (ERROR_CODE_DISCOVERY_CONFIG_CONFLICT.getCode().equals(errorCode)) { + status = Response.Status.CONFLICT; + } else if (ERROR_CODE_DISCOVERY_CONFIG_NOT_EXIST.getCode().equals(errorCode)) { + status = Response.Status.NOT_FOUND; + } + return new APIError(status, errorResponse); + } + + private APIError buildServerError(OrganizationConfigException e) { + + String errorCode = e.getErrorCode(); + ErrorResponse errorResponse = new ErrorResponse.Builder().withCode(errorCode).withMessage(e.getMessage()) + .withDescription(e.getDescription()).build(LOG, e, e.getMessage()); + + Response.Status status = Response.Status.INTERNAL_SERVER_ERROR; + return new APIError(status, errorResponse); + } +} diff --git a/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/v1/impl/OrganizationConfigsApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/v1/impl/OrganizationConfigsApiServiceImpl.java new file mode 100644 index 0000000000..91451087d0 --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/v1/impl/OrganizationConfigsApiServiceImpl.java @@ -0,0 +1,55 @@ +/* + * 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.organization.configs.v1.impl; + +import org.springframework.beans.factory.annotation.Autowired; +import org.wso2.carbon.identity.api.server.organization.configs.v1.OrganizationConfigsApiService; +import org.wso2.carbon.identity.api.server.organization.configs.v1.core.OrganizationConfigsService; +import org.wso2.carbon.identity.api.server.organization.configs.v1.model.Config; + +import javax.ws.rs.core.Response; + +/** + * Implementation of the organization configuration REST API. + */ +public class OrganizationConfigsApiServiceImpl implements OrganizationConfigsApiService { + + @Autowired + private OrganizationConfigsService organizationConfigsService; + + @Override + public Response createDiscoveryConfig(Config config) { + + organizationConfigsService.addDiscoveryConfiguration(config); + return Response.status(Response.Status.CREATED).entity(config).build(); + } + + @Override + public Response deleteDiscoveryConfig() { + + organizationConfigsService.deleteDiscoveryConfiguration(); + return Response.noContent().build(); + } + + @Override + public Response getDiscoveryConfig() { + + return Response.ok().entity(organizationConfigsService.getDiscoveryConfiguration()).build(); + } +} diff --git a/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/main/resources/META-INF/cxf/organization-configs-server-v1-cxf.xml b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/main/resources/META-INF/cxf/organization-configs-server-v1-cxf.xml new file mode 100644 index 0000000000..a9f987b127 --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/main/resources/META-INF/cxf/organization-configs-server-v1-cxf.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + diff --git a/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/main/resources/organization-configs.yaml b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/main/resources/organization-configs.yaml new file mode 100644 index 0000000000..c5fdf1bd1f --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/main/resources/organization-configs.yaml @@ -0,0 +1,202 @@ +openapi: 3.0.0 +info: + title: WSO2 Identity Server - Organization Configuration API Definition + description: This document specifies a **RESTful API** for **WSO2 Identity Server Organization Configurations** + contact: + name: WSO2 + url: http://wso2.com/products/identity-server/ + email: iam-dev@wso2.org + license: + name: Apache 2.0 + url: http://www.apache.org/licenses/LICENSE-2.0.html + version: "v1" +servers: + - url: 'https://localhost:9443/o/{organization-domain}/api/server/v1' + variables: + organization-domain: + default: 10084a8d-113f-4211-a0d5-efe36b082211 +security: + - OAuth2: [] + - BasicAuth: [] + +paths: + /organization-configs/discovery: + get: + tags: + - Discovery + summary: Get organization discovery configuration. + description: | + This API facilitates the retrieval of discovery configuration of the primary organization.
+ Permission required:
+ * /permission/admin/manage/identity/configmgt/view
+ Scope required:
+ * internal_config_mgt_view + operationId: getDiscoveryConfig + responses: + '200': + description: Successful response. + content: + application/json: + schema: + $ref: '#/components/schemas/Config' + '401': + $ref: '#/components/responses/Unauthorized' + '403': + $ref: '#/components/responses/Forbidden' + '500': + $ref: '#/components/responses/ServerError' + post: + tags: + - Discovery + summary: Add organization discovery configuration. + description: | + This API provides the capability to add discovery configuration for the primary organization.
+ Permission required:
+ * /permission/admin/manage/identity/configmgt/add
+ Scope required:
+ * internal_config_mgt_add + operationId: createDiscoveryConfig + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Config' + responses: + "201": + description: Successful Response + content: + application/json: + schema: + $ref: '#/components/schemas/Config' + "400": + description: Bad Request + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + "401": + description: Unauthorized + "403": + description: Forbidden + "409": + description: Conflict + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + "500": + description: Server Error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + delete: + tags: + - Discovery + summary: Delete organization discovery configuration. + description: | + This API provides the capability to delete discovery configuration of the primary organization.
+ Permission required:
+ * /permission/admin/manage/identity/configmgt/delete
+ Scope required:
+ * internal_config_mgt_delete + operationId: deleteDiscoveryConfig + responses: + "204": + description: No Content + "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: + schemas: + Error: + type: object + required: + - code + - message + properties: + code: + type: string + example: OCM-00000 + description: An error code. + message: + type: string + example: Some Error Message + description: An error message. + description: + type: string + example: Some Error Description + description: An error description. + traceId: + type: string + example: e0fbcfeb-3617-43c4-8dd0-7b7d38e13047 + description: An error trace identifier. + + Config: + type: object + properties: + properties: + type: array + items: + $ref: '#/components/schemas/Properties' + Properties: + required: + - key + - value + type: object + properties: + key: + type: string + example: emailDomain.enable + value: + type: string + example: true + + responses: + BadRequest: + description: Invalid input in the request. + content: + 'application/json': + schema: + $ref: '#/components/schemas/Error' + NotFound: + description: Requested resource is not found. + content: + 'application/json': + schema: + $ref: '#/components/schemas/Error' + Unauthorized: + description: Authentication information is missing or invalid. + Forbidden: + description: Access forbidden. + ServerError: + description: Internal server error. + content: + 'application/json': + schema: + $ref: '#/components/schemas/Error' + + securitySchemes: + BasicAuth: + type: http + scheme: basic + OAuth2: + type: oauth2 + flows: + authorizationCode: + authorizationUrl: https://localhost:9443/oauth2/authorize + tokenUrl: https://localhost:9443/oauth2/token + scopes: {} diff --git a/components/org.wso2.carbon.identity.api.server.organization.configs/pom.xml b/components/org.wso2.carbon.identity.api.server.organization.configs/pom.xml new file mode 100644 index 0000000000..1b0c3fdaba --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.organization.configs/pom.xml @@ -0,0 +1,37 @@ + + + + + + identity-api-server + org.wso2.carbon.identity.server.api + 1.2.84-SNAPSHOT + ../../pom.xml + + + 4.0.0 + org.wso2.carbon.identity.api.server.organization.configs + + pom + + + org.wso2.carbon.identity.api.server.organization.configs.common + org.wso2.carbon.identity.api.server.organization.configs.v1 + + diff --git a/pom.xml b/pom.xml index b6901e19e2..9a8fcebbbf 100644 --- a/pom.xml +++ b/pom.xml @@ -555,6 +555,12 @@ ${org.wso2.carbon.identity.organization.management.version} provided + + org.wso2.carbon.identity.organization.management + org.wso2.carbon.identity.organization.config.service + ${org.wso2.carbon.identity.organization.management.version} + provided + org.wso2.carbon.identity.server.api org.wso2.carbon.identity.api.server.organization.management.common @@ -610,6 +616,12 @@ org.wso2.carbon.identity.api.idle.account.identification.common ${project.version} + + org.wso2.carbon.identity.server.api + org.wso2.carbon.identity.api.server.organization.configs.common + ${project.version} + provided + org.apache.felix org.apache.felix.scr.ds-annotations @@ -747,7 +759,7 @@ - 1.3.61 + 1.3.70 @@ -788,6 +800,7 @@ 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 + components/org.wso2.carbon.identity.api.server.organization.configs